diff options
Diffstat (limited to 'tokio-sync/tests/atomic_waker.rs')
-rw-r--r-- | tokio-sync/tests/atomic_waker.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/tokio-sync/tests/atomic_waker.rs b/tokio-sync/tests/atomic_waker.rs new file mode 100644 index 00000000..28a9f40d --- /dev/null +++ b/tokio-sync/tests/atomic_waker.rs @@ -0,0 +1,37 @@ +#![deny(warnings, rust_2018_idioms)] + +use std::task::Waker; +use tokio_sync::task::AtomicWaker; +use tokio_test::task::MockTask; + +trait AssertSend: Send {} +trait AssertSync: Send {} + +impl AssertSend for AtomicWaker {} +impl AssertSync for AtomicWaker {} + +impl AssertSend for Waker {} +impl AssertSync for Waker {} + +#[test] +fn basic_usage() { + let waker = AtomicWaker::new(); + let mut task = MockTask::new(); + + task.enter(|cx| waker.register_by_ref(cx.waker())); + waker.wake(); + + assert!(task.is_woken()); +} + +#[test] +fn wake_without_register() { + let waker = AtomicWaker::new(); + waker.wake(); + + // Registering should not result in a notification + let mut task = MockTask::new(); + task.enter(|cx| waker.register_by_ref(cx.waker())); + + assert!(!task.is_woken()); +} |