|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const common = require('../common'); |
| 4 | +common.skipIfInspectorDisabled(); |
| 5 | + |
| 6 | +const { parentPort, workerData, Worker } = require('node:worker_threads'); |
| 7 | +if (!workerData) { |
| 8 | + common.skipIfWorker(); |
| 9 | +} |
| 10 | + |
| 11 | +const inspector = require('node:inspector'); |
| 12 | +const assert = require('node:assert'); |
| 13 | + |
| 14 | +let TIMEOUT = common.platformTimeout(5000); |
| 15 | +if (common.isWindows) { |
| 16 | + // Refs: https://github.com/nodejs/build/issues/3014 |
| 17 | + TIMEOUT = common.platformTimeout(15000); |
| 18 | +} |
| 19 | + |
| 20 | +// Refs: https://github.com/nodejs/node/issues/52467 |
| 21 | + |
| 22 | +(async () => { |
| 23 | + if (!workerData) { |
| 24 | + // worker.terminate() should terminate the worker and the pending |
| 25 | + // inspector.waitForDebugger(). |
| 26 | + { |
| 27 | + const worker = new Worker(__filename, { workerData: {} }); |
| 28 | + await new Promise((r) => worker.on('message', r)); |
| 29 | + await new Promise((r) => setTimeout(r, TIMEOUT)); |
| 30 | + worker.on('exit', common.mustCall()); |
| 31 | + await worker.terminate(); |
| 32 | + } |
| 33 | + // process.exit() should kill the process. |
| 34 | + { |
| 35 | + const worker = new Worker(__filename, { workerData: {} }); |
| 36 | + await new Promise((r) => worker.on('message', r)); |
| 37 | + await new Promise((r) => setTimeout(r, TIMEOUT)); |
| 38 | + process.on('exit', (status) => assert.strictEqual(status, 0)); |
| 39 | + setImmediate(() => process.exit()); |
| 40 | + } |
| 41 | + } else { |
| 42 | + inspector.open(0, undefined, false); |
| 43 | + parentPort.postMessage('open'); |
| 44 | + inspector.waitForDebugger(); |
| 45 | + } |
| 46 | +})().then(common.mustCall()); |
0 commit comments