Skip to content

middleware: make throttle tests deterministic - #1194

Open
00200200 wants to merge 1 commit into
go-chi:masterfrom
00200200:fix-608-deterministic-throttle-tests
Open

00200200 wants to merge 1 commit into
go-chi:masterfrom
00200200:fix-608-deterministic-throttle-tests

Conversation

@00200200

Copy link
Copy Markdown

TestThrottleBacklog, TestThrottleTriggerGatewayTimeout, TestThrottleMaximum, and TestThrottleRetryAfter still overlap concurrent requests with time.Sleep in the handler. On CI that overlap is racy, so the suite fails intermittently even after #1016 (#608).

Drive those cases with channel handshakes instead: occupy processing/backlog tokens, then assert success, 429, backlog timeout, context cancel, and Retry-After without depending on wall-clock scheduling. TestThrottleCustomStatusCode is unchanged aside from closing response bodies.

Fixes #608

Test plan

  • go test -race -count=50 -timeout 120s ./middleware -run TestThrottle
  • go test -race -count=1 ./...
  • go vet ./...

Replace sleep-based throttle tests with channel handshakes so CI no longer depends on handler duration overlapping request batches (issue 608).

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.

Refactor throttle middleware tests as prone to intermittent failure

1 participant