Skip to content

Commit fb82afd

Browse files
committed
pkg/rate: fix TestMaxParallelRequests flake under CI load
TestMaxParallelRequests configured MaxWaitDuration to 1ms, expecting only the third request to fail once both parallel slots are taken. But MaxWaitDuration is measured from the moment a request is scheduled and also covers the time spent acquiring the parallel-requests semaphore. On a loaded CI runner the scheduling overhead of the very first, uncontended request alone exceeded 1ms, so wait() took the "wait duration exceeds maximum" branch and returned: request would have to wait 0s to be served (maximum wait duration: -215.915µs) failing the require.NoError on request 1 rather than on the intended request 3. Raise MaxWaitDuration to 100ms. That is far above any realistic scheduling jitter for the two uncontended requests, while the third request still fails deterministically because both slots stay occupied for its entire wait window. The test keeps exercising parallel-slot exhaustion, not wall-clock jitter. This commit was prepared with AIL:3. Signed-off-by: André Martins <andre@cilium.io>
1 parent f52ff46 commit fb82afd

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

pkg/rate/api_limiter_test.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,11 +291,18 @@ func TestLimitWaitDurationExceeded(t *testing.T) {
291291

292292
func TestMaxParallelRequests(t *testing.T) {
293293
// Test blocking of max-parallel-requests by allowing two parallel
294-
// requests and having a third request fail due to a very short
295-
// MaxWaitDuration
294+
// requests and having a third request fail because both slots are
295+
// already taken and never free up within MaxWaitDuration.
296+
//
297+
// MaxWaitDuration is measured from the moment a request is scheduled,
298+
// so it also covers the time spent acquiring the parallel-requests
299+
// semaphore. Under a noisy CI environment that scheduling overhead
300+
// alone can exceed a sub-millisecond budget and spuriously fail the
301+
// first two (uncontended) requests. Keep the budget generous enough
302+
// that only the genuinely contended third request fails.
296303
a := NewAPILimiter(hivetest.Logger(t), "foo", APILimiterParameters{
297304
ParallelRequests: 2,
298-
MaxWaitDuration: time.Millisecond,
305+
MaxWaitDuration: 100 * time.Millisecond,
299306
AutoAdjust: true,
300307
}, nil)
301308

0 commit comments

Comments
 (0)