Skip to content

Commit d11b77e

Browse files
author
tamilr0727-ux
committed
test(utils): check boundary robustness of rate limit TTL timers (Variation 3)
1 parent e6b5723 commit d11b77e

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

utils/time.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,25 @@ describe('getSecondsUntilUTCMidnight — sliding window boundary robustness', ()
264264
vi.useRealTimers();
265265
});
266266

267+
it('verifies utility guarantees keys expire exactly at window limit across a sliding range', () => {
268+
// Target inputs: Sliding time range approaching midnight in Asia/Kolkata (UTC+5:30)
269+
// Local midnight happens at UTC 18:30:00
270+
const slidingCases: [string, number][] = [
271+
['2024-06-15T17:30:00.000Z', 3600], // 1 hour before local midnight
272+
['2024-06-15T18:00:00.000Z', 1800], // 30 mins before local midnight
273+
['2024-06-15T18:29:59.000Z', 1], // 1 second before local midnight
274+
['2024-06-15T18:30:00.000Z', 86400], // Exactly local midnight (resets to full day)
275+
];
276+
277+
for (const [utcTime, expectedTTL] of slidingCases) {
278+
vi.setSystemTime(new Date(utcTime));
279+
const seconds = getSecondsUntilMidnightInTimezone('Asia/Kolkata');
280+
281+
// Assert that outputs match guarantees keys expire exactly at window limit
282+
expect(seconds).toBe(expectedTTL);
283+
}
284+
});
285+
267286
it('returns correct TTL across a sliding window of times approaching UTC midnight', () => {
268287
// Verifies that the utility guarantees keys expire exactly at the window limit.
269288
// Each entry is [UTC time string, expected seconds until next midnight].

0 commit comments

Comments
 (0)