Skip to content

Check the throttling test against elapsed time, not how many calls slept - #818

Merged
robzolkos merged 1 commit into
mainfrom
fix-flaky-gate-test
Oct 1, 2026
Merged

robzolkos merged 1 commit into
mainfrom
fix-flaky-gate-test

Conversation

@robzolkos

@robzolkos robzolkos commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

TestGateQueuesTenParallelWorkersThroughTheDefaults failed three times on 1 October, on three unrelated PRs (#815, #816, #791), and passed each time on a rerun. It counted how many of the 30 calls the starting token bucket can't cover slept for a refill, and wanted at least 20. On a loaded runner, under the race detector, the calls themselves are slow, refills land between them, and a call that finds a token waiting is served without sleeping. That's correct limiter behaviour, so the count was measuring the runner (it came in at 7, 17 and 19).

Solution

The test now checks the throttling by time: 80 calls against a 50-token bucket refilling at 10 a second can't finish in under 3 seconds on any machine, and a slow one only takes longer. It asserts the run took at least 90% of that, and that at least one call slept (so the wait path and its counter are exercised). The bulkhead and success assertions are unchanged.

To check it still catches a real bug, I broke the limiter to refill five times too fast: the test fails with "30 calls past the starting bucket cannot finish before 30 tokens refill (3s); it took 623ms". It passed 40 runs under the race detector with four copies competing for the CPU. I couldn't reproduce the original flake locally (the old version passed those runs too), so the CI failures above are the evidence for it.


Summary by cubic

Fixes the flaky TestGateQueesTenParallelWorkersThroughTheDefaults test, which throttling assertions counted calls that slept for a refill and required at least 20 of 30. On a loaded runner, refills land between slow calls so fewer calls need to sleep, and the test failed three times in a day on unrelated PRs.

The test now measures throttling by elapsed time instead. It asserts the run takes at least 90% of the time 30 tokens take to refill (3 seconds at 10 per second) — true on any machine, slower ones only take longer — and that at least one call slept, so the wait path is exercised.

Written for commit 5b9f671. Summary will update on new commits.

Review in cubic

The test counted calls that slept for a refill and wanted at least 20. On a
loaded runner refills land between slow calls, so fewer need to sleep, and it
failed three times in a day on unrelated pull requests. It now checks that the
run took as long as the refill rate requires, which holds on any machine, and
that at least one call slept.
Copilot AI balanced review requested due to automatic review settings October 1, 2026 18:41
@github-actions github-actions Bot added the tests Tests (unit and e2e) label Oct 1, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approved

The revised assertion matches the token-bucket configuration and avoids the reported scheduler-dependent flakiness.

Review effort: Balanced
Findings: None

What changed in this PR

Replaces a flaky sleeper-count assertion with an elapsed-time check for default rate limiting.

Changes:

  • Records elapsed time for barriered invocations.
  • Verifies 30 uncovered calls require approximately three seconds of refill time.
  • Retains checks that the wait path and bulkhead limits are exercised.

[!TIP]
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.

File Description
internal/​resilience/​gate_test.go Measures throttling by elapsed refill time instead of scheduler-sensitive sleep counts.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 1 file

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread internal/resilience/gate_test.go Resolved
@robzolkos
robzolkos merged commit 6cdf74d into main Oct 1, 2026
31 checks passed
@robzolkos
robzolkos deleted the fix-flaky-gate-test branch October 1, 2026 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests Tests (unit and e2e)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants