feat(decoder): alarm banner and warning sound when the decoder drops or goes silent during a heat (1.89.25)
This commit is contained in:
1 parent
259945799d
commit
239cac8033
18 files changed
+225
-5
No files matched your search
@@ -0,0 +1,61 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { startFakeDecoder } from "./browser_fake_decoder.js";
|
||||
|
||||
// Decoder alarm (src/decoder_watch.js): the decoder goes away mid-heat -> red banner with
|
||||
// Reconnect / Silence; it comes back -> green "working again, X s without timing".
|
||||
export async function runDecoderAlarmSmoke({ evaluate, navigate, fill, savedState, waitFor }) {
|
||||
const click = id => evaluate(`document.getElementById(${JSON.stringify(id)}).click()`);
|
||||
const submit = id => evaluate(`document.getElementById(${JSON.stringify(id)}).requestSubmit()`);
|
||||
const findEvent = async name => (await savedState()).events.find(event => event.name === name);
|
||||
const findSession = async name => (await savedState()).sessions.find(session => session.name === name);
|
||||
const patchState = async patch => {
|
||||
const current = await savedState();
|
||||
Object.assign(current, patch);
|
||||
assert.equal((await fetch(new URL("/api/state", await evaluate("location.origin")), { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(current) })).ok, true);
|
||||
};
|
||||
const banner = () => evaluate(`(() => { const el = document.getElementById("decoderAlarm"); return { hidden: el.hidden, kind: el.dataset.kind, text: el.textContent, reconnect: Boolean(el.querySelector('[data-decoder-alarm="reconnect"]')), silence: Boolean(el.querySelector('[data-decoder-alarm="silence"]')) }; })()`);
|
||||
|
||||
let decoder = await startFakeDecoder();
|
||||
const port = decoder.port;
|
||||
try {
|
||||
const seeded = await savedState();
|
||||
await patchState({ settings: { ...seeded.settings, autoReconnect: true, wsUrl: `ws://127.0.0.1:${port}` } });
|
||||
await navigate("events", "eventForm");
|
||||
await waitFor(async () => await evaluate('document.getElementById("connectionBadge")?.classList.contains("badge-online")'), "fake decoder connected");
|
||||
await fill("eventForm", { name: "Decoder Alarm Event", date: "2026-09-10", classId: "test_class" });
|
||||
await submit("eventForm");
|
||||
await waitFor(async () => Boolean(await findEvent("Decoder Alarm Event")), "create event");
|
||||
await click("event-manage-" + (await findEvent("Decoder Alarm Event")).id);
|
||||
await fill("sessionForm", { name: "Decoder Alarm Heat", type: "open_practice", durationMin: "5" });
|
||||
await submit("sessionForm");
|
||||
await waitFor(async () => Boolean(await findSession("Decoder Alarm Heat")), "create heat");
|
||||
await patchState({ activeSessionId: (await findSession("Decoder Alarm Heat")).id });
|
||||
await navigate("race_day", "raceDayStart");
|
||||
await waitFor(async () => (await evaluate('document.getElementById("raceDayStart")?.disabled')) === false, "start enabled");
|
||||
assert.equal((await banner()).hidden, true, "no alarm while the decoder is fine");
|
||||
await click("raceDayStart");
|
||||
await waitFor(async () => (await findSession("Decoder Alarm Heat")).status === "running", "heat running");
|
||||
|
||||
await decoder.close(); // the decoder goes away and stays away
|
||||
await waitFor(async () => (await banner()).kind === "lost", "red banner once the decoder has been gone 3 s", 10000);
|
||||
const lost = await banner();
|
||||
assert.match(lost.text, /Decodern tappade anslutningen|Decoder disconnected/);
|
||||
assert.ok(lost.reconnect && lost.silence, "Reconnect and Silence buttons");
|
||||
await evaluate(`document.querySelector('[data-decoder-alarm="silence"]').click()`);
|
||||
await waitFor(async () => !(await banner()).silence && (await banner()).kind === "lost", "silenced: the banner stays, the button goes");
|
||||
|
||||
decoder = await startFakeDecoder(port);
|
||||
await evaluate(`document.querySelector('[data-decoder-alarm="reconnect"]').click()`);
|
||||
await waitFor(async () => (await banner()).kind === "ok" && !(await banner()).hidden, "green banner when the decoder is back");
|
||||
assert.match((await banner()).text, /\d+ s/);
|
||||
await waitFor(async () => (await banner()).hidden, "the green banner goes after 10 s", 15000);
|
||||
console.log("PASS decoder alarm: red banner when the decoder drops mid-heat, silence, reconnect, then 'working again'");
|
||||
} finally {
|
||||
// Pause the heat through the UI (like the OBS popup test), so no running heat leaks into later tests.
|
||||
await evaluate('document.getElementById("raceDayPause")?.click()').catch(() => {});
|
||||
await waitFor(async () => (await findSession("Decoder Alarm Heat"))?.status !== "running", "heat paused").catch(() => {});
|
||||
const cleanup = await savedState();
|
||||
await patchState({ settings: { ...cleanup.settings, autoReconnect: false } });
|
||||
await decoder.close();
|
||||
}
|
||||
}
|
||||
@@ -13,8 +13,9 @@ export async function freePort() {
|
||||
// Accepts the WebSocket upgrade handshake so the frontend's real decoder-connect path
|
||||
// (src/decoder_runtime.js) reaches `connected: true` without a physical AMMC decoder.
|
||||
// sendPassing() pushes a PASSING frame for scenarios that need the app to see a transponder.
|
||||
export async function startFakeDecoder() {
|
||||
const port = await freePort();
|
||||
// `fixedPort`: listen on a port used before (a decoder coming back on the same address).
|
||||
export async function startFakeDecoder(fixedPort = 0) {
|
||||
const port = fixedPort || await freePort();
|
||||
const server = createServer();
|
||||
// The upgraded sockets are intentionally left open (no decoder frames needed), so a
|
||||
// plain server.close() would wait forever for them to end; track and destroy them
|
||||
|
||||
@@ -33,6 +33,7 @@ import { runRaceDayQuickSmoke } from "./browser_race_day_quick.js";
|
||||
import { runDayScheduleSmoke } from "./browser_day_schedule.js";
|
||||
import { runObsPopupSmoke } from "./browser_obs_popup.js";
|
||||
import { runDecoderReconnectSmoke } from "./browser_decoder_reconnect.js";
|
||||
import { runDecoderAlarmSmoke } from "./browser_decoder_alarm.js";
|
||||
import { runRaceControllerSmoke } from "./browser_race_controller.js";
|
||||
import assert from "node:assert/strict";
|
||||
import { spawn } from "node:child_process";
|
||||
@@ -197,6 +198,7 @@ try {
|
||||
await runRaceDayStartSequencesSmoke({ evaluate, navigate, waitFor, pause, base, dialogs });
|
||||
await runObsPopupSmoke({ evaluate, navigate, fill, savedState, waitFor, pause, base, debugPort, dialogs, realClick });
|
||||
await runDecoderReconnectSmoke({ evaluate, navigate, savedState, waitFor, pause, base });
|
||||
await runDecoderAlarmSmoke({ evaluate, navigate, fill, savedState, waitFor });
|
||||
await runRaceControllerSmoke({ evaluate, navigate, savedState, waitFor, pause, base, debugPort });
|
||||
await navigate("classes", "classForm");
|
||||
await send("Network.emulateNetworkConditions", { offline: true, latency: 0, downloadThroughput: -1, uploadThroughput: -1 });
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { decoderAlarm, silentLimitMs } from "../src/decoder_watch.js";
|
||||
|
||||
const t0 = 1_000_000;
|
||||
const running = { status: "running", startedAt: t0 };
|
||||
|
||||
test("no alarm outside a running heat or its count-down", () => {
|
||||
assert.equal(decoderAlarm({ connected: false, disconnectedAt: t0 }, { status: "finished" }, { now: t0 + 60000 }).kind, "ok");
|
||||
assert.equal(decoderAlarm({ connected: false, disconnectedAt: t0 }, { status: "paused", startedAt: t0 }, { now: t0 + 60000 }).kind, "ok");
|
||||
assert.equal(decoderAlarm({ connected: false }, null, { now: t0 }).kind, "ok");
|
||||
});
|
||||
|
||||
test("lost: the decoder link drops during the heat or the count-down, after 3 s", () => {
|
||||
assert.equal(decoderAlarm({ connected: false, disconnectedAt: t0 + 60000 }, running, { now: t0 + 61000 }).kind, "ok", "quick reconnect window");
|
||||
assert.deepEqual(decoderAlarm({ connected: false, disconnectedAt: t0 + 60000 }, running, { now: t0 + 65000 }), { kind: "lost", sinceMs: 5000 });
|
||||
assert.equal(decoderAlarm({ connected: false }, { status: "ready" }, { startPending: true, now: t0 }).kind, "lost", "never connected during the count-down");
|
||||
});
|
||||
|
||||
test("silent: connected but no passing for 30 s, or 3 best laps", () => {
|
||||
assert.equal(silentLimitMs(0), 30000);
|
||||
assert.equal(silentLimitMs(18000), 54000);
|
||||
const decoder = { connected: true, lastPassingAt: t0 + 40000 };
|
||||
assert.equal(decoderAlarm(decoder, running, { now: t0 + 65000 }).kind, "ok");
|
||||
assert.deepEqual(decoderAlarm(decoder, running, { now: t0 + 71000 }), { kind: "silent", sinceMs: 31000 });
|
||||
assert.equal(decoderAlarm(decoder, running, { bestLapMs: 18000, now: t0 + 71000 }).kind, "ok", "slow track: 3 laps of 18 s");
|
||||
assert.equal(decoderAlarm({ connected: true }, running, { now: t0 + 20000 }).kind, "ok", "first 30 s after the start");
|
||||
assert.equal(decoderAlarm({ connected: true, lastPassingAt: t0 - 99999 }, running, { now: t0 + 45000 }).kind, "silent", "a passing before the start doesn't count");
|
||||
assert.equal(decoderAlarm({ connected: true }, { status: "ready" }, { startPending: true, now: t0 + 99999 }).kind, "ok", "no silence alarm before the start");
|
||||
});
|
||||
|
||||
test("practice: no silence alarm (nobody may be driving), but a dropped link still alarms", () => {
|
||||
const practice = { status: "running", startedAt: t0, type: "open_practice" };
|
||||
assert.equal(decoderAlarm({ connected: true }, practice, { now: t0 + 600000 }).kind, "ok");
|
||||
assert.equal(decoderAlarm({ connected: false, disconnectedAt: t0 + 1000 }, practice, { now: t0 + 9000 }).kind, "lost");
|
||||
});
|
||||
@@ -57,3 +57,4 @@ import "./driver_list.test.js";
|
||||
import "./country_flags.test.js";
|
||||
import "./pdf_flags.test.js";
|
||||
import "./local_fonts.test.js";
|
||||
import "./decoder_watch.test.js";
|
||||
Reference in new issue
Block a user