Skip to content

make flow tests deterministic - #11

Merged
umputun merged 1 commit into
masterfrom
stabilise-flow-tests
Aug 19, 2026
Merged

make flow tests deterministic#11
umputun merged 1 commit into
masterfrom
stabilise-flow-tests

Conversation

@paskal

@paskal paskal commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Two tests in the root package were decided by the scheduler rather than by the code under test.

TestFlowWithTimeout gave 100 inputs to 40 workers sleeping a second each, so the work needed exactly the three seconds of its own deadline, and which of the two won decided whether the flow was cancelled at all. It failed roughly one run in ten locally. The test now releases progress itself, as many inputs as there are workers and no more, so the deadline always lands with inputs left over, and it asserts on how much was processed rather than on elapsed time. It also drops from 3s to 0.5s.

The cancelled-Send path in merge was covered only when a merge goroutine happened to be blocked there at cancellation. That moved the reported coverage between runs of the same commit - the two builds of the head of #5 reported 88.7% and 87.8% - which is why coveralls fails PRs in this repo at random, including the doc-only #9. TestFlowParallelCanceledOnMerge covers both paths on every run: the stage below the merge never reads its input, so the record emitted by the first worker can only leave through the cancelled context, while the second worker closes without emitting.

Root package coverage is now identical on every run, verified over 20 plain runs, race runs and isolated runs.

The pool package still varies by about 1.2%, in the worker select in Go where the parent context and the errgroup context are both ready and go picks either branch. No test can pin that down without changing how the pool reports cancellation, so it is left alone - worth knowing since #6 starts measuring pool on CI.

@paskal
paskal requested a review from umputun as a code owner August 19, 2026 05:32
@paskal paskal closed this Aug 19, 2026
@paskal
paskal deleted the stabilise-flow-tests branch August 19, 2026 05:33
@coveralls

coveralls commented Aug 19, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 32220042359

Coverage increased (+0.4%) to 90.618%

Details

  • Coverage increased (+0.4%) from the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 469
Covered Lines: 425
Line Coverage: 90.62%
Coverage Strength: 2715.67 hits per line

💛 - Coveralls

@paskal
paskal restored the stabilise-flow-tests branch August 19, 2026 05:33
@paskal paskal reopened this Aug 19, 2026
TestFlowWithTimeout gave 100 inputs to 40 workers sleeping a second each,
so the work needed exactly the three seconds of its own deadline and the
race between them decided whether the flow was canceled at all. It failed
about one run in ten. Progress is now released by the test, one input per
worker and no more, so the deadline always lands with inputs left and the
assertion counts what was processed instead of measuring elapsed time.
The test also takes 0.5s instead of 3s.

The cancellation path in merge was covered only when a merge goroutine
happened to be blocked in Send at cancellation, which moved the reported
coverage between identical runs and failed the coveralls check on pull
requests. TestFlowParallelCanceledOnMerge covers both paths every run: the
stage below the merge never reads its input, so the record emitted by the
first worker can only leave through the canceled context, while the second
worker closes its channel without emitting.
@paskal
paskal force-pushed the stabilise-flow-tests branch from bb6e12b to 7224ab2 Compare August 19, 2026 05:36
@umputun
umputun merged commit b7ab593 into master Aug 19, 2026
7 checks passed
@umputun
umputun deleted the stabilise-flow-tests branch August 19, 2026 05:54
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.

3 participants