Skip to content

Commit b18e7ce

Browse files
committed
fix: flaky tests
1 parent 7d3b68c commit b18e7ce

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

src/client/index.test.ts

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,17 @@ describe("workflow client", () => {
133133
url: "http://requestcatcher.com",
134134
});
135135

136-
const firstCancel = await liveClient.cancel({
137-
ids: [workflowRunIdOne, workflowRunIdTwo, "non-existent"],
138-
});
139-
expect(firstCancel).toEqual({ cancelled: 2 });
136+
await new Promise((r) => setTimeout(r, 2000));
137+
138+
eventually(
139+
async () => {
140+
const firstCancel = await liveClient.cancel({
141+
ids: [workflowRunIdOne, workflowRunIdTwo, "non-existent"],
142+
});
143+
expect(firstCancel).toEqual({ cancelled: 2 });
144+
},
145+
{ timeout: 5000, interval: 1000 }
146+
);
140147

141148
// trying to cancel the workflows one by one gives error, as they were canceled above
142149
const secondCancel = await liveClient.cancel({ ids: workflowRunIdOne });
@@ -147,7 +154,7 @@ describe("workflow client", () => {
147154
expect(thirdCancel).toEqual({ cancelled: 0 });
148155
},
149156
{
150-
timeout: 10000,
157+
timeout: 20000,
151158
}
152159
);
153160

@@ -161,14 +168,20 @@ describe("workflow client", () => {
161168
url: "http://requestcatcher.com/second",
162169
});
163170

164-
const cancel = await liveClient.cancel({
165-
urlStartingWith: "http://requestcatcher.com",
166-
});
171+
await new Promise((r) => setTimeout(r, 2000));
167172

168-
expect(cancel).toEqual({ cancelled: 2 });
173+
eventually(
174+
async () => {
175+
const cancel = await liveClient.cancel({
176+
urlStartingWith: "http://requestcatcher.com",
177+
});
178+
expect(cancel).toEqual({ cancelled: 2 });
179+
},
180+
{ timeout: 5000, interval: 1000 }
181+
);
169182
},
170183
{
171-
timeout: 10000,
184+
timeout: 15000,
172185
}
173186
);
174187

src/serve/serve-many.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe("serveMany", () => {
1717
test("should throw if workflowId contains '/'", () => {
1818
const throws = () =>
1919
serveMany({
20-
"workflow/one": createWorkflow(async () => { }),
20+
"workflow/one": createWorkflow(async () => {}),
2121
});
2222
expect(throws).toThrow(
2323
"Invalid workflow name found: 'workflow/one'. Workflow name cannot contain '/'."
@@ -26,7 +26,7 @@ describe("serveMany", () => {
2626

2727
test("should throw if workflowId doesn't match", async () => {
2828
const { POST: handler } = serveMany({
29-
"workflow-one": createWorkflow(async () => { }),
29+
"workflow-one": createWorkflow(async () => {}),
3030
});
3131

3232
const request = new Request("http://localhost:3001/workflow-two", { method: "POST" });

0 commit comments

Comments
 (0)