(executionTimes: number[], interval: number, intervalCap: number, jitterMilliseconds = Math.min(25, Math.trunc(interval * 0.2)))
| 4 | import PQueue from '../source/index.js'; |
| 5 | |
| 6 | const assertSlidingWindow = (executionTimes: number[], interval: number, intervalCap: number, jitterMilliseconds = Math.min(25, Math.trunc(interval * 0.2))) => { |
| 7 | const minimumInterval = Math.max(0, interval - jitterMilliseconds); |
| 8 | |
| 9 | for (let index = intervalCap; index < executionTimes.length; index++) { |
| 10 | const delta = executionTimes[index] - executionTimes[index - intervalCap]; |
| 11 | assert.ok(delta >= minimumInterval, `Task ${index} violated sliding window: ${delta}ms < ${minimumInterval}ms`); |
| 12 | } |
| 13 | }; |
| 14 | |
| 15 | test('strict mode enforces sliding window rate limiting', async () => { |
| 16 | const queue = new PQueue({ |
no outgoing calls
no test coverage detected
searching dependent graphs…