@@ -261,7 +261,7 @@ pub(crate) fn assert_redirect_cached(
261
261
pub ( crate ) struct TestEnvironment {
262
262
build_queue : OnceCell < Arc < BuildQueue > > ,
263
263
config : OnceCell < Arc < Config > > ,
264
- db : OnceCell < TestDatabase > ,
264
+ db : tokio :: sync :: OnceCell < TestDatabase > ,
265
265
storage : OnceCell < Arc < Storage > > ,
266
266
async_storage : OnceCell < Arc < AsyncStorage > > ,
267
267
cdn : OnceCell < Arc < CdnBackend > > ,
@@ -296,7 +296,7 @@ impl TestEnvironment {
296
296
Self {
297
297
build_queue : OnceCell :: new ( ) ,
298
298
config : OnceCell :: new ( ) ,
299
- db : OnceCell :: new ( ) ,
299
+ db : tokio :: sync :: OnceCell :: new ( ) ,
300
300
storage : OnceCell :: new ( ) ,
301
301
async_storage : OnceCell :: new ( ) ,
302
302
cdn : OnceCell :: new ( ) ,
@@ -479,31 +479,22 @@ impl TestEnvironment {
479
479
}
480
480
481
481
pub ( crate ) fn db ( & self ) -> & TestDatabase {
482
- self . db . get_or_init ( || {
483
- TestDatabase :: new ( & self . config ( ) , & self . runtime ( ) , self . instance_metrics ( ) )
484
- . expect ( "failed to initialize the db" )
485
- } )
482
+ self . runtime ( ) . block_on ( self . async_db ( ) )
486
483
}
487
484
488
485
pub ( crate ) async fn async_db ( & self ) -> & TestDatabase {
489
- let config = self . config ( ) . clone ( ) ;
490
- let runtime = self . runtime ( ) . clone ( ) ;
491
- let instance_metrics = self . instance_metrics ( ) . clone ( ) ;
492
- if self . db . get ( ) . is_none ( ) {
493
- self . db
494
- . try_insert (
495
- self . runtime ( )
496
- . spawn_blocking ( move || {
497
- TestDatabase :: new ( & config, & runtime, instance_metrics)
498
- . expect ( "failed to initialize the db" )
499
- } )
500
- . await
501
- . unwrap ( ) ,
502
- )
503
- . unwrap ( )
504
- } else {
505
- self . db . get ( ) . unwrap ( )
506
- }
486
+ self . db
487
+ . get_or_init ( || async {
488
+ let config = self . config ( ) ;
489
+ let runtime = self . runtime ( ) ;
490
+ let instance_metrics = self . instance_metrics ( ) ;
491
+ self . runtime ( )
492
+ . spawn_blocking ( move || TestDatabase :: new ( & config, & runtime, instance_metrics) )
493
+ . await
494
+ . unwrap ( )
495
+ . expect ( "failed to initialize the db" )
496
+ } )
497
+ . await
507
498
}
508
499
509
500
pub ( crate ) fn override_frontend ( & self , init : impl FnOnce ( & mut TestFrontend ) ) -> & TestFrontend {
0 commit comments