Skip to content

Commit 80b8bd9

Browse files
make workers created with startWorker await the ready promise on dispose (#9541)
* make workers created with `startWorker` await the `ready` promise on `dispose` * Revert "make workers created with `startWorker` await the `ready` promise on `dispose`" This reverts commit 8e7fa7a. * reject ready promise instead of resolving it to null * fix typo in test assert match * properly fix typo * Update packages/wrangler/src/api/startDevWorker/DevEnv.ts Co-authored-by: Pete Bacon Darwin <[email protected]> * update tests * fix formatting --------- Co-authored-by: Pete Bacon Darwin <[email protected]>
1 parent 92305af commit 80b8bd9

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

.changeset/five-shoes-call.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
make workers created with `startWorker` await the `ready` promise on `dispose`

fixtures/start-worker-node-test/src/config-errors.test.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,15 @@ describe("startWorker - configuration errors", () => {
1212
}),
1313
(err) => {
1414
assert(err instanceof Error);
15-
assert.match(
15+
assert.strictEqual(
1616
err.message,
17-
/he entry-point file at "not a real entrypoint" was not found./
17+
"An error occurred when starting the server"
18+
);
19+
const cause = err.cause;
20+
assert(cause instanceof Error);
21+
assert.match(
22+
cause.message,
23+
/The entry-point file at "not a real entrypoint" was not found./
1824
);
1925
return true;
2026
}
@@ -26,8 +32,14 @@ describe("startWorker - configuration errors", () => {
2632
unstable_startWorker({ config: "non-existing-config" }),
2733
(err) => {
2834
assert(err instanceof Error);
29-
assert.match(
35+
assert.strictEqual(
3036
err.message,
37+
"An error occurred when starting the server"
38+
);
39+
const cause = err.cause;
40+
assert(cause instanceof Error);
41+
assert.match(
42+
cause.message,
3143
/Missing entry-point to Worker script or to assets directory/
3244
);
3345
return true;
@@ -58,8 +70,6 @@ describe("startWorker - configuration errors", () => {
5870
}
5971
);
6072

61-
// TODO: worker.dispose() should itself await worker.ready
62-
await worker.ready;
6373
await worker.dispose();
6474
});
6575

@@ -86,8 +96,6 @@ describe("startWorker - configuration errors", () => {
8696
}
8797
);
8898

89-
// TODO: worker.dispose() should itself await worker.ready
90-
await worker.ready;
9199
await worker.dispose();
92100
});
93101
});

packages/wrangler/src/api/startDevWorker/DevEnv.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ export class DevEnv extends EventEmitter {
2323
try {
2424
await this.config.set(options, true);
2525
} catch (e) {
26+
const error = new Error("An error occurred when starting the server", {
27+
cause: e,
28+
});
29+
this.proxy.ready.reject(error);
2630
await worker.dispose();
2731
throw e;
2832
}
@@ -186,7 +190,7 @@ function createWorkerObject(devEnv: DevEnv): Worker {
186190
return w.scheduled(...args);
187191
},
188192
async dispose() {
189-
await devEnv.teardown();
193+
await devEnv.proxy.ready.promise.finally(() => devEnv.teardown());
190194
},
191195
raw: devEnv,
192196
};

0 commit comments

Comments
 (0)