diff options
author | Nathan Whitaker <17734409+nathanwhit@users.noreply.github.com> | 2024-08-27 20:05:32 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-28 03:05:32 +0000 |
commit | 511d13abaf5cc98cc01250f7adc5edf15dc29276 (patch) | |
tree | 6cd171394f451fb3d7e619bc00d2be9d37c0bad5 /tests/unit_node/worker_threads_test.ts | |
parent | 3dba98532a3054e4e74bb1b3304e4cb809d284dc (diff) |
fix(ext/node): emit `online` event after worker thread is initialized (#25243)
Fixes #23281. Part of #20613.
We were emitting the `online` event in the constructor, so the caller
could never receive it (since there was no time for them to add a
listener). Instead, emit the event where it's intended – after the
worker is initialized.
---
After this parcel no longer freezes, but still will fail due to other
bugs (which will be fixed in other PRs)
Diffstat (limited to 'tests/unit_node/worker_threads_test.ts')
-rw-r--r-- | tests/unit_node/worker_threads_test.ts | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/unit_node/worker_threads_test.ts b/tests/unit_node/worker_threads_test.ts index d9fe9f77d..ac797601f 100644 --- a/tests/unit_node/worker_threads_test.ts +++ b/tests/unit_node/worker_threads_test.ts @@ -590,3 +590,34 @@ Deno.test({ channel.port2.close(); }, }); + +Deno.test({ + name: "[node/worker_threads] Emits online event", + async fn() { + const worker = new workerThreads.Worker( + ` + import { parentPort } from "node:worker_threads"; + const p = Promise.withResolvers(); + let ok = false; + parentPort.on("message", () => { + ok = true; + p.resolve(); + }); + await Promise.race([p.promise, new Promise(resolve => setTimeout(resolve, 20000))]); + if (ok) { + parentPort.postMessage("ok"); + } else { + parentPort.postMessage("timed out"); + } + `, + { + eval: true, + }, + ); + worker.on("online", () => { + worker.postMessage("ok"); + }); + assertEquals((await once(worker, "message"))[0], "ok"); + worker.terminate(); + }, +}); |