Skip to content

Commit b1b58dd

Browse files
pelikhanCopilot
andauthored
test: make checkpoint-history abort deadline deterministic (#74959)
Replace the 1 ms real-time timeout with Vitest fake timers and the default one-second budget. Assert lookup starts, remains un-aborted at 999 ms, and aborts exactly once at 1000 ms, restoring real timers in finally. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 1291c9c commit b1b58dd

1 file changed

Lines changed: 30 additions & 17 deletions

File tree

‎actions/setup/js/finish_work_queue_claim.test.cjs‎

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -139,31 +139,44 @@ describe("independent trusted Claim finalization", () => {
139139
});
140140

141141
it("aborts checkpoint-history lookup at its one-second deadline", async () => {
142-
const controller = vi.fn();
143-
const client = {
144-
rest: {
145-
git: {
146-
getCommit: vi.fn(({ request }) => {
147-
request.signal.addEventListener("abort", controller, { once: true });
148-
return new Promise(() => {});
149-
}),
142+
vi.useFakeTimers();
143+
try {
144+
const controller = vi.fn();
145+
const client = {
146+
rest: {
147+
git: {
148+
getCommit: vi.fn(({ request }) => {
149+
request.signal.addEventListener("abort", controller, { once: true });
150+
return new Promise(() => {});
151+
}),
152+
},
150153
},
151-
},
152-
};
153-
const latest = { sha: "c".repeat(40), eventLocations: { checkpoint_prior_git_sha: "b".repeat(40) } };
154+
};
155+
const latest = { sha: "c".repeat(40), eventLocations: { checkpoint_prior_git_sha: "b".repeat(40) } };
154156

155-
await expect(
156-
workQueueStore.resolveWorkQueueEventLocations({
157+
const lookup = workQueueStore.resolveWorkQueueEventLocations({
157158
githubClient: client,
158159
owner: "owner",
159160
repo: "repo",
160161
latest,
161162
work_id: "work-1",
162163
claim_id: "claim-1",
163-
timeoutMs: 1,
164-
})
165-
).resolves.toBeUndefined();
166-
expect(controller).toHaveBeenCalledTimes(1);
164+
});
165+
expect(client.rest.git.getCommit).toHaveBeenCalledTimes(1);
166+
const { signal } = client.rest.git.getCommit.mock.calls[0][0].request;
167+
expect(signal.aborted).toBe(false);
168+
169+
await vi.advanceTimersByTimeAsync(999);
170+
expect(controller).not.toHaveBeenCalled();
171+
expect(signal.aborted).toBe(false);
172+
173+
await vi.advanceTimersByTimeAsync(1);
174+
await expect(lookup).resolves.toBeUndefined();
175+
expect(controller).toHaveBeenCalledTimes(1);
176+
expect(signal.aborted).toBe(true);
177+
} finally {
178+
vi.useRealTimers();
179+
}
167180
});
168181

169182
it("reuses only repository-scoped footer links from the reconciliation output after trusted authorization", async () => {

0 commit comments

Comments
 (0)