test: fix race in cargo_compile_with_invalid_code_in_deps#17203
Conversation
…_in_deps Replace with_stderr_data (exact unordered match) with with_stderr_contains (partial patterns) in the cargo_compile_with_invalid_code_in_deps test. The test previously expected both "bar" and "baz" compilation errors in the output. Due to a race condition in parallel compilation, one job can finish before the other starts, producing only one error and causing the test to fail flakily with the second error line missing. Using with_stderr_contains with partial patterns ([..]) ensures the test passes regardless of whether one or both compilation errors appear. Fixes: #17161 Signed-off-by: Functionhx <[email protected]>
|
Thanks for the pull request, and welcome! The Rust Project is excited to review your changes, and you should hear from @weihanglo (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
Why was this reviewer chosen?The reviewer was selected based on:
|
|
This won't fix the problem, because it is still checking for both crates to be built. |
| "#]] | ||
| .unordered(), | ||
| ) | ||
| .with_stderr_contains("[COMPILING] bar v0.1.0 [..]") |
There was a problem hiding this comment.
Thanks for the contribution.
We probably don't want to go back and use contains methods. Please see
cargo/crates/cargo-test-support/src/compare.rs
Lines 3 to 7 in 2ceefa0
and
cargo/crates/cargo-test-support/src/lib.rs
Lines 807 to 822 in 2ceefa0
Have you reproduced it? Could you find other means to fix it, for example with -j1?
There was a problem hiding this comment.
Thanks. Switched to -j1 to force serial compilation and restored with_stderr_data -- makes the output deterministic without needing partial matches. PTAL.
There was a problem hiding this comment.
The other way is this:
[COMPILING] ba[..] v0.1.0 ([ROOT]/ba[..])
...
[ERROR] could not compile `ba[..]` (lib) due to 1 previous error
...
It may work even without -j1. I haven't checked why this test needs two dependencies though.
|
Reminder, once the PR becomes ready for a review, use |
3d72d0a to
c37011d
Compare
|
Thanks for catching that. I've updated the fix to only check for bar's COMPILING message (removed the baz COMPILING check). The test now verifies that at least one dep compiled and the build errored, without depending on which order the parallel jobs finish. |
c37011d to
6eeb071
Compare
There was a problem hiding this comment.
Thanks, I misunderstood the main concern.I'll deepseek!
6eeb071 to
f0a9c26
Compare
…pile_with_invalid_code_in_deps Replace with_stderr_contains (deprecated, checks for both bar and baz) with -j1 for serial compilation and with_stderr_data using ba[..] wildcards so the test only checks for one dep's COMPILING and ERROR messages, not both. Fixes #17161 Signed-off-by: Yuchen Fan <[email protected]>
f0a9c26 to
a12c2c7
Compare
|
Tested both variants locally (Linux x86-64, 32-core, rustc 1.91.0):
The |
Update cargo submodule 29 commits in 59800466c5c41c444d264b1010b4d57e85a7117f..3efb1f477e99b42974b982d939fd100303cdf7db 2026-07-07 15:52:22 +0000 to 2026-07-17 23:53:19 +0000 - refactor(context): normalize in `homedir` instead (rust-lang/cargo#17222) - chore(ci): reflect doc folder move in book deployment (rust-lang/cargo#17235) - refactor(ops): Have cargo-metadata's ops match the command name (rust-lang/cargo#17233) - chore: Flatten src (rust-lang/cargo#17231) - chore: Flatten `src` (rust-lang/cargo#17230) - chore(ci): remove stale libsecret packages (rust-lang/cargo#17229) - perf: Lazily initialize git2 fetch transports (rust-lang/cargo#17226) - test(trim-paths): re-enable lldb debugger tests (rust-lang/cargo#17223) - Include SBOM outputs in fingerprints (rust-lang/cargo#17216) - Update cfg_aliases to 0.2.2 (rust-lang/cargo#17225) - test(trim-paths): exercise GDB on windows-gnu (rust-lang/cargo#17221) - feat(profile): Disable incremental compilation under CI by default (rust-lang/cargo#17220) - Remove myself from review rotation (rust-lang/cargo#17219) - Fix typo in comment in sync (rust-lang/cargo#17217) - docs(ref): Improve handing of built-in profiles (rust-lang/cargo#17213) - fix: dont apply host-config gating to stable behavior (rust-lang/cargo#17198) - chore(deps): update msrv (rust-lang/cargo#17192) - test: fix race in cargo_compile_with_invalid_code_in_deps (rust-lang/cargo#17203) - Rename `-Zno-embed-metadata` to `-Zembed-metadata=no` (rust-lang/cargo#17149) - fix(source): incorrect duplicate package warning (rust-lang/cargo#17204) - Fix manifest schema generation: `TomlDebugInfo` enum-variants doesn't renamed (rust-lang/cargo#17202) - Reduce library search path length in new build dir layout (rust-lang/cargo#17191) - fix(install): Move --debug to Compilation options (rust-lang/cargo#17199) - chore(ci): dogfood `build.warnings` (rust-lang/cargo#17195) - docs(lints): Better match clippy in lint section titles (rust-lang/cargo#17190) - chore: bump to 0.100.0; update changelog (rust-lang/cargo#17189) - docs(ref): Clarify MSRV for lints (rust-lang/cargo#17184) - docs(report): add missing entry for `cargo report future-incompatibilities` (rust-lang/cargo#17188) - Reduce rustc `-L` args used in the new `build-dir` layout (rust-lang/cargo#17168)
Update cargo submodule 29 commits in 59800466c5c41c444d264b1010b4d57e85a7117f..3efb1f477e99b42974b982d939fd100303cdf7db 2026-07-07 15:52:22 +0000 to 2026-07-17 23:53:19 +0000 - refactor(context): normalize in `homedir` instead (rust-lang/cargo#17222) - chore(ci): reflect doc folder move in book deployment (rust-lang/cargo#17235) - refactor(ops): Have cargo-metadata's ops match the command name (rust-lang/cargo#17233) - chore: Flatten src (rust-lang/cargo#17231) - chore: Flatten `src` (rust-lang/cargo#17230) - chore(ci): remove stale libsecret packages (rust-lang/cargo#17229) - perf: Lazily initialize git2 fetch transports (rust-lang/cargo#17226) - test(trim-paths): re-enable lldb debugger tests (rust-lang/cargo#17223) - Include SBOM outputs in fingerprints (rust-lang/cargo#17216) - Update cfg_aliases to 0.2.2 (rust-lang/cargo#17225) - test(trim-paths): exercise GDB on windows-gnu (rust-lang/cargo#17221) - feat(profile): Disable incremental compilation under CI by default (rust-lang/cargo#17220) - Remove myself from review rotation (rust-lang/cargo#17219) - Fix typo in comment in sync (rust-lang/cargo#17217) - docs(ref): Improve handing of built-in profiles (rust-lang/cargo#17213) - fix: dont apply host-config gating to stable behavior (rust-lang/cargo#17198) - chore(deps): update msrv (rust-lang/cargo#17192) - test: fix race in cargo_compile_with_invalid_code_in_deps (rust-lang/cargo#17203) - Rename `-Zno-embed-metadata` to `-Zembed-metadata=no` (rust-lang/cargo#17149) - fix(source): incorrect duplicate package warning (rust-lang/cargo#17204) - Fix manifest schema generation: `TomlDebugInfo` enum-variants doesn't renamed (rust-lang/cargo#17202) - Reduce library search path length in new build dir layout (rust-lang/cargo#17191) - fix(install): Move --debug to Compilation options (rust-lang/cargo#17199) - chore(ci): dogfood `build.warnings` (rust-lang/cargo#17195) - docs(lints): Better match clippy in lint section titles (rust-lang/cargo#17190) - chore: bump to 0.100.0; update changelog (rust-lang/cargo#17189) - docs(ref): Clarify MSRV for lints (rust-lang/cargo#17184) - docs(report): add missing entry for `cargo report future-incompatibilities` (rust-lang/cargo#17188) - Reduce rustc `-L` args used in the new `build-dir` layout (rust-lang/cargo#17168)
Fixes #17161.
Parallel compilation of multiple failing dependency crates can
produce different stderr output depending on which finishes first.
Replaced exact with_stderr_data assertion with with_stderr_contains
partial patterns to eliminate the race.