test(studio): the poll test waits through four quiet windows before it counts, and its failure says how many milliseconds after the baseline each commit landed

This commit is contained in:
yhh committed 2026-11-07 02:34:23 -08:00
1 parent 03cdec40a2
commit 8447cc10ac
1 file changed
+5 -4
@@ -16,13 +16,13 @@ const tick = () => act(async () => { await vi.advanceTimersByTimeAsync(3000); })
/** Waits until the panel has stopped committing on its own: what opening a file
* leaves behind (an entering tab's 220ms timer, a lazily loaded chunk, a
* persisted list) lands at a time that depends on the machine, and none of it
* is what a poll does. Two quiet 50ms windows in a row end the wait; a panel
* is what a poll does. Four quiet 100ms windows in a row end the wait; a panel
* that never goes quiet leaves the real assertion to fail. */
async function quiet(commits: ReturnType<typeof vi.fn>) {
let still = 0;
for (let i = 0; i < 60 && still < 2; i++) {
for (let i = 0; i < 60 && still < 4; i++) {
commits.mockClear();
await act(async () => { await new Promise((resolve) => setTimeout(resolve, 50)); });
await act(async () => { await new Promise((resolve) => setTimeout(resolve, 100)); });
still = commits.mock.calls.length === 0 ? still + 1 : 0;
}
}
@@ -114,10 +114,11 @@ it("leaves the rendered Workbench untouched when Markdown polls are unchanged",
await act(async () => {});
await quiet(commits);
commits.mockClear();
const base = performance.now();
const seen: string[] = [];
for (const n of [1, 2]) {
await tick();
seen.push(`after poll ${n}: ${commits.mock.calls.length} commits [${commits.mock.calls.map((c) => c[1]).join(",")}], file reads ${read.mock.calls.length}, listings ${listed.mock.calls.length}`);
seen.push(`after poll ${n} (${(performance.now() - base).toFixed(0)}ms): ${commits.mock.calls.length} commits [${commits.mock.calls.map((c) => `${c[1]}@${(c[5] - base).toFixed(0)}ms`).join(",")}], file reads ${read.mock.calls.length}, listings ${listed.mock.calls.length}`);
}
expect(read).toHaveBeenCalledTimes(3);
expect(commits.mock.calls.length, seen.join("; ")).toBe(0);