diff options
Diffstat (limited to 'tokio/tests/sync_notify.rs')
-rw-r--r-- | tokio/tests/sync_notify.rs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/tokio/tests/sync_notify.rs b/tokio/tests/sync_notify.rs index 8c70fe39..8ffe020f 100644 --- a/tokio/tests/sync_notify.rs +++ b/tokio/tests/sync_notify.rs @@ -100,3 +100,37 @@ fn notified_multi_notify_drop_one() { assert!(notified2.is_woken()); assert_ready!(notified2.poll()); } + +#[test] +fn notify_in_drop_after_wake() { + use futures::task::ArcWake; + use std::future::Future; + use std::sync::Arc; + + let notify = Arc::new(Notify::new()); + + struct NotifyOnDrop(Arc<Notify>); + + impl ArcWake for NotifyOnDrop { + fn wake_by_ref(_arc_self: &Arc<Self>) {} + } + + impl Drop for NotifyOnDrop { + fn drop(&mut self) { + self.0.notify_waiters(); + } + } + + let mut fut = Box::pin(async { + notify.notified().await; + }); + + { + let waker = futures::task::waker(Arc::new(NotifyOnDrop(notify.clone()))); + let mut cx = std::task::Context::from_waker(&waker); + assert!(fut.as_mut().poll(&mut cx).is_pending()); + } + + // Now, notifying **should not** deadlock + notify.notify_waiters(); +} |