1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-15 03:48:02 -05:00
denoland-deno/tests/node_compat/test/parallel/test-worker-message-port-infinite-message-loop.js
Yoshiya Hinosawa 58c96d3ecb
chore: update node_compat setup script (#27051)
This PR updates the node_compat setup script. Now the copied version in
each test file is corrected. Also `TODO.md` links to the correct files
in Node.js repo.
2024-11-28 15:47:23 +01:00

36 lines
1.1 KiB
JavaScript

// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
const common = require('../common');
const assert = require('assert');
const { MessageChannel } = require('worker_threads');
// Make sure that an infinite asynchronous .on('message')/postMessage loop
// does not lead to a stack overflow and does not starve the event loop.
// We schedule timeouts both from before the .on('message') handler and
// inside of it, which both should run.
const { port1, port2 } = new MessageChannel();
let count = 0;
port1.on('message', () => {
if (count === 0) {
setTimeout(common.mustCall(() => {
port1.close();
}), 0);
}
port2.postMessage(0);
assert(count++ < 10000, `hit ${count} loop iterations`);
});
port2.postMessage(0);
// This is part of the test -- the event loop should be available and not stall
// out due to the recursive .postMessage() calls.
setTimeout(common.mustCall(), 0);