55 lines
1.8 KiB
TypeScript
55 lines
1.8 KiB
TypeScript
import { describe, expect, it } from "@suaveplan/testing/runner";
|
|
import { TWOPC_CODES, TwoPcError } from "../error-codes/error-codes.js";
|
|
import { DEFAULT_TIMEOUT_MS, TIMEOUT_CEILING_MS } from "../options/options.js";
|
|
import { assertTimeoutBelowCeiling } from "./timeout-ceiling.js";
|
|
|
|
function expectCeilingError(fn: () => void): TwoPcError {
|
|
try {
|
|
fn();
|
|
} catch (err) {
|
|
expect(err).toBeInstanceOf(TwoPcError);
|
|
const e = err as TwoPcError;
|
|
expect(e.twoPcCode).toBe(TWOPC_CODES.TIMEOUT_CEILING_EXCEEDED);
|
|
return e;
|
|
}
|
|
throw new Error("expected TWOPC_TIMEOUT_CEILING_EXCEEDED");
|
|
}
|
|
|
|
describe("assertTimeoutBelowCeiling", () => {
|
|
it("accepts the default timeoutMs (5000)", { timeout: 5000 }, () => {
|
|
expect(() =>
|
|
assertTimeoutBelowCeiling(DEFAULT_TIMEOUT_MS)
|
|
).not.toThrow();
|
|
});
|
|
|
|
it("accepts a value equal to the ceiling", { timeout: 5000 }, () => {
|
|
expect(() =>
|
|
assertTimeoutBelowCeiling(TIMEOUT_CEILING_MS)
|
|
).not.toThrow();
|
|
});
|
|
|
|
it("rejects timeoutMs above the ceiling", { timeout: 5000 }, () => {
|
|
expectCeilingError(() =>
|
|
assertTimeoutBelowCeiling(TIMEOUT_CEILING_MS + 1)
|
|
);
|
|
});
|
|
|
|
it("rejects zero", { timeout: 5000 }, () => {
|
|
expectCeilingError(() => assertTimeoutBelowCeiling(0));
|
|
});
|
|
|
|
it("rejects negative values", { timeout: 5000 }, () => {
|
|
expectCeilingError(() => assertTimeoutBelowCeiling(-1));
|
|
});
|
|
|
|
it("rejects NaN", { timeout: 5000 }, () => {
|
|
expectCeilingError(() => assertTimeoutBelowCeiling(Number.NaN));
|
|
});
|
|
|
|
it("rejects Infinity", { timeout: 5000 }, () => {
|
|
expectCeilingError(() =>
|
|
assertTimeoutBelowCeiling(Number.POSITIVE_INFINITY)
|
|
);
|
|
});
|
|
});
|