Fix flaky test_unique_id by making ID counter thread-local - #4
Merged
Conversation
`test_unique_id` reset the global ID counter and asserted exact values
(_1, _2, foo3), but the counter was a process-global AtomicUsize. Rust
runs tests in parallel within a binary, so other tests calling unique_id
(via layout -> acyclic's unique_id("rev")) concurrently bumped the
counter between assertions, intermittently producing "_3" instead of
"_2".
Generated IDs only need to be unique within a single graph, and a layout
runs entirely on one thread, so a thread-local counter is correct and
removes the cross-test interference. dagre layout has no internal
parallelism, and nothing relies on the counter being shared across
threads.
Verified deterministic over 150 consecutive runs of the dagre test
binary; full workspace suite green.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Merged
cmwright
added a commit
that referenced
this pull request
Jun 9, 2026
Bump workspace crates to 0.1.2 and publish the fixes landed since 0.1.1: - Fix overlapping parallel edges between same node pair (#3) - Fix flaky test_unique_id: make ID counter thread-local (#4) Update inter-crate dependency pins (mermaid-core -> mermaid-dagre, mermaid-rs-cli -> mermaid-core) to 0.1.2. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
util::tests::test_unique_idwas flaky, intermittently failing with:Reproduced reliably (~1 in 18 runs of the dagre test binary).
Root cause
The test resets the global ID counter and asserts exact values (
_1,_2,foo3). ButID_COUNTERwas a process-globalAtomicUsize, and Rust runs tests in parallel within a test binary. Other tests that callunique_idconcurrently — chiefly vialayout()→acyclic'sunique_id("rev")— bumped the counter between this test's assertions, so the second call returned_3instead of_2.Fix
Make the counter
thread_local!. Generated IDs only need to be unique within a single graph, and a dagre layout runs entirely on one thread (no rayon / thread spawning in the layout path), so a per-thread counter is correct. Each test thread now gets its own counter, eliminating cross-test interference while preserving the exact-value assertions.Nothing relies on the counter being shared across threads, and
add_dummy_nodeonly consultsunique_idon a name collision, so normal layout output (bare_d/_ep/_rootprefixes) is unchanged.Testing
🤖 Generated with Claude Code