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

Function testWaitForDisconnectInWorker

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

Source from the content-addressed store, hash-verified

205}
206
207async function testWaitForDisconnectInWorker(session, post) {
208 console.log('Test NodeRuntime.waitForDisconnect in worker');
209
210 const sessionWithoutWaiting = new Session();
211 sessionWithoutWaiting.connect();
212 const sessionWithoutWaitingPost = doPost.bind(null, sessionWithoutWaiting);
213
214 await sessionWithoutWaitingPost('NodeWorker.enable', {
215 waitForDebuggerOnStart: true
216 });
217 await post('NodeWorker.enable', { waitForDebuggerOnStart: true });
218
219 const attached = [
220 waitForWorkerAttach(session),
221 waitForWorkerAttach(sessionWithoutWaiting),
222 ];
223
224 let worker = null;
225 const exitPromise = runWorker(2, (w) => worker = w);
226
227 const [{ sessionId: sessionId1 }, { sessionId: sessionId2 }] =
228 await Promise.all(attached);
229
230 const workerSession1 = new WorkerSession(session, sessionId1);
231 const workerSession2 = new WorkerSession(sessionWithoutWaiting, sessionId2);
232
233 await workerSession2.post('Runtime.enable');
234 await workerSession1.post('Runtime.enable');
235 await workerSession1.post('NodeRuntime.notifyWhenWaitingForDisconnect', {
236 enabled: true
237 });
238 await workerSession1.post('Runtime.runIfWaitingForDebugger');
239
240 // Create the promises before sending the exit message to the Worker in order
241 // to avoid race conditions.
242 const disconnectPromise =
243 waitForEvent(workerSession1, 'NodeRuntime.waitingForDisconnect');
244 const executionContextDestroyedPromise =
245 waitForEvent(workerSession2, 'Runtime.executionContextDestroyed');
246 worker.postMessage('resume');
247
248 await disconnectPromise;
249 post('NodeWorker.detach', { sessionId: sessionId1 });
250 await executionContextDestroyedPromise;
251
252 await exitPromise;
253
254 await post('NodeWorker.disable');
255 await sessionWithoutWaitingPost('NodeWorker.disable');
256 sessionWithoutWaiting.disconnect();
257}
258
259(async function test() {
260 const session = new Session();

Callers 1

Calls 11

connectMethod · 0.95
postMethod · 0.95
disconnectMethod · 0.95
waitForWorkerAttachFunction · 0.85
allMethod · 0.80
postFunction · 0.70
runWorkerFunction · 0.70
waitForEventFunction · 0.70
logMethod · 0.45
bindMethod · 0.45
postMessageMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…