• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3
4common.skipIfInspectorDisabled();
5
6const { NodeInstance } = require('../common/inspector-helper.js');
7
8// Sets up JS bindings session and runs till the "paused" event
9const script = `
10const { Session } = require('inspector');
11const session = new Session();
12let done = false;
13const interval = setInterval(() => {
14  if (done)
15    clearInterval(interval);
16}, 150);
17session.on('Debugger.paused', () => {
18  done = true;
19});
20session.connect();
21session.post('Debugger.enable');
22console.log('Ready');
23console.log('Ready');
24`;
25
26async function setupSession(node) {
27  const session = await node.connectInspectorSession();
28  await session.send([
29    { 'method': 'Runtime.enable' },
30    { 'method': 'Debugger.enable' },
31    { 'method': 'Debugger.setPauseOnExceptions',
32      'params': { 'state': 'none' } },
33    { 'method': 'Debugger.setAsyncCallStackDepth',
34      'params': { 'maxDepth': 0 } },
35    { 'method': 'Profiler.enable' },
36    { 'method': 'Profiler.setSamplingInterval',
37      'params': { 'interval': 100 } },
38    { 'method': 'Debugger.setBlackboxPatterns',
39      'params': { 'patterns': [] } },
40    { 'method': 'Runtime.runIfWaitingForDebugger' },
41  ]);
42  return session;
43}
44
45async function testSuspend(sessionA, sessionB) {
46  console.log('[test]', 'Breaking in code and verifying events are fired');
47  await sessionA.waitForNotification('Debugger.paused', 'Initial pause');
48  sessionA.send({ 'method': 'Debugger.resume' });
49
50  await sessionA.waitForNotification('Runtime.consoleAPICalled',
51                                     'Console output');
52  // NOTE(mmarchini): Remove second console.log when
53  // https://bugs.chromium.org/p/v8/issues/detail?id=10287 is fixed.
54  await sessionA.waitForNotification('Runtime.consoleAPICalled',
55                                     'Console output');
56  sessionA.send({ 'method': 'Debugger.pause' });
57  return Promise.all([
58    sessionA.waitForNotification('Debugger.paused', 'SessionA paused'),
59    sessionB.waitForNotification('Debugger.paused', 'SessionB paused'),
60  ]);
61}
62
63async function runTest() {
64  const child = new NodeInstance(undefined, script);
65
66  const [session1, session2] =
67      await Promise.all([setupSession(child), setupSession(child)]);
68  await testSuspend(session2, session1);
69  console.log('[test]', 'Should shut down after both sessions disconnect');
70
71  await session1.runToCompletion();
72  await session2.send({ 'method': 'Debugger.disable' });
73  await session2.disconnect();
74  return child.expectShutdown();
75}
76
77runTest().then(common.mustCall());
78