Extend self-serve hardware batch wait

This commit is contained in:
Jeppe Bundgaard
2026-06-30 15:22:29 +02:00
parent 806db63e9e
commit 48f428a4f0
2 changed files with 42 additions and 1 deletions
@@ -164,7 +164,7 @@ const extractPayload = (response: any): any => {
const sleep = (ms: number): Promise<void> => new Promise((resolve) => setTimeout(resolve, ms));
const BATCH_POLL_INTERVAL_MS = 250;
const BATCH_POLL_ATTEMPTS = 40;
const BATCH_POLL_ATTEMPTS = 120;
const TERMINAL_BATCH_STATES = new Set(["COMPLETED", "FAILED", "PARTIAL", "UNKNOWN_OUTCOME"]);
const ACTIVE_BATCH_STORAGE_PREFIX = "truckwash.selfserve.hardwareBatch.";
const ACTIVE_BATCH_MAX_AGE_MS = 6 * 60 * 60 * 1000;
@@ -183,6 +183,47 @@ describe("self-serve machine connectivity store", () => {
expect(connectivity.statuses.value.MACHINE?.on).toBe(true);
});
it("waits long enough for slow edge batches to complete", async () => {
vi.useFakeTimers();
const laneId = 12;
let pollCount = 0;
mocks.request.mockImplementation(async (endpoint, method, payload) => {
if (endpoint === batchSetEndpoint && method === "POST") {
return {
data: {
data: buildBatch(
[buildBatchItem(laneId, relayKinds.MACHINE, { on: Boolean(payload?.commands?.[0]?.on) })],
"PENDING"
),
},
};
}
if (endpoint === "/modules/self-serve/lane/hardware/batch/batch-test-id" && method === "GET") {
pollCount += 1;
return {
data: {
data:
pollCount < 45
? buildBatch([buildBatchItem(laneId, relayKinds.MACHINE, { on: true })], "PENDING")
: buildBatch([buildBatchItem(laneId, relayKinds.MACHINE, { on: true })]),
},
};
}
throw new Error(`Unexpected endpoint: ${endpoint}`);
});
const connectivity = useMachineConnectivity(laneId);
const togglePromise = connectivity.toggleRelay(relayKinds.MACHINE, true);
await vi.advanceTimersByTimeAsync(12_000);
await togglePromise;
expect(pollCount).toBeGreaterThan(40);
expect(connectivity.statuses.value.MACHINE?.on).toBe(true);
expect(connectivity.error.value).toBeNull();
});
it("runs force and command actions through shared connectivity helpers", async () => {
const laneId = 15;