Skip to content

fix/608 - Fix flaky Throttle middleware test by synchronizing token usage#1016

Merged
VojtechVitek merged 2 commits intogo-chi:masterfrom
OtavioBernardes:chore/tests/intermittent-608
Aug 26, 2025
Merged

fix/608 - Fix flaky Throttle middleware test by synchronizing token usage#1016
VojtechVitek merged 2 commits intogo-chi:masterfrom
OtavioBernardes:chore/tests/intermittent-608

Conversation

@OtavioBernardes
Copy link
Contributor

@OtavioBernardes OtavioBernardes commented Aug 14, 2025

Description:

The TestThrottleRetryAfter test was intermittently failing on CI due to timing and scheduling issues. Previously, it relied on blocking, sleeps, and sequential request batches, making results non-deterministic.

Problem:

  • Tokens could be released before the next batch of requests was issued, causing expected 429 responses to be missed.
  • The test was overly complex and prone to intermittent failures.

Solution:

  • Removed sequential batches and blocking.
  • Dispatched all requests concurrently to a handler with a small processing delay.
  • Only validates total number of successful (200 OK) and throttled (429 Too Many Requests) requests matches the configured limit.
  • Retry-After header is correctly set in throttled responses.

Result:

  • Test is simpler, faster, and reliable on CI.
  • No longer depends on the execution order of goroutines or sequential sleeps to enforce token consumption.
  • Accurately verifies that the throttler enforces the request limit and sets the Retry-After header correctly.

#608

@OtavioBernardes OtavioBernardes force-pushed the chore/tests/intermittent-608 branch from 014ec0b to 4fd8fd5 Compare August 14, 2025 15:38
@OtavioBernardes OtavioBernardes marked this pull request as ready for review August 14, 2025 15:56
Copy link
Contributor

@VojtechVitek VojtechVitek left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you for your contribution! 🎉

@VojtechVitek VojtechVitek merged commit 9040e95 into go-chi:master Aug 26, 2025
10 checks passed
@OtavioBernardes OtavioBernardes deleted the chore/tests/intermittent-608 branch September 2, 2025 00:09
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