mirror of
https://git.sync.wtf/troed/oc-ls-stats.git
synced 2026-08-31 09:43:38 +03:00
29 lines
819 B
TypeScript
29 lines
819 B
TypeScript
import { test } from "node:test"
|
|
import assert from "node:assert/strict"
|
|
import { backoffDelayMs } from "./src/stats.ts"
|
|
|
|
test("first failure retries after the base delay", () => {
|
|
assert.equal(backoffDelayMs(1), 1000)
|
|
})
|
|
|
|
test("second failure doubles the delay", () => {
|
|
assert.equal(backoffDelayMs(2), 2000)
|
|
})
|
|
|
|
test("delay grows exponentially", () => {
|
|
assert.equal(backoffDelayMs(3), 4000)
|
|
assert.equal(backoffDelayMs(4), 8000)
|
|
})
|
|
|
|
test("delay is capped at the maximum", () => {
|
|
assert.equal(backoffDelayMs(5), 10000)
|
|
assert.equal(backoffDelayMs(10), 10000)
|
|
assert.equal(backoffDelayMs(20), 10000)
|
|
})
|
|
|
|
test("uses provided base and max", () => {
|
|
assert.equal(backoffDelayMs(1, 200, 5000), 200)
|
|
assert.equal(backoffDelayMs(5, 200, 5000), 3200)
|
|
assert.equal(backoffDelayMs(20, 200, 5000), 5000)
|
|
})
|