@@ -663,8 +663,8 @@ pub async fn migrate(pool: &PgPool) -> anyhow::Result<()> {
663
663
664
664
#[ cfg( test) ]
665
665
mod test_current_user {
666
- use crate :: CurrentUser ;
667
666
use crate :: models:: User ;
667
+ use crate :: CurrentUser ;
668
668
use std:: collections:: HashMap ;
669
669
670
670
// New current user should set user and visible clusters to none.
@@ -674,27 +674,43 @@ mod test_current_user {
674
674
assert ! ( test_user. get_user( ) . is_none( ) && test_user. get_visible_clusters( ) . is_none( ) ) ;
675
675
}
676
676
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 ( ) {
680
680
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 ( ) ;
685
682
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
+ }
695
711
}
696
712
697
- // It should be possible to set and get visible clusters.
713
+ // It should be possible to set and get visible clusters.
698
714
#[ test]
699
715
fn test_set_get_visible_clusters ( ) {
700
716
let test_user = CurrentUser :: new ( ) ;
@@ -705,48 +721,44 @@ mod test_current_user {
705
721
test_user. set_visible_clusters ( new_visible_clusters. clone ( ) ) ;
706
722
assert_eq ! (
707
723
(
708
- test_user. get_visible_clusters( ) . unwrap( ) . get( "1" ) ,
724
+ test_user. get_visible_clusters( ) . unwrap( ) . get( "1" ) ,
709
725
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" ) )
714
728
)
715
729
}
716
730
717
- // It should reset current user and visible clusters to none.
731
+ // It should reset current user and visible clusters to none.
718
732
#[ test]
719
733
fn test_reset_user_to_default ( ) {
720
734
let test_user = CurrentUser :: new ( ) ;
721
735
let new_user_data = User {
722
- id : 1 ,
736
+ id : 1 ,
723
737
email : "test@email.com" . to_string ( ) ,
724
738
} ;
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 ( ) ) ] ) ;
726
741
test_user. set_user ( new_user_data) ;
727
742
test_user. set_visible_clusters ( new_visible_clusters) ;
728
743
test_user. set_to_default ( ) ;
729
744
assert ! ( test_user. get_user( ) . is_none( ) && test_user. get_visible_clusters( ) . is_none( ) )
730
-
731
745
}
732
746
}
733
747
734
748
#[ cfg( test) ]
735
749
mod test_clusters {
736
- use crate :: Clusters ;
750
+ use crate :: Clusters ;
737
751
738
- // It should initiate with context and pool being empty hashmaps.
752
+ // It should initiate with context and pool being empty hashmaps.
739
753
#[ test]
740
754
fn test_new_clusters ( ) {
741
755
let test_clusters = Clusters :: new ( ) ;
742
756
assert_eq ! (
743
757
(
744
758
test_clusters. pools. lock( ) . len( ) ,
745
759
test_clusters. contexts. lock( ) . len( ) ,
746
- ) , (
747
- 0 ,
748
- 0 ,
749
- ) ) ;
760
+ ) ,
761
+ ( 0 , 0 , )
762
+ ) ;
750
763
}
751
-
752
- }
764
+ }
0 commit comments