MCPcopy Index your code
hub / github.com/nodejs/node / testTwoWorkers

Function testTwoWorkers

test/parallel/test-worker-debug.js:174–205  ·  view source on GitHub ↗
(session, post)

Source from the content-addressed store, hash-verified

172}
173
174async function testTwoWorkers(session, post) {
175 console.log('Test attach to a running worker and then start a new one');
176 await post('NodeWorker.disable');
177 let okToAttach = false;
178 const worker1attached = waitForWorkerAttach(session).then((notification) => {
179 assert.strictEqual(okToAttach, true);
180 return notification;
181 });
182
183 let worker1Exited;
184 const worker = await new Promise((resolve, reject) => {
185 worker1Exited = runWorker(2, resolve);
186 }).then((worker) => new Promise(
187 (resolve) => worker.once('message', () => resolve(worker))));
188 okToAttach = true;
189 await post('NodeWorker.enable', { waitForDebuggerOnStart: true });
190 const { waitingForDebugger: worker1Waiting } = await worker1attached;
191 assert.strictEqual(worker1Waiting, false);
192
193 const worker2Attached = waitForWorkerAttach(session);
194 let worker2Done = false;
195 const worker2Exited = runWorker(1)
196 .then(() => assert.strictEqual(worker2Done, true));
197 const worker2AttachInfo = await worker2Attached;
198 assert.strictEqual(worker2AttachInfo.waitingForDebugger, true);
199 worker2Done = true;
200
201 const workerSession = new WorkerSession(session, worker2AttachInfo.sessionId);
202 workerSession.post('Runtime.runIfWaitingForDebugger');
203 worker.postMessage('resume');
204 await Promise.all([worker1Exited, worker2Exited]);
205}
206
207async function testWaitForDisconnectInWorker(session, post) {
208 console.log('Test NodeRuntime.waitForDisconnect in worker');

Callers 1

Calls 10

postMethod · 0.95
waitForWorkerAttachFunction · 0.85
allMethod · 0.80
postFunction · 0.70
runWorkerFunction · 0.70
resolveFunction · 0.50
logMethod · 0.45
thenMethod · 0.45
onceMethod · 0.45
postMessageMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…