Skip to main content
This release is 23 versions behind 1.4.9 — the latest version of @fedify/fedify. Jump to latest

Built and signed on GitHub Actions

An ActivityPub/fediverse server framework

This package works with Node.js, Deno, Bun
This package works with Node.js
This package works with Deno
This package works with Bun
JSR Score
94%
Published
3 months ago (1.3.3)
Package root>federation>retry.test.ts
import { assertEquals } from "jsr:/@std/assert@^0.226.0/assert-equals"; import { assertNotEquals } from "jsr:/@std/assert@^0.226.0/assert-not-equals"; import { AssertionError } from "jsr:/@std/assert@^0.226.0/assertion-error"; import { test } from "../testing/mod.ts"; import { createExponentialBackoffPolicy } from "./retry.ts"; test("createExponentialBackoffPolicy()", () => { const policy = createExponentialBackoffPolicy({ maxAttempts: 4, }); const noMatter = Temporal.Duration.from({ seconds: 0 }); for (let i = 0; i < 10; i++) { assertDurationRange( policy({ elapsedTime: noMatter, attempts: 0 }), { seconds: 1 }, { seconds: 2 }, ); } for (let i = 0; i < 10; i++) { assertDurationRange( policy({ elapsedTime: noMatter, attempts: 1 }), { seconds: 2 }, { seconds: 4 }, ); } for (let i = 0; i < 10; i++) { assertDurationRange( policy({ elapsedTime: noMatter, attempts: 2 }), { seconds: 4 }, { seconds: 8 }, ); } for (let i = 0; i < 10; i++) { assertDurationRange( policy({ elapsedTime: noMatter, attempts: 3 }), { seconds: 8 }, { seconds: 16 }, ); } assertEquals(policy({ elapsedTime: noMatter, attempts: 4 }), null); }); function assertDurationRange( actual: Temporal.Duration | null, min: Temporal.DurationLike, max: Temporal.DurationLike, ) { assertNotEquals(actual, null); if (actual == null) return; const minDuration = Temporal.Duration.from(min); const maxDuration = Temporal.Duration.from(max); if ( Temporal.Duration.compare(actual, minDuration) < 0 || Temporal.Duration.compare(actual, maxDuration) > 0 ) { throw new AssertionError( `Expected ${actual} to be between ${min} and ${max}`, ); } }