From 6b1302465dc40198d209eb6947164e364c10d519 Mon Sep 17 00:00:00 2001 From: mox692 Date: Thu, 6 Mar 2025 23:55:29 +0900 Subject: [PATCH] chore: enable loom tests for tokio-util --- .github/labeler.yml | 2 ++ .github/workflows/loom.yml | 16 ++++++++++++++++ tokio-util/Cargo.toml | 3 +++ tokio-util/src/cfg.rs | 6 ++++++ tokio-util/src/sync/mod.rs | 2 ++ tokio-util/src/sync/tests/mod.rs | 4 +++- 6 files changed, 32 insertions(+), 1 deletion(-) diff --git a/.github/labeler.yml b/.github/labeler.yml index b69490cc2a9..a9fc36a3869 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -2,6 +2,8 @@ R-loom-sync: - tokio/src/sync/* - tokio/src/sync/**/* +- tokio-util/src/sync/* +- tokio-util/src/sync/**/* R-loom-time-driver: - tokio/src/runtime/time/* diff --git a/.github/workflows/loom.yml b/.github/workflows/loom.yml index b25f9ac5e30..9dc60019eda 100644 --- a/.github/workflows/loom.yml +++ b/.github/workflows/loom.yml @@ -39,6 +39,22 @@ jobs: run: cargo test --lib --release --features full -- --nocapture sync::tests working-directory: tokio + loom-util-sync: + name: loom tokio-util::sync + # base_ref is null when it's not a pull request + if: github.repository_owner == 'tokio-rs' && (contains(github.event.pull_request.labels.*.name, 'R-loom-sync') || (github.base_ref == null)) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install Rust ${{ env.rust_stable }} + uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ env.rust_stable }} + - uses: Swatinem/rust-cache@v2 + - name: run tests + run: cargo test --lib --release --features default -- --nocapture sync::tests + working-directory: tokio-util + loom-time-driver: name: loom time driver # base_ref is null when it's not a pull request diff --git a/tokio-util/Cargo.toml b/tokio-util/Cargo.toml index 6160e301604..4c4f33092d8 100644 --- a/tokio-util/Cargo.toml +++ b/tokio-util/Cargo.toml @@ -58,6 +58,9 @@ futures-test = "0.3.5" parking_lot = "0.12.0" tempfile = "3.1.0" +[target.'cfg(loom)'.dev-dependencies] +loom = { version = "0.7", features = ["futures", "checkpoint"] } + [package.metadata.docs.rs] all-features = true # enable unstable features in the documentation diff --git a/tokio-util/src/cfg.rs b/tokio-util/src/cfg.rs index 4035255aff0..dd0374d76f6 100644 --- a/tokio-util/src/cfg.rs +++ b/tokio-util/src/cfg.rs @@ -69,3 +69,9 @@ macro_rules! cfg_time { )* } } + +macro_rules! cfg_loom { + ($($item:item)*) => { + $( #[cfg(loom)] $item )* + } +} diff --git a/tokio-util/src/sync/mod.rs b/tokio-util/src/sync/mod.rs index 1ae1b7ee452..7299e04d2f5 100644 --- a/tokio-util/src/sync/mod.rs +++ b/tokio-util/src/sync/mod.rs @@ -13,3 +13,5 @@ pub use poll_semaphore::PollSemaphore; mod reusable_box; pub use reusable_box::ReusableBoxFuture; + +mod tests; diff --git a/tokio-util/src/sync/tests/mod.rs b/tokio-util/src/sync/tests/mod.rs index 8b137891791..b420d0f3860 100644 --- a/tokio-util/src/sync/tests/mod.rs +++ b/tokio-util/src/sync/tests/mod.rs @@ -1 +1,3 @@ - +cfg_loom! { + mod loom_cancellation_token; +}