@@ -75,6 +75,15 @@ impl IsolatedRuntime {
7575 IsolatedRuntime :: new ( & MetricsRegistry :: new ( ) , Some ( TEST_THREADS ) )
7676 }
7777
78+ #[ cfg( feature = "turmoil" ) ]
79+ /// Create a no-op shim that spawns tasks on the current tokio runtime.
80+ ///
81+ /// This is useful for simulation tests where we don't want to spawn additional threads and/or
82+ /// tokio runtimes.
83+ pub fn new_disabled ( ) -> Self {
84+ IsolatedRuntime { inner : None }
85+ }
86+
7887 /// Spawns a task onto this runtime.
7988 ///
8089 /// Note: We purposefully do not use the [`tokio::task::spawn_blocking`] API here, see the doc
@@ -86,10 +95,11 @@ impl IsolatedRuntime {
8695 F : Future + Send + ' static ,
8796 F :: Output : Send + ' static ,
8897 {
89- self . inner
90- . as_ref ( )
91- . expect ( "exists until drop" )
92- . spawn_named ( name, fut)
98+ if let Some ( runtime) = & self . inner {
99+ runtime. spawn_named ( name, fut)
100+ } else {
101+ mz_ore:: task:: spawn ( name, fut)
102+ }
93103 }
94104}
95105
@@ -98,9 +108,8 @@ impl Drop for IsolatedRuntime {
98108 // We don't need to worry about `shutdown_background` leaking
99109 // blocking tasks (i.e., tasks spawned with `spawn_blocking`) because
100110 // the `IsolatedRuntime` wrapper prevents access to `spawn_blocking`.
101- self . inner
102- . take ( )
103- . expect ( "cannot drop twice" )
104- . shutdown_background ( )
111+ if let Some ( runtime) = self . inner . take ( ) {
112+ runtime. shutdown_background ( ) ;
113+ }
105114 }
106115}
0 commit comments