-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
ci: Run loom test in tokio-util #7536
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
.github/workflows/loom.yml
Outdated
- name: Run CancellationToken Loom tests | ||
run: | | ||
LOOM_MAX_PREEMPTIONS=1 LOOM_MAX_BRANCHES=10000 \ | ||
RUSTFLAGS="-C debug_assertions --cfg loom --cfg tokio_unstable" \ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this 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.
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).
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 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 |
There was a problem hiding this 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
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