diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2024-04-16 00:06:39 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-16 01:06:39 +0200 |
commit | 0b8d7d1d4b068df46a14895b2f55c00781bd1eef (patch) | |
tree | 0a478c09731a8f5c15b3eaee5124dadd39631edc /tests | |
parent | 46c709e52f712ef7e1e41285ec06e9bbbe10c0a5 (diff) |
fix(ext/node): panic on 'worker_threads.receiveMessageOnPort' (#23386)
Closes https://github.com/denoland/deno/issues/23362
Previously we were panicking if there was a pending read on a
port and `receiveMessageOnPort` was called. This is now fixed
by cancelling the pending read, trying to read a message and
resuming reading in a loop.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit_node/worker_threads_test.ts | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/unit_node/worker_threads_test.ts b/tests/unit_node/worker_threads_test.ts index 2351e1052..bd600469b 100644 --- a/tests/unit_node/worker_threads_test.ts +++ b/tests/unit_node/worker_threads_test.ts @@ -414,3 +414,25 @@ Deno.test({ mainPort.close(); }, }); + +// Regression test for https://github.com/denoland/deno/issues/23362 +Deno.test("[node/worker_threads] receiveMessageOnPort works if there's pending read", function () { + const { port1, port2 } = new workerThreads.MessageChannel(); + + const message1 = { hello: "world" }; + const message2 = { foo: "bar" }; + + assertEquals(workerThreads.receiveMessageOnPort(port2), undefined); + port2.start(); + + port1.postMessage(message1); + port1.postMessage(message2); + assertEquals(workerThreads.receiveMessageOnPort(port2), { + message: message1, + }); + assertEquals(workerThreads.receiveMessageOnPort(port2), { + message: message2, + }); + port1.close(); + port2.close(); +}); |