-
Notifications
You must be signed in to change notification settings - Fork 30.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
46 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const { Worker } = require('worker_threads'); | ||
|
||
new Worker(__dirname + '/worker.js', { type: 'module' }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
console.log("worker thread"); | ||
process.on('exit', () => { | ||
console.log('Worker1: Exiting...'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,50 @@ | ||
// Flags: --inspect=0 --experimental-worker-inspection | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const fixtures = require('../common/fixtures'); | ||
const { Worker } = require('worker_threads'); | ||
|
||
common.skipIfInspectorDisabled(); | ||
|
||
const assert = require('assert'); | ||
const { Session } = require('inspector'); | ||
const { NodeInstance } = require('../common/inspector-helper.js'); | ||
|
||
const session = new Session(); | ||
(async () => { | ||
const child = new NodeInstance(['--inspect-brk', '--experimental-worker-inspection'], | ||
'', | ||
fixtures.path('inspect-worker/index.js') | ||
); | ||
|
||
session.connect(); | ||
const session = await child.connectInspectorSession(); | ||
await session.send({ method: 'NodeRuntime.enable' }); | ||
await session.waitForNotification('NodeRuntime.waitingForDebugger'); | ||
await session.send({ method: 'Runtime.enable' }); | ||
await session.send({ method: 'Debugger.enable' }); | ||
await session.send({ method: 'Runtime.runIfWaitingForDebugger' }); | ||
await session.send({ method: 'NodeRuntime.disable' }); | ||
await session.waitForNotification((notification) => { | ||
// // The main assertion here is that we do hit the loader script first. | ||
return notification.method === 'Debugger.scriptParsed' && | ||
notification.params.url === 'node:internal/bootstrap/realm'; | ||
}); | ||
|
||
new Worker(fixtures.path('worker-script.mjs'), { type: 'module' }); | ||
session.on('Target.targetCreated', common.mustCall(({ params }) => { | ||
const targetInfo = params.targetInfo; | ||
assert.strictEqual(targetInfo.type, 'worker'); | ||
assert.ok(targetInfo.url.includes('worker-script.mjs')); | ||
assert.strictEqual(targetInfo.targetId, '1'); | ||
})); | ||
await session.waitForNotification('Debugger.paused'); | ||
await session.send({ method: 'Debugger.resume' }); | ||
|
||
session.on('Target.attachedToTarget', common.mustCall(({ params }) => { | ||
assert.strictEqual(params.sessionId, '1'); | ||
})); | ||
const sessionId = '1'; | ||
await session.waitForNotification('Target.targetCreated'); | ||
await session.waitForNotification((notification) => { | ||
return notification.method === 'Target.attachedToTarget' && | ||
notification.params.sessionId === sessionId; | ||
}); | ||
|
||
await session.send({ method: 'Runtime.enable', sessionId }); | ||
await session.send({ method: 'Debugger.enable', sessionId }); | ||
await session.send({ method: 'Runtime.runIfWaitingForDebugger', sessionId }); | ||
await session.send({ method: 'NodeRuntime.enable', sessionId }); | ||
await session.waitForNotification((notification) => { | ||
return notification.method === 'Debugger.scriptParsed' && | ||
notification.params.url === 'node:internal/bootstrap/realm'; | ||
}); | ||
await session.waitForNotification('Debugger.paused'); | ||
await session.send({ method: 'Debugger.resume', sessionId }); | ||
await session.waitForDisconnect(); | ||
})().then(common.mustCall()); |