@@ -261,7 +261,7 @@ pub(crate) fn assert_redirect_cached(
261261pub ( crate ) struct TestEnvironment {
262262 build_queue : OnceCell < Arc < BuildQueue > > ,
263263 config : OnceCell < Arc < Config > > ,
264- db : OnceCell < TestDatabase > ,
264+ db : tokio :: sync :: OnceCell < TestDatabase > ,
265265 storage : OnceCell < Arc < Storage > > ,
266266 async_storage : OnceCell < Arc < AsyncStorage > > ,
267267 cdn : OnceCell < Arc < CdnBackend > > ,
@@ -296,7 +296,7 @@ impl TestEnvironment {
296296 Self {
297297 build_queue : OnceCell :: new ( ) ,
298298 config : OnceCell :: new ( ) ,
299- db : OnceCell :: new ( ) ,
299+ db : tokio :: sync :: OnceCell :: new ( ) ,
300300 storage : OnceCell :: new ( ) ,
301301 async_storage : OnceCell :: new ( ) ,
302302 cdn : OnceCell :: new ( ) ,
@@ -479,31 +479,22 @@ impl TestEnvironment {
479479 }
480480
481481 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 ( ) )
486483 }
487484
488485 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
507498 }
508499
509500 pub ( crate ) fn override_frontend ( & self , init : impl FnOnce ( & mut TestFrontend ) ) -> & TestFrontend {
0 commit comments