Skip to content

Commit

Permalink
fix mysten-common
Browse files Browse the repository at this point in the history
  • Loading branch information
DaughterOfMars committed Aug 12, 2024
1 parent ce8bf56 commit 6b6198a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 24 deletions.
5 changes: 4 additions & 1 deletion crates/mysten-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
51 changes: 28 additions & 23 deletions crates/mysten-common/src/sync/notify_once.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
}
}

0 comments on commit 6b6198a

Please sign in to comment.