test: tests that assumed an idle machine wait for what they assert, or carry a budget for their work
Under a busy machine (the gate's lanes side by side, 12 busy cores) these went red at random: a press landed while the button was still busy, an answer was settled before it was asked for, a page grew past one wait's budget, a lazy chunk was transformed inside a 1 s wait, focus was taken a frame after the press. They now wait for the condition they depend on, preload the chunks they open, and the tests that do heavy work (whole-repo scans, the type-aware linter, module resets) carry an explicit budget naming that work. The whole suite four times under 12 busy-loop processes: red 4/4 before, 0/4 after.
This commit is contained in:
@@ -75,10 +75,12 @@ describe("Feed — the count while a new search's count loads", () => {
|
||||
it("dims the previous count and marks it busy until the new one lands", async () => {
|
||||
vi.spyOn(api, "feed").mockResolvedValue({ items: [], next_cursor: null } as never);
|
||||
let settle: (v: unknown) => void = () => {};
|
||||
vi.spyOn(api, "feedSummary").mockImplementation(((f: FeedFilters) =>
|
||||
f.q === "kitchen"
|
||||
? Promise.resolve({ count: 1937, facets: {} })
|
||||
: new Promise((r) => (settle = r))) as never);
|
||||
const summary = vi
|
||||
.spyOn(api, "feedSummary")
|
||||
.mockImplementation(((f: FeedFilters) =>
|
||||
f.q === "kitchen"
|
||||
? Promise.resolve({ count: 1937, facets: {} })
|
||||
: new Promise((r) => (settle = r))) as never);
|
||||
const qc = new QueryClient({ defaultOptions: { queries: { retry: false } } });
|
||||
qc.setQueryData(qk.me(), { id: 1, can_write: true, prefs: {} });
|
||||
const pill = () => screen.getByTestId("item-count");
|
||||
@@ -91,6 +93,9 @@ describe("Feed — the count while a new search's count loads", () => {
|
||||
await waitFor(() => expect(pill().getAttribute("aria-busy")).toBe("true"));
|
||||
expect(pill().getAttribute("title")).toBe("1,937"); // still the old figure, now marked as such
|
||||
|
||||
// The pill turns busy in the render that changes the search, and the count is asked for in an
|
||||
// effect after it: answer only once it has been asked, or the answer goes to no one.
|
||||
await waitFor(() => expect(summary).toHaveBeenCalledWith(expect.objectContaining({ q: "a" })));
|
||||
settle({ count: 178991, facets: {} });
|
||||
await waitFor(() => expect(pill().getAttribute("title")).toBe("178,991"));
|
||||
expect(pill().getAttribute("aria-busy")).toBeNull();
|
||||
|
||||
Reference in New Issue
Block a user