diff --git a/madsim-tokio/src/sim/runtime.rs b/madsim-tokio/src/sim/runtime.rs index 92bc4ad..52abd79 100644 --- a/madsim-tokio/src/sim/runtime.rs +++ b/madsim-tokio/src/sim/runtime.rs @@ -190,6 +190,33 @@ mod tests { } // FIXME(kwannoel): See https://github.com/madsim-rs/madsim/issues/228 + // #[test] + #[allow(dead_code)] + fn runtime_drop_and_spawn_struct_fail_with_try_current_task() { + #[derive(Debug)] + struct A {} + impl Drop for A { + fn drop(&mut self) { + if let Some(handle) = Handle::try_current().ok() { + handle.spawn(std::future::pending::<()>()); + } + } + } + + let a = A {}; + let runtime = madsim::runtime::Runtime::new(); + runtime.block_on(async move { + let rt = Runtime::new().unwrap(); + let join_handle = rt.spawn(async move { drop(a) }); + drop(rt); + + let err = join_handle.await.unwrap_err(); + assert!(err.is_cancelled()); + }) + } + + // FIXME(kwannoel): See https://github.com/madsim-rs/madsim/issues/228 + // #[test] #[allow(dead_code)] fn runtime_drop_and_spawn_struct_fail() { #[derive(Debug)]