(session, post)
| 205 | } |
| 206 | |
| 207 | async 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(); |
no test coverage detected
searching dependent graphs…