Skip to content

Commit 90f6e4f

Browse files
brainkimclaude
andcommitted
fix: retry Miniflare spawn for flaky workerd on CI
workerd occasionally fails to spawn on CI runners (child_process connect error). Added createMiniflare() helper with 3 retries. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 888efd0 commit 90f6e4f

1 file changed

Lines changed: 19 additions & 6 deletions

File tree

test/cloudflare-build.test.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,23 @@ import {copyFixtureToTemp, fileExists} from "./utils.js";
1414
const TIMEOUT = 10000;
1515
const MINIFLARE_TIMEOUT = 30000;
1616

17+
/**
18+
* Create a Miniflare instance with retry for flaky workerd spawns on CI.
19+
*/
20+
async function createMiniflare(options, retries = 3) {
21+
for (let i = 0; i < retries; i++) {
22+
try {
23+
const mf = new Miniflare(options);
24+
await mf.ready;
25+
return mf;
26+
} catch (err) {
27+
if (i === retries - 1) throw err;
28+
// Brief pause before retry
29+
await new Promise((r) => setTimeout(r, 500));
30+
}
31+
}
32+
}
33+
1734
test(
1835
"cloudflare build - basic ServiceWorker",
1936
async () => {
@@ -151,15 +168,13 @@ test(
151168

152169
// Load and run the worker in Miniflare
153170
// This will fail if setTimeout is called in global scope during lifecycle
154-
mf = new Miniflare({
171+
mf = await createMiniflare({
155172
modules: true,
156173
script,
157174
compatibilityDate: "2024-09-23",
158175
compatibilityFlags: ["nodejs_compat"],
159176
});
160177

161-
await mf.ready;
162-
163178
// Send a request to the worker
164179
const response = await mf.dispatchFetch("http://localhost/");
165180
expect(response.status).toBe(200);
@@ -246,7 +261,7 @@ self.addEventListener("fetch", (event) => {
246261
const workerPath = join(outDir, "server", "worker.js");
247262
const script = await FS.readFile(workerPath, "utf8");
248263

249-
mf = new Miniflare({
264+
mf = await createMiniflare({
250265
modules: true,
251266
script,
252267
compatibilityDate: "2024-09-23",
@@ -258,8 +273,6 @@ self.addEventListener("fetch", (event) => {
258273
},
259274
});
260275

261-
await mf.ready;
262-
263276
// Fetch the URL map from the worker
264277
const response = await mf.dispatchFetch("http://localhost/");
265278
expect(response.status).toBe(200);

0 commit comments

Comments
 (0)