24 lines
837 B
TypeScript
24 lines
837 B
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
DeadlineExceededError,
|
|
remainingDeadlineMs,
|
|
} from "../../../src/platform/resilience/deadline.ts";
|
|
|
|
describe("remainingDeadlineMs", () => {
|
|
it("returns only time remaining from the original absolute deadline", () => {
|
|
expect(remainingDeadlineMs(6_000, 1_000)).toBe(5_000);
|
|
expect(remainingDeadlineMs(6_000, 5_500)).toBe(500);
|
|
expect(() => remainingDeadlineMs(6_000, 6_001)).toThrow(DeadlineExceededError);
|
|
});
|
|
|
|
it("treats the exact deadline instant as zero remaining", () => {
|
|
expect(remainingDeadlineMs(6_000, 6_000)).toBe(0);
|
|
});
|
|
|
|
it("rejects non-finite clock values", () => {
|
|
expect(() => remainingDeadlineMs(Number.POSITIVE_INFINITY, 0)).toThrow(TypeError);
|
|
expect(() => remainingDeadlineMs(10, Number.NaN)).toThrow(TypeError);
|
|
});
|
|
});
|