Skip to content

Commit 6a4b2bb

Browse files
committed
test: test on retry timeout failure
1 parent 2d9b3d0 commit 6a4b2bb

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

src/__snapshots__/return-dispatch.spec.ts.snap

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,15 @@ exports[`return-dispatch > handleAction > getRunIdAndUrl > should return the ID
6363
"Attempting to identify run ID from steps...",
6464
]
6565
`;
66+
67+
exports[`return-dispatch > handleAction > getRunIdAndUrl > should timeout when unable failing to get the run IDs 1`] = `
68+
[
69+
"Attempting to identify Run ID for workflow.yml (123)",
70+
]
71+
`;
72+
73+
exports[`return-dispatch > handleAction > getRunIdAndUrl > should timeout when unable failing to get the run IDs 2`] = `
74+
[
75+
"Attempting to identify run ID from steps...",
76+
]
77+
`;

src/return-dispatch.spec.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,43 @@ describe("return-dispatch", () => {
739739
assertNoneCalled();
740740
});
741741

742-
it("should timeout when unable failing to get the run IDs");
742+
it("should timeout when unable failing to get the run IDs", async () => {
743+
apiRetryOrTimeoutMock.mockResolvedValue({
744+
success: false,
745+
reason: "timeout",
746+
});
747+
748+
// Behaviour
749+
const getRunIdAndUrlPromise = getRunIdAndUrl({
750+
...defaultOpts,
751+
});
752+
await vi.advanceTimersByTimeAsync(1000);
753+
754+
const run = await getRunIdAndUrlPromise;
755+
756+
if (run.success) {
757+
expect.fail("expected call to fail");
758+
}
759+
760+
// Behaviour
761+
expect(run.reason).toStrictEqual("timeout");
762+
763+
expect(apiRetryOrTimeoutMock).toHaveBeenCalledOnce();
764+
expect(apiFetchWorkflowRunJobStepsMock).not.toHaveBeenCalled();
765+
expect(apiFetchWorkflowRunIdsMock).not.toHaveBeenCalled();
766+
expect(utilSleepMock).not.toHaveBeenCalled();
767+
768+
// Logging
769+
assertOnlyCalled(coreDebugLogMock, coreInfoLogMock);
770+
expect(coreDebugLogMock).toHaveBeenCalledTimes(2);
771+
expect(coreDebugLogMock.mock.calls[0]).toMatchSnapshot();
772+
expect(coreDebugLogMock.mock.calls[1]?.[0]).toMatch(
773+
/Timed out while attempting to fetch Workflow Run IDs, waited [0-9]+ms/,
774+
);
775+
776+
expect(coreInfoLogMock).toHaveBeenCalledOnce();
777+
expect(coreInfoLogMock.mock.calls[0]).toMatchSnapshot();
778+
});
743779

744780
it("should timeout when unable to find over time");
745781
});

0 commit comments

Comments
 (0)