Skip to content

test(demo): make the sibling-failure test wait for its third change before failing - #1181

Draft
sbalabanov wants to merge 1 commit into
mainfrom
sergeyb/test-demo-sibling-failure-handshake
Draft

sbalabanov wants to merge 1 commit into
mainfrom
sergeyb/test-demo-sibling-failure-handshake

Conversation

@sbalabanov

@sbalabanov sbalabanov commented Dec 3, 2026 •

Copy link
Copy Markdown
Collaborator

TLDR: A demo test could hang forever because two goroutines raced; the test now makes one wait for the other so the hang cannot happen.

Summary

TestSiblingFailureDoesNotCancelInFlightLand hung until the Bazel timeout under the race detector (about 1 in 10 runs, measured during the flakiness investigation).

  • Cause: change 2's Land blocks until change 3's readiness hook closes siblingsCancelled, which only happens after the gate is cancelled. Change 1's hook cancels the gate by failing as soon as Land starts. If change 1 failed before change 3 reached Readiness.Wait, the runner skipped change 3 (its gate was already cancelled), nothing closed siblingsCancelled, and Land blocked forever. The production code is correct; the test did not enforce the order it relies on.
  • Fix: change 1's hook now also waits on a thirdWaiting channel that change 3 closes on entering Wait, so the gate cannot cancel before change 3 is inside Wait. Test-only, no timeouts added.

Test Plan

Run locally from the repo root:

  • ./tool/bazel test //service/submitqueue/demo:go_default_test - PASSED
  • Stress, targeted test under race, 10 runs x 300 iterations at GOMAXPROCS=1 (3,000 iterations): ./tool/bazel test //service/submitqueue/demo:go_default_test --@rules_go//go/config:race --build_tests_only --test_arg=-test.run='^TestSiblingFailureDoesNotCancelInFlightLand$' --test_arg=-test.cpu=1 --test_arg=-test.count=300 --runs_per_test=10 --nocache_test_results - 10/10 PASSED
  • Whole package under race, 100 runs: ./tool/bazel test //service/submitqueue/demo:go_default_test --@rules_go//go/config:race --build_tests_only --runs_per_test=100 --runs_per_test_detects_flakes --nocache_test_results - 100/100 PASSED (run with --local_test_jobs=8 instead of 32 on a shared host)
  • make fmt lint check-gazelle check-tidy - passed
  • Not run here: reproducing the hang on the unfixed test (about 1 in 10 runs under race, measured during the flakiness investigation). To reproduce, check out the parent commit and run ./tool/bazel test //service/submitqueue/demo:go_default_test --@rules_go//go/config:race --build_tests_only --test_arg=-test.run='^TestSiblingFailureDoesNotCancelInFlightLand$' --test_arg=-test.cpu=1 --test_arg=-test.count=300 --runs_per_test=5 --nocache_test_results --test_timeout=120; hung runs hit the 120s timeout (the timeout flag only bounds the demonstration and is not part of the test).

🤖 Generated with Claude Code

…efore failing

TestSiblingFailureDoesNotCancelInFlightLand hung until the Bazel timeout in about 1 of 10 runs under the race detector.

Change 2's Land blocks until change 3's readiness hook closes siblingsCancelled, which happens only after the gate is cancelled. Change 1's hook cancels the gate by failing as soon as Land starts. If change 1 failed before change 3 reached Readiness.Wait, the runner skipped change 3 because its gate was already cancelled, so nothing ever closed siblingsCancelled and Land blocked forever. The production code is correct; the test did not enforce the order it relies on.

Change 1's hook now also waits for a thirdWaiting channel that change 3 closes on entering Wait, so the gate cannot cancel before change 3 is inside Wait.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

@sbalabanov sbalabanov left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[flaky-1-f1-reviewer] nit: PR description only. The Test Plan line "The pre-fix hang demonstration (optional command in the spec) was not run." refers to a document that readers of this public repository cannot see. The Summary's "about 1 of 10 runs" is a pre-fix rate that this PR did not measure. Consider replacing that bullet with a self-contained repro that says where the rate comes from, for example: "Repro (not run here): the targeted stress command above, run on the parent commit, hangs until the test timeout; an earlier investigation saw the whole package hang in about 1 of 10 race runs." That also gives the description the repro step a bug fix should have.

Verdict: satisfied with head b119828; the nit above is optional. Checked against run.go:

  • Ordering: nothing can cancel the gate before change 3 enters Wait. Change 1 is parked on thirdWaiting and change 2 on siblingsCancelled, and Open/Wait succeed for changes 2 and 3. So change 3 always passes the gate checks at run.go:221, :225 and :259, in every schedule, including GOMAXPROCS=1.
  • No double close: each close runs once per iteration. There is one forEachChange, one Wait per change, and each -test.count iteration makes fresh channels.
  • Coverage kept: Land is in flight before change 1 fails and returns only after the gate is cancelled. A regression that ran Land on the gate would fail on assert.NoError(t, landErr) instead of hanging.
  • Rules and scope: no sleep, no timeout, one hazard-comment line, only run_test.go.
  • Alternatives: none smaller. Having Land wait on a gate captured from change 1's hook would make change 3 unnecessary, but it is a larger rewrite.

@sbalabanov

Copy link
Copy Markdown
Collaborator Author

[flaky-1-f1-implementer] fixed in PR body: replaced the spec reference in the Test Plan with a self-contained, not-run-here repro command and credited the failure rate to the flakiness investigation.

This branch has not been deployed

No deployments
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