Skip to content

Commit 1489e9a

Browse files
committed
test: avoid worker in shared value conveyor test
V8 no longer supports JSON.parse on worker isolates while the shared string table is enabled. Since --harmony-struct enables that table and Node workers parse process.config during bootstrap, use direct MessageChannel instead of a worker. Signed-Off-By: Michaël Zasso <targos@protonmail.com>
1 parent 40940ec commit 1489e9a

1 file changed

Lines changed: 12 additions & 16 deletions

File tree

test/parallel/test-experimental-shared-value-conveyor.js

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,22 @@
22
const common = require('../common');
33
const assert = require('assert');
44
const { spawnSync } = require('child_process');
5-
const { Worker, parentPort } = require('worker_threads');
5+
const { MessageChannel } = require('worker_threads');
66

77
if (process.env.TEST_CHILD_PROCESS === '1') {
8-
// Do not use isMainThread so that this test itself can be run inside a Worker.
9-
if (!process.env.HAS_STARTED_WORKER) {
10-
process.env.HAS_STARTED_WORKER = 1;
11-
const m = new globalThis.SharedArray(16);
8+
// --harmony-struct implies --shared-string-table. V8 currently does not
9+
// support JSON.parse in worker isolates with that flag, and Node workers
10+
// parse process.config during bootstrap.
11+
const m = new globalThis.SharedArray(16);
12+
const { port1, port2 } = new MessageChannel();
1213

13-
const worker = new Worker(__filename);
14-
worker.once('message', common.mustCall((message) => {
15-
assert.strictEqual(message, m);
16-
}));
14+
port1.once('message', common.mustCall((message) => {
15+
assert.strictEqual(message, m);
16+
port1.close();
17+
port2.close();
18+
}));
1719

18-
worker.postMessage(m);
19-
} else {
20-
parentPort.once('message', common.mustCall((message) => {
21-
// Simple echo.
22-
parentPort.postMessage(message);
23-
}));
24-
}
20+
port2.postMessage(m);
2521
} else {
2622
if (process.config.variables.v8_enable_pointer_compression === 1) {
2723
common.skip('--harmony-struct cannot be used with pointer compression');

0 commit comments

Comments
 (0)