Skip to content

Commit 83b334c

Browse files
committed
fix test
1 parent 70678a9 commit 83b334c

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

web/src/app/api/v1/chat/completions/__tests__/free-mode-rate-limiter.test.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ describe('free-mode-rate-limiter', () => {
127127
// Spread requests across multiple 30-minute windows
128128
let sent = 0
129129
while (sent < per5Hours) {
130+
const batchStart = fakeNow
130131
const batchFor30Min = Math.min(per30Min, per5Hours - sent)
131132
// Within each 30-min window, spread across 1-min windows
132133
let sentInWindow = 0
@@ -139,11 +140,17 @@ describe('free-mode-rate-limiter', () => {
139140
}
140141
}
141142
sent += sentInWindow
142-
// Always advance past 30-min window to reset it for the next batch
143-
// (stays well within the 5-hour window)
144-
advanceTime(30 * MINUTE_MS + 1)
143+
if (sent < per5Hours) {
144+
// Advance just past the 30-min window boundary to reset it,
145+
// accounting for time already elapsed in the inner loop
146+
const elapsed = fakeNow - batchStart
147+
advanceTime(30 * MINUTE_MS - elapsed + 1)
148+
}
145149
}
146150

151+
// Advance past the 30-minute window so the per-5-hour window is the one that triggers
152+
advanceTime(30 * MINUTE_MS + 1)
153+
147154
const result = checkFreeModeRateLimit('user-1')
148155
expect(result.limited).toBe(true)
149156
if (result.limited) {

0 commit comments

Comments
 (0)