From 0113c2faff98bf8c2aea23907aeb9d79951b7f18 Mon Sep 17 00:00:00 2001 From: HoshimiP Date: Fri, 28 Nov 2025 00:03:57 +0800 Subject: [PATCH 1/4] test: add async tests --- Cargo.lock | 171 +++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 4 ++ tests/async.rs | 102 +++++++++++++++++++++++++++++ 3 files changed, 277 insertions(+) create mode 100644 tests/async.rs diff --git a/Cargo.lock b/Cargo.lock index acc0338..b230bcd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7,8 +7,10 @@ name = "axpoll" version = "0.1.0" dependencies = [ "bitflags", + "futures", "linux-raw-sys", "spin", + "tokio", ] [[package]] @@ -17,14 +19,183 @@ version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" +[[package]] +name = "futures" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" + +[[package]] +name = "futures-executor" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" + +[[package]] +name = "futures-macro" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" + +[[package]] +name = "futures-task" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" + +[[package]] +name = "futures-util" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + [[package]] name = "linux-raw-sys" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df1d3c3b53da64cf5760482273a98e575c651a67eec7f77df96b5b642de8f039" +[[package]] +name = "memchr" +version = "2.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" + +[[package]] +name = "pin-project-lite" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "slab" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a2ae44ef20feb57a68b23d846850f861394c2e02dc425a50098ae8c90267589" + [[package]] name = "spin" version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d5fe4ccb98d9c292d56fec89a5e07da7fc4cf0dc11e156b41793132775d3e591" + +[[package]] +name = "syn" +version = "2.0.111" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "390cc9a294ab71bdb1aa2e99d13be9c753cd2d7bd6560c77118597410c4d2e87" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff360e02eab121e0bc37a2d3b4d4dc622e6eda3a8e5253d5435ecf5bd4c68408" +dependencies = [ + "pin-project-lite", + "tokio-macros", +] + +[[package]] +name = "tokio-macros" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af407857209536a95c8e56f8231ef2c2e2aff839b22e07a1ffcbc617e9db9fa5" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "unicode-ident" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" diff --git a/Cargo.toml b/Cargo.toml index 2282781..6509be9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,3 +19,7 @@ linux-raw-sys = { version = "0.11", default-features = false, features = [ "general", ] } spin = { version = "0.10", default-features = false, features = ["spin_mutex"] } + +[dev-dependencies] +futures = "0.3" +tokio = { version = "1", features = ["rt-multi-thread", "macros", "time"] } \ No newline at end of file diff --git a/tests/async.rs b/tests/async.rs new file mode 100644 index 0000000..3d1cd5e --- /dev/null +++ b/tests/async.rs @@ -0,0 +1,102 @@ +use std::{ + future::Future, + pin::Pin, + sync::{ + Arc, + atomic::{AtomicBool, AtomicUsize, Ordering}, + }, + task::{Context, Poll}, + time::Duration, +}; + +use axpoll::PollSet; +use tokio::time; + +struct WaitFuture { + ps: Arc, + ready: Arc, +} + +impl Future for WaitFuture { + type Output = (); + + fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { + if self.ready.load(Ordering::SeqCst) { + Poll::Ready(()) + } else { + self.ps.register(cx.waker()); + Poll::Pending + } + } +} + +impl WaitFuture { + fn new(ps: Arc, ready: Arc) -> Self { + Self { ps, ready } + } +} + +struct Counter(AtomicUsize); + +impl Counter { + fn new() -> Arc { + Arc::new(Self(AtomicUsize::new(0))) + } + + fn count(&self) -> usize { + self.0.load(Ordering::SeqCst) + } + + fn add(&self) { + self.0.fetch_add(1, Ordering::SeqCst); + } +} + +#[tokio::test] +async fn async_wake_single() { + let ps = Arc::new(PollSet::new()); + let ready = Arc::new(AtomicBool::new(false)); + + let f = WaitFuture::new(ps.clone(), ready.clone()); + + let handle = tokio::spawn(async move { + ready.clone().store(true, Ordering::SeqCst); + ps.clone().wake(); + }); + + f.await; + handle.await.unwrap(); +} + +#[tokio::test] +async fn async_wake_many() { + let ps = Arc::new(PollSet::new()); + let counter = Counter::new(); + + let mut flags = Vec::new(); + let mut handles = Vec::new(); + + for _ in 0..65 { + let flag = Arc::new(AtomicBool::new(false)); + let f = WaitFuture::new(ps.clone(), flag.clone()); + let counter = counter.clone(); + let h = tokio::spawn(async move { + f.await; + counter.add(); + }); + flags.push(flag); + handles.push(h); + } + + time::sleep(Duration::from_millis(20)).await; + + for f in &flags { + f.store(true, Ordering::SeqCst); + } + ps.wake(); + for h in handles { + h.await.unwrap(); + } + + assert_eq!(counter.count(), 65); +} From b5e79cacec50f2b9e6c6b7f18e903d4199931d4e Mon Sep 17 00:00:00 2001 From: HoshimiP Date: Fri, 28 Nov 2025 01:36:28 +0800 Subject: [PATCH 2/4] split wakeup --- Cargo.lock | 108 ------------------------------------------------- Cargo.toml | 3 +- tests/async.rs | 27 ++++++++----- 3 files changed, 18 insertions(+), 120 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b230bcd..3e1f6e6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7,7 +7,6 @@ name = "axpoll" version = "0.1.0" dependencies = [ "bitflags", - "futures", "linux-raw-sys", "spin", "tokio", @@ -19,119 +18,18 @@ version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" -[[package]] -name = "futures" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" - -[[package]] -name = "futures-executor" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" - -[[package]] -name = "futures-macro" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "futures-sink" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" - -[[package]] -name = "futures-task" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" - -[[package]] -name = "futures-util" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - [[package]] name = "linux-raw-sys" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df1d3c3b53da64cf5760482273a98e575c651a67eec7f77df96b5b642de8f039" -[[package]] -name = "memchr" -version = "2.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" - [[package]] name = "pin-project-lite" version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - [[package]] name = "proc-macro2" version = "1.0.103" @@ -150,12 +48,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "slab" -version = "0.4.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a2ae44ef20feb57a68b23d846850f861394c2e02dc425a50098ae8c90267589" - [[package]] name = "spin" version = "0.10.0" diff --git a/Cargo.toml b/Cargo.toml index 6509be9..6e3a747 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,5 +21,4 @@ linux-raw-sys = { version = "0.11", default-features = false, features = [ spin = { version = "0.10", default-features = false, features = ["spin_mutex"] } [dev-dependencies] -futures = "0.3" -tokio = { version = "1", features = ["rt-multi-thread", "macros", "time"] } \ No newline at end of file +tokio = { version = "1.37", features = ["rt-multi-thread", "macros", "time", "sync"] } diff --git a/tests/async.rs b/tests/async.rs index 3d1cd5e..e5dc40e 100644 --- a/tests/async.rs +++ b/tests/async.rs @@ -6,11 +6,10 @@ use std::{ atomic::{AtomicBool, AtomicUsize, Ordering}, }, task::{Context, Poll}, - time::Duration, }; use axpoll::PollSet; -use tokio::time; +use tokio::{task, sync::Barrier}; struct WaitFuture { ps: Arc, @@ -60,8 +59,8 @@ async fn async_wake_single() { let f = WaitFuture::new(ps.clone(), ready.clone()); let handle = tokio::spawn(async move { - ready.clone().store(true, Ordering::SeqCst); - ps.clone().wake(); + ready.store(true, Ordering::SeqCst); + ps.wake(); }); f.await; @@ -75,28 +74,36 @@ async fn async_wake_many() { let mut flags = Vec::new(); let mut handles = Vec::new(); - - for _ in 0..65 { + let barrier = Arc::new(Barrier::new(66)); + for i in 0..65 { let flag = Arc::new(AtomicBool::new(false)); + if i % 2 == 0 { + flag.store(true, Ordering::SeqCst); + } + let b = barrier.clone(); let f = WaitFuture::new(ps.clone(), flag.clone()); let counter = counter.clone(); let h = tokio::spawn(async move { + b.wait().await; f.await; counter.add(); }); flags.push(flag); handles.push(h); } + barrier.wait().await; + let pending: Vec<_> = flags.iter().filter(|f| !f.load(Ordering::SeqCst)).collect(); - time::sleep(Duration::from_millis(20)).await; - - for f in &flags { + ps.wake(); + task::yield_now().await; + assert_eq!(counter.count(), 33); + + for f in &pending { f.store(true, Ordering::SeqCst); } ps.wake(); for h in handles { h.await.unwrap(); } - assert_eq!(counter.count(), 65); } From 069d4ad555779d254dc34c37c62a66090373983e Mon Sep 17 00:00:00 2001 From: HoshimiP Date: Fri, 28 Nov 2025 18:43:27 +0800 Subject: [PATCH 3/4] refactor: finish check logic --- Cargo.lock | 108 +++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + tests/async.rs | 61 ++++++++++++---------------- 3 files changed, 134 insertions(+), 36 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3e1f6e6..b230bcd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7,6 +7,7 @@ name = "axpoll" version = "0.1.0" dependencies = [ "bitflags", + "futures", "linux-raw-sys", "spin", "tokio", @@ -18,18 +19,119 @@ version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" +[[package]] +name = "futures" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" + +[[package]] +name = "futures-executor" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" + +[[package]] +name = "futures-macro" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" + +[[package]] +name = "futures-task" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" + +[[package]] +name = "futures-util" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + [[package]] name = "linux-raw-sys" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df1d3c3b53da64cf5760482273a98e575c651a67eec7f77df96b5b642de8f039" +[[package]] +name = "memchr" +version = "2.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" + [[package]] name = "pin-project-lite" version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + [[package]] name = "proc-macro2" version = "1.0.103" @@ -48,6 +150,12 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "slab" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a2ae44ef20feb57a68b23d846850f861394c2e02dc425a50098ae8c90267589" + [[package]] name = "spin" version = "0.10.0" diff --git a/Cargo.toml b/Cargo.toml index 6e3a747..0c71d4e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,3 +22,4 @@ spin = { version = "0.10", default-features = false, features = ["spin_mutex"] } [dev-dependencies] tokio = { version = "1.37", features = ["rt-multi-thread", "macros", "time", "sync"] } +futures = "0.3" diff --git a/tests/async.rs b/tests/async.rs index e5dc40e..8fc99fb 100644 --- a/tests/async.rs +++ b/tests/async.rs @@ -3,13 +3,14 @@ use std::{ pin::Pin, sync::{ Arc, - atomic::{AtomicBool, AtomicUsize, Ordering}, + atomic::{AtomicBool, Ordering}, }, task::{Context, Poll}, }; use axpoll::PollSet; -use tokio::{task, sync::Barrier}; +use tokio::sync::Barrier; +use futures::future; struct WaitFuture { ps: Arc, @@ -35,22 +36,6 @@ impl WaitFuture { } } -struct Counter(AtomicUsize); - -impl Counter { - fn new() -> Arc { - Arc::new(Self(AtomicUsize::new(0))) - } - - fn count(&self) -> usize { - self.0.load(Ordering::SeqCst) - } - - fn add(&self) { - self.0.fetch_add(1, Ordering::SeqCst); - } -} - #[tokio::test] async fn async_wake_single() { let ps = Arc::new(PollSet::new()); @@ -70,40 +55,44 @@ async fn async_wake_single() { #[tokio::test] async fn async_wake_many() { let ps = Arc::new(PollSet::new()); - let counter = Counter::new(); - let mut flags = Vec::new(); let mut handles = Vec::new(); let barrier = Arc::new(Barrier::new(66)); - for i in 0..65 { + for _ in 0..65 { let flag = Arc::new(AtomicBool::new(false)); - if i % 2 == 0 { - flag.store(true, Ordering::SeqCst); - } let b = barrier.clone(); let f = WaitFuture::new(ps.clone(), flag.clone()); - let counter = counter.clone(); let h = tokio::spawn(async move { b.wait().await; f.await; - counter.add(); }); flags.push(flag); handles.push(h); } barrier.wait().await; - let pending: Vec<_> = flags.iter().filter(|f| !f.load(Ordering::SeqCst)).collect(); - ps.wake(); - task::yield_now().await; - assert_eq!(counter.count(), 33); - - for f in &pending { - f.store(true, Ordering::SeqCst); + let mut ready: Vec<_> = Vec::new(); + let mut pending: Vec<_> = Vec::new(); + for (i, h) in handles.into_iter().enumerate() { + if i % 2 == 0 { + ready.push(h); + flags[i].store(true, Ordering::SeqCst); + } else { + pending.push(h); + } } ps.wake(); - for h in handles { - h.await.unwrap(); + let results = future::join_all(ready).await; + assert_eq!(results.len(), 33); + assert!(results.into_iter().all(|r| r.is_ok())); + + for (i, f) in flags.iter().enumerate() { + if i % 2 != 0 { + f.store(true, Ordering::SeqCst); + } } - assert_eq!(counter.count(), 65); + ps.wake(); + let results = future::join_all(pending).await; + assert_eq!(results.len(), 32); + assert!(results.into_iter().all(|r| r.is_ok())); } From 63a69dd76b5321405ebe9b5851e7acd97b62af9c Mon Sep 17 00:00:00 2001 From: HoshimiP Date: Fri, 28 Nov 2025 19:05:32 +0800 Subject: [PATCH 4/4] use try_join_all --- tests/async.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/tests/async.rs b/tests/async.rs index 8fc99fb..4c7fa8a 100644 --- a/tests/async.rs +++ b/tests/async.rs @@ -82,9 +82,7 @@ async fn async_wake_many() { } } ps.wake(); - let results = future::join_all(ready).await; - assert_eq!(results.len(), 33); - assert!(results.into_iter().all(|r| r.is_ok())); + future::try_join_all(ready).await.unwrap(); for (i, f) in flags.iter().enumerate() { if i % 2 != 0 { @@ -92,7 +90,5 @@ async fn async_wake_many() { } } ps.wake(); - let results = future::join_all(pending).await; - assert_eq!(results.len(), 32); - assert!(results.into_iter().all(|r| r.is_ok())); + future::try_join_all(pending).await.unwrap(); }