mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 12:02:50 +08:00
M003: add TeamSpeak reconnect recovery
This commit is contained in:
1 parent
8c7a940de5
commit
3cca211ae9
10 files changed
+362
-98
No files matched your search
@@ -0,0 +1,19 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { WebSpeakError } from "../src/errors.js";
|
||||
import { RECONNECT_WINDOW_MS, isRecoverable, reconnectDelayMs, reconnectWindowOpen } from "../src/server/reconnect-policy.js";
|
||||
|
||||
test("reconnect backoff follows the bounded policy and applies deterministic jitter", () => {
|
||||
assert.deepEqual([1, 2, 3, 4, 5, 6, 8].map((attempt) => reconnectDelayMs(attempt, () => 0.5)), [1000, 2000, 4000, 8000, 15000, 30000, 30000]);
|
||||
assert.equal(reconnectDelayMs(1, () => 0), 900);
|
||||
assert.equal(reconnectDelayMs(1, () => 1), 1100);
|
||||
assert.equal(reconnectDelayMs(0, () => 0.5), 1000);
|
||||
});
|
||||
|
||||
test("reconnect eligibility distinguishes transient failures from authentication failures", () => {
|
||||
assert.equal(isRecoverable(new WebSpeakError("unreachable", "offline", true)), true);
|
||||
assert.equal(isRecoverable(new WebSpeakError("authentication_failed", "bad password", false)), false);
|
||||
assert.equal(isRecoverable(null), true);
|
||||
assert.equal(reconnectWindowOpen(10_000, 10_000 + RECONNECT_WINDOW_MS - 1), true);
|
||||
assert.equal(reconnectWindowOpen(10_000, 10_000 + RECONNECT_WINDOW_MS), false);
|
||||
});
|
||||
@@ -14,6 +14,18 @@ test("connection state machine accepts the normal lifecycle and rejects illegal
|
||||
assert.throws(() => machine.transition("connected"), /Illegal connection state transition/);
|
||||
});
|
||||
|
||||
test("connection state machine can retry a transient authentication phase", () => {
|
||||
const machine = new ConnectionStateMachine();
|
||||
machine.transition("connecting");
|
||||
machine.transition("authenticating");
|
||||
machine.transition("reconnecting");
|
||||
machine.transition("connecting");
|
||||
machine.transition("authenticating");
|
||||
machine.transition("syncing");
|
||||
machine.transition("connected");
|
||||
assert.equal(machine.state, "connected");
|
||||
});
|
||||
|
||||
test("managed session teardown is idempotent and reaches idle even when cleanup fails", async () => {
|
||||
const manager = new SessionManager();
|
||||
let cleanupCalls = 0;
|
||||
|
||||
Reference in new issue
Block a user