import { describe, expect, it } from "vitest"; import type { SessionState } from "../logging/diagnostic-session-state.js"; import {
calculateBackoffMs,
getCommandPollSuggestion,
pruneStaleCommandPolls,
recordCommandPoll,
resetCommandPollCount,
} from "./command-poll-backoff.js";
describe("command-poll-backoff", () => {
describe("calculateBackoffMs", () => {
it("returns 5s for first poll", () => {
expect(calculateBackoffMs(0)).toBe(5000);
});
it("returns 10s for second poll", () => {
expect(calculateBackoffMs(1)).toBe(10000);
});
it("returns 30s for third poll", () => {
expect(calculateBackoffMs(2)).toBe(30000);
});
it("returns 60s for fourth and subsequent polls (capped)", () => {
expect(calculateBackoffMs(3)).toBe(60000);
expect(calculateBackoffMs(4)).toBe(60000);
expect(calculateBackoffMs(10)).toBe(60000);
expect(calculateBackoffMs(100)).toBe(60000);
});
});
describe("recordCommandPoll", () => {
it("returns 5s on first no-output poll", () => { const state: SessionState = {
lastActivity: Date.now(),
state: "processing",
queueDepth: 0,
}; const retryMs = recordCommandPoll(state, "cmd-123", false);
expect(retryMs).toBe(5000);
expect(state.commandPollCounts?.get("cmd-123")?.count).toBe(0); // First poll = index 0
});
// New output resets count const retryMs = recordCommandPoll(state, "cmd-123", true);
expect(retryMs).toBe(5000); // Back to first poll delay
expect(state.commandPollCounts?.get("cmd-123")?.count).toBe(0);
});
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.