Skip to content

Conversation

pepedinho
Copy link

Added a dedicated CI task to run sync_cancellation_token tests in Loom.

Note:
I was unable to apply the --cfg loom flag to this test because it generated compilation conflicts. Therefore, the test runs without it in this task.

fixes #7271

@ADD-SP ADD-SP added A-tokio-util Area: The tokio-util crate M-sync Module: tokio/sync A-ci Area: The continuous integration setup labels Aug 15, 2025
- name: Run CancellationToken Loom tests
run: |
LOOM_MAX_PREEMPTIONS=1 LOOM_MAX_BRANCHES=10000 \
RUSTFLAGS="-C debug_assertions --cfg loom --cfg tokio_unstable" \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clarify what you mean about not being able to apply --cfg loom? I see it right here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my bad, I removed it in my local tests, but I forgot to remove it in the CI, I will send a commit to fix that

Copy link
Member

@ADD-SP ADD-SP left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are some suggestions in case you are unfamiliar with the tokio project.

You could add loom as dev-dependency gated by cfg(loom), here is an example.

tokio/tokio/Cargo.toml

Lines 159 to 160 in dd74c7c

[target.'cfg(loom)'.dev-dependencies]
loom = { version = "0.7", features = ["futures", "checkpoint"] }

Then, enter the tokio-util directory, an run the following command.

LOOM_MAX_PREEMPTIONS=1 LOOM_MAX_BRANCHES=10000 \
RUSTFLAGS="-C debug_assertions --cfg tokio_unstable --cfg loom" \
 cargo test --features full cancellation_token -- --test-threads=1 --nocapture

You will see several compilation errors, including some use import statements are failed, this is because some module is gated by #![cfg(not(loom))] but tokio-util doesn't has relevant gate. this can be fixed by adding #![cfg(not(loom))] in a proper place.

Once you have finished all compilation errors, you could read the document of loom to understand its usage, and also read existing loom tests as example.

You might also need to mock the std's import by loom, just like what tokio did.

Finally, you can run tests, write tests, and fix tests.

The tokio::net, tokio::fs, and tokio::signal modules are disabled when compiling with --cfg loom. This caused compilation errors in tokio-util and tokio-stream because their wrappers were still trying to use these modules.

This commit adds #[cfg(not(loom))] guards to the affected modules and re-exports, so that loom tests can build and run without attempting to use I/O, fs, or signal APIs (which are not supported under loom).
@pepedinho
Copy link
Author

Thank you very much for your help and your time. I’ve added the guards everywhere they were needed, and now the tests run without any issues using the --cfg loom flag.
Now i run this in ci job :

LOOM_MAX_PREEMPTIONS=1 LOOM_MAX_BRANCHES=10000 \
          RUSTFLAGS="-C debug_assertions --cfg tokio_unstable --cfg loom" \
          cargo test --features full --test sync_cancellation_token -- --test-threads=1 --nocapture

Copy link
Member

@ADD-SP ADD-SP left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the loom as optional dev-dependency of tokio-util, we also need to enable tokio-util/src/sync/tests/loom_cancellation_token.rs as this test is currently ignored.

LOOM_MAX_PREEMPTIONS=1 LOOM_MAX_BRANCHES=10000 \
RUSTFLAGS="-C debug_assertions --cfg tokio_unstable --cfg loom" \
cargo test --features full --test sync_cancellation_token -- --test-threads=1 --nocapture
working-directory: tokio
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
working-directory: tokio
working-directory: tokio-util

run: |
LOOM_MAX_PREEMPTIONS=1 LOOM_MAX_BRANCHES=10000 \
RUSTFLAGS="-C debug_assertions --cfg tokio_unstable --cfg loom" \
cargo test --features full --test sync_cancellation_token -- --test-threads=1 --nocapture
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cargo test --features full --test sync_cancellation_token -- --test-threads=1 --nocapture
cargo test --lib --release --features full -- --test-threads=1 --nocapture loom_cancellation_token

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ci Area: The continuous integration setup A-tokio-util Area: The tokio-util crate M-sync Module: tokio/sync
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Run loom test in tokio-util
3 participants