Skip to content

Stabilize two flaky tests: a JIT-safe allocation measurement, and a leak check that waits for the whole release - #128

Merged
electricessence merged 1 commit into
masterfrom
fix/flaky-channel-tests
Nov 12, 2026
Merged

electricessence merged 1 commit into
masterfrom
fix/flaky-channel-tests

Conversation

@electricessence

Copy link
Copy Markdown
Collaborator

Stabilize two flaky tests: TokenTerminalTests.Allocation_Channel and LeakPipelineTests.CreatedTarget_NobodyEverReads_TheReaderIsStillReleased.

Both have been failing gate runs without any code change behind them (the allocation test about one run in three, the leak test now and then). Neither needed a change to the library: the fixes are in the tests.

Allocation_Channel: a measurement artifact

  • The JIT recompiles hot Channel code while the process runs, and the new code allocates less (about 370 down to about 345 bytes a call). The four token variants were measured one after another (the smallest of 14 rounds each), so one variant could be measured before the recompile and exceed the 16-byte slack.
  • Evidence from the failures the author reproduced: the per-round numbers drop from 364-372 to 344-347 bytes after bursts of JIT activity, the failing variant changed from run to run, and the first shape run failed in all three reproductions.
  • Fix: the variants now take turns call by call, with the starting variant rotating, so they always see the same JIT state. The result is the median of 7 rounds, as in the heap-growth test. The slack is unchanged.
  • Before: 3 failures in 16 full-suite runs. After: 0 failures in 51 consecutive full-suite runs (three test hosts at once), then 0 in 6 more on the final tree.

CreatedTarget_NobodyEverReads...: a race in the test, not in the library

  • This one was not reproduced naturally (0 failures in 611 single-test runs and in more than 70 full-suite runs), so what follows is the mechanism a spin observer showed, not a measured cure; there is no recorded failure text to confirm which of the two caused a failure.
  • The test waited for the reader's disposal and then asserted that the command was disposed and the connection released. Those happen after the reader is disposed, on the producer's thread, so a check landing in that gap fails a release that is still under way. Fix: the assertion retries for up to the existing 30 s bound (EventuallyHolds) and still fails with the last failure.
  • A polling condition indexed a list (tally.Readers[0]) while the producer appends to it, and List<T>.Add stores the new size before the item, so a poll can see a null item. The polling conditions (and the same pattern in WaitUntilBlocked) now use is { Disposes: 1 } / is { Reads: >= 2 }.

Not changed

  • The two other copies of the BytesPerCall helper (AllocationQuickWinTests, DerivedNameCostTests) have not flaked and are untouched, though they are measured the same way.

Checks

  • Release and Debug builds: 0 warnings, 0 errors. Tests: 9677 of 9677 pass in both. Samples: 103 of 103 checks pass. Style and analyzers: 0 findings. DocFX: 0 warnings.

🤖 Generated with Claude Code

…eak check that waits for the whole release

Allocation_Channel measured the four token variants one after another; the JIT recompiles hot channel code
mid-run (about 370 to 345 bytes a call), so a variant measured before the recompile could exceed the slack. The
variants now take turns call by call and the result is the median of seven rounds, as in the heap-growth test.

CreatedTarget_NobodyEverReads_TheReaderIsStillReleased checked the command and the connection the moment the reader
was disposed; the producer releases them a moment later on its own thread. It now waits for the whole released
state, and the polling conditions no longer index a list the producer is appending to.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@electricessence
electricessence merged commit 7f12bca into master Nov 12, 2026
2 checks passed
@electricessence
electricessence deleted the fix/flaky-channel-tests branch November 12, 2026 14:53
electricessence added a commit that referenced this pull request Nov 12, 2026
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
electricessence added a commit that referenced this pull request Nov 12, 2026
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
electricessence added a commit that referenced this pull request Nov 12, 2026
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
electricessence added a commit that referenced this pull request Nov 12, 2026
Conflicts: the SingleResult wording in mapping.md and the MappedQuery remarks keep master's text with this branch's
First and Single additions; whats-new keeps both sets of bullets.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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.

1 participant