aboutsummaryrefslogtreecommitdiff
path: root/test/parallel/test-worker-debug.js
diff options
context:
space:
mode:
authorAleksei Koziatinskii <ak239spb@gmail.com>2019-05-14 18:13:48 -0700
committerAleksei Koziatinskii <ak239spb@gmail.com>2019-06-02 22:37:11 +0300
commit7e18c650de419ae98511be3c7bc54b34efc6d3d4 (patch)
tree2793e5e9ad53c6e55febdb858383307418132fe3 /test/parallel/test-worker-debug.js
parente8f31191902a8304f77f7ed4377f10de91aca103 (diff)
downloadandroid-node-v8-7e18c650de419ae98511be3c7bc54b34efc6d3d4.tar.gz
android-node-v8-7e18c650de419ae98511be3c7bc54b34efc6d3d4.tar.bz2
android-node-v8-7e18c650de419ae98511be3c7bc54b34efc6d3d4.zip
inspector: supported NodeRuntime domain in worker
NodeRuntime domain was introduced to give inspector client way to fetch captured information before Node process is gone. We need similar capability for work. With current protocol inspector client can force worker to wait on start by passing waitForDebuggerOnStart flag to NodeWorker.enable method. So client has some time to setup environment, e.g. start profiler. At the same time there is no way to prevent worker from being terminated. So we can start capturing profile but we can not reliably get captured data back. This PR implemented NodeRuntime.notifyWhenWaitingForDisconnect method for worker. When NodeRuntime.waitingForDisconnect notification is enabled, worker will wait for explicit NodeWorker.detach call. With this PR worker tooling story is nicely aligned with main thread tooling story. The only difference is that main thread by default is waiting for disconnect but worker thread is not waiting. Issue: https://github.com/nodejs/node/issues/27677 PR-URL: https://github.com/nodejs/node/pull/27706 Reviewed-By: Eugene Ostroukhov <eostroukhov@google.com>
Diffstat (limited to 'test/parallel/test-worker-debug.js')
-rw-r--r--test/parallel/test-worker-debug.js47
1 files changed, 47 insertions, 0 deletions
diff --git a/test/parallel/test-worker-debug.js b/test/parallel/test-worker-debug.js
index 8726d2a031..4906f623e8 100644
--- a/test/parallel/test-worker-debug.js
+++ b/test/parallel/test-worker-debug.js
@@ -206,6 +206,52 @@ async function testTwoWorkers(session, post) {
await Promise.all([worker1Exited, worker2Exited]);
}
+async function testWaitForDisconnectInWorker(session, post) {
+ console.log('Test NodeRuntime.waitForDisconnect in worker');
+
+ const sessionWithoutWaiting = new Session();
+ sessionWithoutWaiting.connect();
+ const sessionWithoutWaitingPost = doPost.bind(null, sessionWithoutWaiting);
+
+ await sessionWithoutWaitingPost('NodeWorker.enable', {
+ waitForDebuggerOnStart: true
+ });
+ await post('NodeWorker.enable', { waitForDebuggerOnStart: true });
+
+ const attached = [
+ waitForWorkerAttach(session),
+ waitForWorkerAttach(sessionWithoutWaiting)
+ ];
+
+ let worker = null;
+ const exitPromise = runWorker(2, (w) => worker = w);
+
+ const [{ sessionId: sessionId1 }, { sessionId: sessionId2 }] =
+ await Promise.all(attached);
+
+ const workerSession1 = new WorkerSession(session, sessionId1);
+ const workerSession2 = new WorkerSession(sessionWithoutWaiting, sessionId2);
+
+ await workerSession2.post('Runtime.enable');
+ await workerSession1.post('Runtime.enable');
+ await workerSession1.post('NodeRuntime.notifyWhenWaitingForDisconnect', {
+ enabled: true
+ });
+ await workerSession1.post('Runtime.runIfWaitingForDebugger');
+
+ worker.postMessage('resume');
+
+ await waitForEvent(workerSession1, 'NodeRuntime.waitingForDisconnect');
+ post('NodeWorker.detach', { sessionId: sessionId1 });
+ await waitForEvent(workerSession2, 'Runtime.executionContextDestroyed');
+
+ await exitPromise;
+
+ await post('NodeWorker.disable');
+ await sessionWithoutWaitingPost('NodeWorker.disable');
+ sessionWithoutWaiting.disconnect();
+}
+
async function test() {
const session = new Session();
session.connect();
@@ -219,6 +265,7 @@ async function test() {
await testNoWaitOnStart(session, post);
await testTwoWorkers(session, post);
+ await testWaitForDisconnectInWorker(session, post);
session.disconnect();
console.log('Test done');