Skip to content

test(swarm): wait for every slot to be released before checking the drain - #1181

Merged
jatmn merged 1 commit into
mainfrom
test/swarm-drain-waits-for-slot
Oct 29, 2026
Merged

jatmn merged 1 commit into
mainfrom
test/swarm-drain-waits-for-slot

Conversation

@Vasanthdev2004

@Vasanthdev2004 Vasanthdev2004 commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

What changed

TestConcurrencyCapAndQueueDrains now waits until all five tasks are done and every slot is released, instead of checking the running count the moment the fifth task reads Done. Test-only.

Why

It failed the Zero Review job on #835, which doesn't touch internal/swarm:

--- FAIL: TestConcurrencyCapAndQueueDrains (0.00s)
    lifecycle_test.go:153: after drain running=1 queue=0, want 0/0

A finishing member's task reads Done before its slot is freed. The supervisor in lifecycle.go calls CompleteWithSession, then removeMember, and only then afterExit, whose drain releases the slot. The test waited for Done == 5 and checked Running() straight after, so on a busy runner it could land in that gap. The production order looks deliberate: the barrier is published before the drain on purpose (see the comment above run.finish()), and the slot is freed as part of that drain. So the fix is in the test.

Linked issue

None. Maintainer fix for a CI flake, opened through the internal development process.

Verification

  • With a throwaway 20 ms sleep before t.removeMember in lifecycle.go, the old test fails every run with the same message and the new one passes.
  • A mutation that leaks a slot once the queue is empty still fails the new test, with "timed out waiting for all tasks done and every slot released".
  • 200 runs under -race pass.
  • go vet ./... for windows, linux and darwin, gofmt, git diff --check, go test ./..., the release build and smoke, and govulncheck for linux and windows all pass.

Summary by CodeRabbit

  • Tests
    • Improved test synchronization by waiting for all tasks to complete and for running and queued work to clear before checking results. This makes the concurrency test’s completion checks more consistent.

…rain

A finishing member's task reads Done before its slot is freed: the
supervisor completes the task, removes the member and only then frees
the slot in afterExit. The test waited for Done == 5 and checked the
running count straight after, so a busy runner could see one slot still
held. It now waits for the drain itself.
@github-actions

Copy link
Copy Markdown
Contributor

Zero automated PR review

Verdict: No blockers found

Blockers

  • None found.

Validation

  • [pass] Diff hygiene: git diff --check
  • [pass] Tests: go test ./...
  • [pass] Build: go run ./cmd/zero-release build
  • [pass] Smoke build: go run ./cmd/zero-release smoke

Scope

Head: 79e51c87f2c2
Changed files (1): internal/swarm/lifecycle_test.go

This deterministic review checks validation status and basic diff hygiene. A human reviewer still owns product judgment and design quality.

@coderabbitai

coderabbitai Bot commented Oct 29, 2026

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 4247a07 and 79e51c8.

Files selected for processing: 1
  • internal/swarm/lifecycle_test.go

Included review availability: This review used your included allowance. 4 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 5 reviews per hour.

Walkthrough

The concurrency-cap test now waits for all five tasks to complete and for the team to have no running members or queued specs. Comments note that task completion can occur before slot release.

Changes

Concurrency cap test

Layer / File(s) Summary
Wait for task and team completion
internal/swarm/lifecycle_test.go
The test waits for five completed tasks, zero running members, and an empty queue in one condition. Comments clarify that task completion can precede slot release.

Priority: Low

Estimated code review effort: 1 (Trivial) | ~5 minutes

Change: Other

Suggested reviewers: gnanam1990

Merge Risk: Minimal · up to 79e51

The updated test waits for the full drain before asserting state, with no merge-blocking risk identified.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the test change: it waits for every concurrency slot to be released before checking that the queue drains.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 1 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Billing warning: we have not been able to collect payment for this subscription for more than 72 hours. Please update the payment method or pay any pending invoices in Billing to avoid service interruption.

Comment @coderabbitai help to get the list of available commands.

@jatmn jatmn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🟢 Thanks for the contribution. I do not see any actionable issues from my review.

The test now waits for the actual drain boundary while preserving its initial concurrency-cap check, five-task completion requirement, zero running/queued counts, and exactly-five-launch assertion. The added comment matches the supervisor's completion-before-slot-release order.

Reviewed scope

Surface Contract and result
TestConcurrencyCapAndQueueDrains Five registered tasks; two running and three queued before release; eventually five done, zero occupied slots and zero queued tasks; five launches. All assertions retained.
Completion and cleanup Traced launcher → supervisor → coordinator completion → member removal → execution barrier → slot release/queue drain. Close joins outstanding lifecycle work and watchers.
Changed explanatory comment Accurate for the production order. No production, persistence, protocol, dependency or operator-documentation change.

Validation

  • Focused test: 100 repetitions under -race passed; full internal/swarm package under -race passed; scoped go vet and diff hygiene passed.
  • A 20 ms delay before member removal reproduces the merge-base test's running=1 queue=0 failure; the changed test passes with the same delay.
  • A deliberate permanent slot leak makes the changed test fail at its bounded timeout, confirming that the synchronization repair preserves leak detection.
  • Completed primary inspection, two waves of two independent blind searches, a missing-contract search, candidate reconciliation, intent/attribution audit and final clean-outcome challenge.

Merge readiness

Reviewed head 79e51c87f2c28cb4de6a6547dc25520964111bd5 against merge-base/live main 4247a07aba0f89c3c2597314a33edaede56be70c. The branch is current and mergeable; all 13 reported GitHub checks pass, including race and Linux/macOS/Windows smoke jobs. No duplicate or superseding drain repair, unresolved actionable reviewer request, or scope drift was identified. Author association is COLLABORATOR, so the approved-community-issue requirement does not apply.

Local execution was on Linux. Native macOS/Windows execution and the repository-wide suite were not repeated locally; the exact-head CI results provide those broader checks. The CodeRabbit docstring coverage notice is advisory and does not identify a defect in this test-only change.

@jatmn
jatmn merged commit 2e10a4b into main Oct 29, 2026
13 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.

2 participants