Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion packages/ui-react/tests/browser/offline/recording-cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,29 @@ export function recordingCell(ctx: TestContext) {
const events: RecordingEvent[] = [];
const cleanup: Array<() => void> = [];
store.onEvent((event) => events.push(event));
const committedCount = () => events.filter((event) => event.kind === "committed").length;
/**
* Resolves when the store has emitted at least `count` committed events.
* Native capture commits in real time, so a fixed polling window measures
* runner load rather than the precondition; the test timeout stays the
* only failure bound. The recorder above runs first, so `events` already
* holds the event a later listener is told about.
*/
const committed = (count: number) => new Promise<void>((resolve) => {
if (committedCount() >= count) return resolve();
const unsubscribe = store.onEvent(() => {
if (committedCount() < count) return;
unsubscribe();
resolve();
});
cleanup.push(unsubscribe);
});
ctx.onTestFinished(async () => {
const failures: unknown[] = [];
for (const finish of [...cleanup.reverse(), () => store.stop("interrupted"), () => store.dispose(), () => root.dispose()]) {
try { await finish(); } catch (error) { failures.push(error); }
}
if (failures.length) throw new AggregateError(failures, "Recording fixture cleanup failed");
});
return { root, partitions, store, events, cleanup, account: (key: string | null) => { held = key; root.stores.connection.getState().setVpnStatus(key ? "connected" : "unauthorized", key); } };
return { root, partitions, store, events, committed, committedCount, cleanup, account: (key: string | null) => { held = key; root.stores.connection.getState().setVpnStatus(key ? "connected" : "unauthorized", key); } };
}
11 changes: 5 additions & 6 deletions packages/ui-react/tests/browser/recording-limits.offline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ test("registered production warning and deadline finalize short native audio and
// real time. Invoking a registered callback proves its real stop path; the
// separate controlled-timer test proves when it is scheduled. Neither this
// short recording nor synthetic boundary blobs prove ten-minute endurance.
await expect.poll(() => c.events.filter((event) => event.kind === "committed").length).toBeGreaterThanOrEqual(2);
await c.committed(2);
expect(registered.has(540_000), "production warning registered at nine minutes").toBe(true);
expect(registered.has(599_750), "production deadline registered at ten minutes").toBe(true);
expect(updateHeld(c.root)).toBe(true);
Expand Down Expand Up @@ -181,12 +181,11 @@ test("source starvation reports only encoded audio", async (ctx) => {
c.cleanup.push(() => mic.restore());
const start = performance.now();
const capture = await c.store.start({ timesliceMs: 250 });
await expect.poll(() => c.events.filter(e => e.kind === "committed").length).toBeGreaterThanOrEqual(2);
await c.committed(2);
await mic.contexts[0]!.suspend();
await new Promise(resolve => setTimeout(resolve, 1200));
await mic.contexts[0]!.resume();
const before = c.events.filter(e => e.kind === "committed").length;
await expect.poll(() => c.events.filter(e => e.kind === "committed").length).toBeGreaterThanOrEqual(before + 2);
await c.committed(c.committedCount() + 2);
await capture.stop("user");
const elapsed = performance.now() - start;
const row = (await c.store.list("account:odysseus"))[0]!;
Expand Down Expand Up @@ -311,7 +310,7 @@ test("registered wall backstop finalizes native audio as interrupted", async (ct
// real time. Invoking a registered callback proves its real stop path; the
// separate controlled-timer test proves when it is scheduled. Neither this
// short recording nor synthetic boundary blobs prove ten-minute endurance.
await expect.poll(() => c.events.filter((event) => event.kind === "committed").length).toBeGreaterThanOrEqual(2);
await c.committed(2);
expect(registered.has(540_000), "production warning registered at nine minutes").toBe(true);
expect(registered.has(599_750), "production deadline registered at ten minutes").toBe(true);
expect(updateHeld(c.root)).toBe(true);
Expand Down Expand Up @@ -374,7 +373,7 @@ test("late limit at the committed flush target stops without a zero-delay re-arm
test("caller stop at expired wall deadline normalizes before first-stop-wins", async (ctx) => {
const c = recordingCell(ctx);
const capture = await c.store.start({ timesliceMs: 250 });
await expect.poll(() => c.events.filter(e => e.kind === "committed").length).toBeGreaterThanOrEqual(2);
await c.committed(2);
const descriptor = Object.getOwnPropertyDescriptor(performance, "now");
Object.defineProperty(performance, "now", { configurable: true, value: () => 1e12 });
c.cleanup.push(() => { if (descriptor) Object.defineProperty(performance, "now", descriptor); else delete (performance as { now?: unknown }).now; });
Expand Down
Loading