|
| 1 | +import { randomUUID } from "crypto"; |
1 | 2 | import { rm } from "fs/promises"; |
2 | 3 | import { resolve } from "path"; |
3 | 4 | import { fetch } from "undici"; |
4 | | -import { afterAll, beforeAll, describe, it, vi } from "vitest"; |
| 5 | +import { afterAll, beforeAll, describe, it, test, vi } from "vitest"; |
5 | 6 | import { runWranglerDev } from "../../shared/src/run-wrangler-long-lived"; |
6 | 7 |
|
7 | 8 | describe("Workflows", () => { |
@@ -98,4 +99,86 @@ describe("Workflows", () => { |
98 | 99 | name: "Error", |
99 | 100 | }); |
100 | 101 | }); |
| 102 | + |
| 103 | + describe("retrying a step", () => { |
| 104 | + test("should retry a step if a generic Error (with a generic error message) is thrown", async ({ |
| 105 | + expect, |
| 106 | + }) => { |
| 107 | + const name = randomUUID(); |
| 108 | + await fetchJson( |
| 109 | + `http://${ip}:${port}/createDemo3?workflowName=${name}&doRetry=true&errorMessage=generic_error_message` |
| 110 | + ); |
| 111 | + |
| 112 | + await vi.waitFor( |
| 113 | + async () => { |
| 114 | + const result = await fetchJson( |
| 115 | + `http://${ip}:${port}/get3?workflowName=${name}` |
| 116 | + ); |
| 117 | + |
| 118 | + expect(result["output"]).toEqual("The step was retried 3 times"); |
| 119 | + }, |
| 120 | + { timeout: 1500 } |
| 121 | + ); |
| 122 | + }); |
| 123 | + |
| 124 | + test("should retry a step if a generic Error (with an empty error message) is thrown", async ({ |
| 125 | + expect, |
| 126 | + }) => { |
| 127 | + const name = randomUUID(); |
| 128 | + await fetchJson( |
| 129 | + `http://${ip}:${port}/createDemo3?workflowName=${name}&doRetry=true&errorMessage=` |
| 130 | + ); |
| 131 | + |
| 132 | + await vi.waitFor( |
| 133 | + async () => { |
| 134 | + const result = await fetchJson( |
| 135 | + `http://${ip}:${port}/get3?workflowName=${name}` |
| 136 | + ); |
| 137 | + |
| 138 | + expect(result["output"]).toEqual("The step was retried 3 times"); |
| 139 | + }, |
| 140 | + { timeout: 1500 } |
| 141 | + ); |
| 142 | + }); |
| 143 | + |
| 144 | + test("should not retry a step if a NonRetryableError (with a generic error message) is thrown", async ({ |
| 145 | + expect, |
| 146 | + }) => { |
| 147 | + const name = randomUUID(); |
| 148 | + await fetchJson( |
| 149 | + `http://${ip}:${port}/createDemo3?workflowName=${name}&doRetry=false&errorMessage=generic_error_message"` |
| 150 | + ); |
| 151 | + |
| 152 | + await vi.waitFor( |
| 153 | + async () => { |
| 154 | + const result = await fetchJson( |
| 155 | + `http://${ip}:${port}/get3?workflowName=${name}` |
| 156 | + ); |
| 157 | + |
| 158 | + expect(result["output"]).toEqual("The step was retried 0 times"); |
| 159 | + }, |
| 160 | + { timeout: 1500 } |
| 161 | + ); |
| 162 | + }); |
| 163 | + |
| 164 | + test("should not retry a step if a NonRetryableError (with an empty error message) is thrown", async ({ |
| 165 | + expect, |
| 166 | + }) => { |
| 167 | + const name = randomUUID(); |
| 168 | + await fetchJson( |
| 169 | + `http://${ip}:${port}/createDemo3?workflowName=${name}&doRetry=false&errorMessage=` |
| 170 | + ); |
| 171 | + |
| 172 | + await vi.waitFor( |
| 173 | + async () => { |
| 174 | + const result = await fetchJson( |
| 175 | + `http://${ip}:${port}/get3?workflowName=${name}` |
| 176 | + ); |
| 177 | + |
| 178 | + expect(result["output"]).toEqual("The step was retried 0 times"); |
| 179 | + }, |
| 180 | + { timeout: 1500 } |
| 181 | + ); |
| 182 | + }); |
| 183 | + }); |
101 | 184 | }); |
0 commit comments