fix(race): finish the lap you are on, one clock owner, edits survive refresh, participants editable (1.59.0)
This commit is contained in:
1 parent
afb8829b16
commit
db6a9f19e4
16 files changed
+313
-39
No files matched your search
@@ -0,0 +1,60 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { getCompetitorEndTs, getFinishWait } from "../src/timing_logic.js";
|
||||
import { syncParticipantsToSessions, applyFormatToPendingSessions } from "../src/event_race_logic.js";
|
||||
import { keepIdentityById } from "../src/runtime_services.js";
|
||||
|
||||
test("finish the lap: each car's own end, then the heat closes when all crossed or the wait runs out", () => {
|
||||
const flying = { type: "qualification", startMode: "flying", durationMin: 5, startedAt: 0, followUpSec: 10, totalPausedMs: 0 };
|
||||
assert.equal(getCompetitorEndTs(flying, { startTimestamp: 4000 }), 304000, "own clock from own first crossing");
|
||||
const mass = { ...flying, startMode: "position", startedAt: 1000 };
|
||||
assert.equal(getCompetitorEndTs(mass, { startTimestamp: 1000 }), 301000);
|
||||
assert.equal(getCompetitorEndTs({ ...mass, type: "open_practice" }, {}), null, "rolling practice has no end");
|
||||
|
||||
const out = { a: { laps: 10, startTimestamp: 1000, lastLapMs: 30000, finishedAt: 302000 }, b: { laps: 9, startTimestamp: 1000, lastLapMs: 32000 } };
|
||||
const wait = getFinishWait(mass, out);
|
||||
assert.equal(wait.allFinished, false);
|
||||
assert.equal(wait.closeAt, 301000 + 48000, "1.5 x the slow car's own lap, longer than the 10 s follow-up");
|
||||
assert.equal(getFinishWait(mass, out, { maxLapMs: 40000 }).closeAt, 301000 + 40000, "never longer than max lap time");
|
||||
out.b.finishedAt = 320000;
|
||||
assert.equal(getFinishWait(mass, out).allFinished, true);
|
||||
});
|
||||
|
||||
test("the entry list reaches the sessions not run yet", () => {
|
||||
const sessions = [
|
||||
{ id: "p", type: "practice", status: "ready", driverIds: ["a", "b", "c"] },
|
||||
{ id: "q11", name: "Q1 H1", type: "qualification", status: "ready", driverIds: ["a", "b"], manualGridIds: ["a", "b"] },
|
||||
{ id: "q12", name: "Q1 H2", type: "qualification", status: "ready", driverIds: ["c"], manualGridIds: ["c"] },
|
||||
{ id: "q21", name: "Q2 H1", type: "qualification", status: "ready", driverIds: ["a", "b"] },
|
||||
{ id: "q22", name: "Q2 H2", type: "qualification", status: "ready", driverIds: ["c"] },
|
||||
{ id: "done", name: "Q0 H1", type: "qualification", status: "finished", startedAt: 1, driverIds: ["a", "b"] },
|
||||
];
|
||||
syncParticipantsToSessions(sessions, ["a", "b", "c"], ["a", "c", "d"]);
|
||||
const ids = (id) => sessions.find((session) => session.id === id).driverIds;
|
||||
assert.deepEqual(ids("p"), ["a", "c", "d"]);
|
||||
assert.ok(!ids("q11").includes("b") && !ids("q21").includes("b"), "b left every heat to run");
|
||||
assert.deepEqual(ids("q11"), ["a", "d"], "d joins the smallest heat (a tie goes to the lower heat)");
|
||||
assert.deepEqual(ids("q21"), ["a", "d"], "the same heat number in every round");
|
||||
assert.deepEqual(ids("q12"), ["c"]);
|
||||
assert.deepEqual(ids("done"), ["a", "b"], "a run heat is history");
|
||||
});
|
||||
|
||||
test("a changed race format reaches the sessions not run yet", () => {
|
||||
const sessions = [
|
||||
{ type: "qualification", status: "ready", durationMin: 5, startMode: "flying" },
|
||||
{ type: "qualification", status: "finished", startedAt: 1, durationMin: 5 },
|
||||
{ type: "final", status: "ready", durationMin: 5 },
|
||||
{ type: "practice", status: "ready", durationMin: 5 },
|
||||
];
|
||||
applyFormatToPendingSessions(sessions, { qualDurationMin: 5, finalDurationMin: 5, qualStartMode: "flying" }, { qualDurationMin: 3, finalDurationMin: 5, qualStartMode: "flying" });
|
||||
assert.deepEqual(sessions.map((session) => session.durationMin), [3, 5, 5, 3]);
|
||||
});
|
||||
|
||||
test("the background refresh keeps the objects a form already holds", () => {
|
||||
const held = { id: "s1", durationMin: 5, old: true };
|
||||
const next = keepIdentityById([held], [{ id: "s1", durationMin: 3 }, { id: "s2" }]);
|
||||
assert.equal(next[0], held, "same object");
|
||||
assert.deepEqual(held, { id: "s1", durationMin: 3 }, "with the server's values");
|
||||
held.durationMin = 4;
|
||||
assert.equal(next[0].durationMin, 4, "so an edit through the held reference is not lost");
|
||||
});
|
||||
Reference in new issue
Block a user