Skip to content

Commit bf3bc26

Browse files
committed
Failing test
1 parent 92a4402 commit bf3bc26

File tree

1 file changed

+47
-35
lines changed

1 file changed

+47
-35
lines changed

pgml-dashboard/src/lib.rs

Lines changed: 47 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -663,8 +663,8 @@ pub async fn migrate(pool: &PgPool) -> anyhow::Result<()> {
663663

664664
#[cfg(test)]
665665
mod test_current_user {
666-
use crate::CurrentUser;
667666
use crate::models::User;
667+
use crate::CurrentUser;
668668
use std::collections::HashMap;
669669

670670
// New current user should set user and visible clusters to none.
@@ -674,27 +674,43 @@ mod test_current_user {
674674
assert!(test_user.get_user().is_none() && test_user.get_visible_clusters().is_none());
675675
}
676676

677-
// It should be possible to set and get current user.
678-
#[test]
679-
fn test_set_get_current_user() {
677+
// It should be possible to set and get current user.
678+
#[tokio::test]
679+
async fn test_set_get_current_user() {
680680
let test_user = CurrentUser::new();
681-
let new_user_data = User {
682-
id: 1,
683-
email: "test@email.com".to_string(),
684-
};
681+
let mut tests = Vec::new();
685682

686-
test_user.set_user(new_user_data.clone());
687-
assert_eq!(
688-
(
689-
test_user.get_user().unwrap().id,
690-
test_user.get_user().unwrap().email,
691-
), (
692-
new_user_data.id,
693-
new_user_data.email,
694-
));
683+
for id in 0..2500 {
684+
let test_user_clone = test_user.clone();
685+
686+
let handle = tokio::task::spawn(async move {
687+
let new_user_data = User {
688+
id,
689+
email: format!("test_{}@test.com", id),
690+
};
691+
692+
test_user_clone.set_user(new_user_data.clone());
693+
694+
tokio::time::sleep(tokio::time::Duration::from_millis(10)).await;
695+
696+
assert_eq!(
697+
(
698+
test_user_clone.get_user().unwrap().id,
699+
test_user_clone.get_user().unwrap().email,
700+
),
701+
(new_user_data.id, new_user_data.email,)
702+
);
703+
});
704+
705+
tests.push(handle);
706+
}
707+
708+
for test in tests {
709+
test.await.unwrap();
710+
}
695711
}
696712

697-
// It should be possible to set and get visible clusters.
713+
// It should be possible to set and get visible clusters.
698714
#[test]
699715
fn test_set_get_visible_clusters() {
700716
let test_user = CurrentUser::new();
@@ -705,48 +721,44 @@ mod test_current_user {
705721
test_user.set_visible_clusters(new_visible_clusters.clone());
706722
assert_eq!(
707723
(
708-
test_user.get_visible_clusters().unwrap().get("1"),
724+
test_user.get_visible_clusters().unwrap().get("1"),
709725
test_user.get_visible_clusters().unwrap().get("2"),
710-
), (
711-
new_visible_clusters.get("1"),
712-
new_visible_clusters.get("2")
713-
)
726+
),
727+
(new_visible_clusters.get("1"), new_visible_clusters.get("2"))
714728
)
715729
}
716730

717-
// It should reset current user and visible clusters to none.
731+
// It should reset current user and visible clusters to none.
718732
#[test]
719733
fn test_reset_user_to_default() {
720734
let test_user = CurrentUser::new();
721735
let new_user_data = User {
722-
id: 1,
736+
id: 1,
723737
email: "test@email.com".to_string(),
724738
};
725-
let new_visible_clusters: HashMap<String, String> = HashMap::from([("1".to_string(), "123456789".to_string())]);
739+
let new_visible_clusters: HashMap<String, String> =
740+
HashMap::from([("1".to_string(), "123456789".to_string())]);
726741
test_user.set_user(new_user_data);
727742
test_user.set_visible_clusters(new_visible_clusters);
728743
test_user.set_to_default();
729744
assert!(test_user.get_user().is_none() && test_user.get_visible_clusters().is_none())
730-
731745
}
732746
}
733747

734748
#[cfg(test)]
735749
mod test_clusters {
736-
use crate::Clusters;
750+
use crate::Clusters;
737751

738-
// It should initiate with context and pool being empty hashmaps.
752+
// It should initiate with context and pool being empty hashmaps.
739753
#[test]
740754
fn test_new_clusters() {
741755
let test_clusters = Clusters::new();
742756
assert_eq!(
743757
(
744758
test_clusters.pools.lock().len(),
745759
test_clusters.contexts.lock().len(),
746-
), (
747-
0,
748-
0,
749-
));
760+
),
761+
(0, 0,)
762+
);
750763
}
751-
752-
}
764+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy