Initial commit
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { InstallationLimiter } from '../src/server/installation-limiter.js'
|
||||
|
||||
describe('InstallationLimiter', () => {
|
||||
it('enforces a bounded window independently per installation', () => {
|
||||
const limiter = new InstallationLimiter(2, 1_000)
|
||||
expect(limiter.consume('first', 0)).toBe(true)
|
||||
expect(limiter.consume('first', 1)).toBe(true)
|
||||
expect(limiter.consume('first', 2)).toBe(false)
|
||||
expect(limiter.consume('second', 2)).toBe(true)
|
||||
expect(limiter.consume('first', 1_000)).toBe(true)
|
||||
})
|
||||
|
||||
it('fails closed when too many active installation counters exist', () => {
|
||||
const limiter = new InstallationLimiter(2, 1_000)
|
||||
for (let index = 0; index < 10_000; index += 1) {
|
||||
expect(limiter.consume(`installation-${index}`, 0)).toBe(true)
|
||||
}
|
||||
expect(limiter.consume('overflow', 1)).toBe(false)
|
||||
expect(limiter.consume('installation-0', 1)).toBe(true)
|
||||
expect(limiter.consume('overflow', 1_000)).toBe(true)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user