@@ -491,13 +491,15 @@ pub struct Auth {
491
491
492
492
#[ cfg( test) ]
493
493
pub mod test_util {
494
+ use std:: ops;
495
+
494
496
use adapter:: {
495
497
dummy:: { Dummy , Options } ,
496
498
Adapter ,
497
499
} ;
498
500
use primitives:: {
499
501
config:: GANACHE_CONFIG ,
500
- test_util:: { discard_logger, CREATOR , FOLLOWER , IDS , LEADER } ,
502
+ test_util:: { discard_logger, DUMMY_AUTH , IDS , LEADER } ,
501
503
} ;
502
504
503
505
use crate :: {
@@ -510,19 +512,38 @@ pub mod test_util {
510
512
Application ,
511
513
} ;
512
514
515
+ /// This guard holds the Redis and Postgres pools taken from their respective Pool of pools.
516
+ ///
517
+ /// This ensures that they will not be dropped which will cause tests to fail randomly.
518
+ pub struct ApplicationGuard {
519
+ pub app : Application < Dummy > ,
520
+ #[ allow( dead_code) ]
521
+ redis_pool : deadpool:: managed:: Object < crate :: db:: redis_pool:: Manager > ,
522
+ #[ allow( dead_code) ]
523
+ db_pool : deadpool:: managed:: Object < crate :: db:: tests_postgres:: Manager > ,
524
+ }
525
+
526
+ impl ops:: Deref for ApplicationGuard {
527
+ type Target = Application < Dummy > ;
528
+
529
+ fn deref ( & self ) -> & Self :: Target {
530
+ & self . app
531
+ }
532
+ }
533
+ impl ops:: DerefMut for ApplicationGuard {
534
+ fn deref_mut ( & mut self ) -> & mut Self :: Target {
535
+ & mut self . app
536
+ }
537
+ }
538
+
513
539
/// Uses development and therefore the goerli testnet addresses of the tokens
514
- /// It still uses DummyAdapter.
515
- pub async fn setup_dummy_app ( ) -> Application < Dummy > {
540
+ /// but still uses the ` DummyAdapter` .
541
+ pub async fn setup_dummy_app ( ) -> ApplicationGuard {
516
542
let config = GANACHE_CONFIG . clone ( ) ;
543
+
517
544
let adapter = Adapter :: new ( Dummy :: init ( Options {
518
545
dummy_identity : IDS [ & LEADER ] ,
519
- dummy_auth_tokens : vec ! [
520
- ( * CREATOR , "AUTH_Creator" . into( ) ) ,
521
- ( * LEADER , "AUTH_Leader" . into( ) ) ,
522
- ( * FOLLOWER , "AUTH_Follower" . into( ) ) ,
523
- ]
524
- . into_iter ( )
525
- . collect ( ) ,
546
+ dummy_auth_tokens : DUMMY_AUTH . clone ( ) ,
526
547
} ) ) ;
527
548
528
549
let redis = TESTS_POOL . get ( ) . await . expect ( "Should return Object" ) ;
@@ -550,6 +571,10 @@ pub mod test_util {
550
571
platform_api,
551
572
) ;
552
573
553
- app
574
+ ApplicationGuard {
575
+ app,
576
+ redis_pool : redis,
577
+ db_pool : database,
578
+ }
554
579
}
555
580
}
0 commit comments