Skip to content

Fix flaky flexbuffers_alloc_check test in cargo test#8965

Merged
jtdavis777 merged 1 commit into
google:masterfrom
RenzoMXD:fix/flaky-rust-alloc-check-test
Mar 9, 2026
Merged

Fix flaky flexbuffers_alloc_check test in cargo test#8965
jtdavis777 merged 1 commit into
google:masterfrom
RenzoMXD:fix/flaky-rust-alloc-check-test

Conversation

@RenzoMXD
Copy link
Copy Markdown
Contributor

@RenzoMXD RenzoMXD commented Mar 7, 2026

The alloc check binaries use a global non-thread-safe allocation counter (static mut NUM_ALLOCS) to assert zero heap allocations on warm builder reuse.
When run via cargo test, the test harness's background threads occasionally allocate, inflating the counter and causing intermittent assertion failures. These binaries are already run reliably via cargo run --bin in RustTest.sh, so disabling them as test targets avoids the flaky behavior with no loss of coverage.
Closes #8961

@RenzoMXD RenzoMXD requested a review from dbaileychess as a code owner March 7, 2026 14:16
@RenzoMXD RenzoMXD mentioned this pull request Mar 7, 2026
@jtdavis777
Copy link
Copy Markdown
Collaborator

Just to make sure I understand your comment, these tests are executed as part of a PR build elsewhere? What is the use of this file?

Thank you for all your help :)

@RenzoMXD
Copy link
Copy Markdown
Contributor Author

RenzoMXD commented Mar 9, 2026

Just to make sure I understand your comment, these tests are executed as part of a PR build elsewhere? What is the use of this file?

RustTest.sh runs two commands that both execute flexbuffers_alloc_check:

  1. Line 46: cargo test -- --quiet — This runs all test targets in the package, including any [[bin]] with #[test] functions. It picks up flexbuffers_alloc_check because it has a #[test] fn no_extra_allocations().

  2. Line 55: cargo run --bin=flexbuffers_alloc_check — This runs the same binary directly via its main() function, without the test harness.

So the same binary was being executed twice in a single CI run — first by cargo test (with the test harness, which adds background threads and extra allocations), then by cargo run --bin (clean, no harness). The flaky failure happens in step 1 because the test harness threads' allocations interfere with the global counter.

With test = false, cargo test skips these binaries entirely, and they only run via the reliable cargo run --bin path.

@jtdavis777 jtdavis777 merged commit 8aa7084 into google:master Mar 9, 2026
50 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rust: flaky CI test

2 participants