diff --git a/crates/mysten-common/Cargo.toml b/crates/mysten-common/Cargo.toml index 53f1971f7c7..23a016900d9 100644 --- a/crates/mysten-common/Cargo.toml +++ b/crates/mysten-common/Cargo.toml @@ -9,4 +9,7 @@ publish = false [dependencies] futures.workspace = true parking_lot.workspace = true -tokio.workspace = true +tokio = { workspace = true, features = ["sync"] } + +[dev-dependencies] +tokio = { workspace = true, features = ["test-util", "macros"] } diff --git a/crates/mysten-common/src/sync/notify_once.rs b/crates/mysten-common/src/sync/notify_once.rs index 802be3050ed..4628cfec234 100644 --- a/crates/mysten-common/src/sync/notify_once.rs +++ b/crates/mysten-common/src/sync/notify_once.rs @@ -82,27 +82,32 @@ impl Default for NotifyOnce { } } -#[tokio::test] -async fn notify_once_test() { - let notify_once = NotifyOnce::new(); - // Before notify() is called .wait() is not ready - assert!( - futures::future::poll_immediate(notify_once.wait()) - .await - .is_none() - ); - let wait = notify_once.wait(); - notify_once.notify().unwrap(); - // Pending wait() call is ready now - assert!(futures::future::poll_immediate(wait).await.is_some()); - // Take wait future and don't resolve it. - // This makes sure lock is dropped properly and wait futures resolve - // independently of each other - let _dangle_wait = notify_once.wait(); - // Any new wait() is immediately ready - assert!( - futures::future::poll_immediate(notify_once.wait()) - .await - .is_some() - ); +#[cfg(test)] +mod test { + use super::*; + + #[tokio::test] + async fn notify_once_test() { + let notify_once = NotifyOnce::new(); + // Before notify() is called .wait() is not ready + assert!( + futures::future::poll_immediate(notify_once.wait()) + .await + .is_none() + ); + let wait = notify_once.wait(); + notify_once.notify().unwrap(); + // Pending wait() call is ready now + assert!(futures::future::poll_immediate(wait).await.is_some()); + // Take wait future and don't resolve it. + // This makes sure lock is dropped properly and wait futures resolve + // independently of each other + let _dangle_wait = notify_once.wait(); + // Any new wait() is immediately ready + assert!( + futures::future::poll_immediate(notify_once.wait()) + .await + .is_some() + ); + } }