0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-30 15:30:56 +01:00
nodejs/test/report/test-report-worker.js
cjihrig 9d1a3b6f60
doc,lib,src,test: make --experimental-report a nop
This commit makes the --experimental-report CLI flag a no-op.

PR-URL: https://github.com/nodejs/node/pull/32242
Fixes: https://github.com/nodejs/node/issues/26293
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2020-03-15 13:29:34 -04:00

50 lines
1.3 KiB
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const { Worker } = require('worker_threads');
const { once } = require('events');
const helper = require('../common/report');
async function basic() {
// Test that the report includes basic information about Worker threads.
const w = new Worker(`
const { parentPort } = require('worker_threads');
parentPort.once('message', () => {
/* Wait for message to stop the Worker */
});
`, { eval: true });
await once(w, 'online');
const report = process.report.getReport();
helper.validateContent(report);
assert.strictEqual(report.workers.length, 1);
helper.validateContent(report.workers[0]);
assert.strictEqual(report.workers[0].header.threadId, w.threadId);
w.postMessage({});
await once(w, 'exit');
}
async function interruptingJS() {
// Test that the report also works when Worker threads are busy in JS land.
const w = new Worker('while (true);', { eval: true });
await once(w, 'online');
const report = process.report.getReport();
helper.validateContent(report);
assert.strictEqual(report.workers.length, 1);
helper.validateContent(report.workers[0]);
await w.terminate();
}
(async function() {
await basic();
await interruptingJS();
})().then(common.mustCall());