11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ci 41cb0ef41Sopenharmony_cicommon.skipIfInspectorDisabled(); 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ciconst { NodeInstance } = require('../common/inspector-helper.js'); 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ci// Sets up JS bindings session and runs till the "paused" event 91cb0ef41Sopenharmony_ciconst script = ` 101cb0ef41Sopenharmony_ciconst { Session } = require('inspector'); 111cb0ef41Sopenharmony_ciconst session = new Session(); 121cb0ef41Sopenharmony_cilet done = false; 131cb0ef41Sopenharmony_ciconst interval = setInterval(() => { 141cb0ef41Sopenharmony_ci if (done) 151cb0ef41Sopenharmony_ci clearInterval(interval); 161cb0ef41Sopenharmony_ci}, 150); 171cb0ef41Sopenharmony_cisession.on('Debugger.paused', () => { 181cb0ef41Sopenharmony_ci done = true; 191cb0ef41Sopenharmony_ci}); 201cb0ef41Sopenharmony_cisession.connect(); 211cb0ef41Sopenharmony_cisession.post('Debugger.enable'); 221cb0ef41Sopenharmony_ciconsole.log('Ready'); 231cb0ef41Sopenharmony_ciconsole.log('Ready'); 241cb0ef41Sopenharmony_ci`; 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_ciasync function setupSession(node) { 271cb0ef41Sopenharmony_ci const session = await node.connectInspectorSession(); 281cb0ef41Sopenharmony_ci await session.send([ 291cb0ef41Sopenharmony_ci { 'method': 'Runtime.enable' }, 301cb0ef41Sopenharmony_ci { 'method': 'Debugger.enable' }, 311cb0ef41Sopenharmony_ci { 'method': 'Debugger.setPauseOnExceptions', 321cb0ef41Sopenharmony_ci 'params': { 'state': 'none' } }, 331cb0ef41Sopenharmony_ci { 'method': 'Debugger.setAsyncCallStackDepth', 341cb0ef41Sopenharmony_ci 'params': { 'maxDepth': 0 } }, 351cb0ef41Sopenharmony_ci { 'method': 'Profiler.enable' }, 361cb0ef41Sopenharmony_ci { 'method': 'Profiler.setSamplingInterval', 371cb0ef41Sopenharmony_ci 'params': { 'interval': 100 } }, 381cb0ef41Sopenharmony_ci { 'method': 'Debugger.setBlackboxPatterns', 391cb0ef41Sopenharmony_ci 'params': { 'patterns': [] } }, 401cb0ef41Sopenharmony_ci { 'method': 'Runtime.runIfWaitingForDebugger' }, 411cb0ef41Sopenharmony_ci ]); 421cb0ef41Sopenharmony_ci return session; 431cb0ef41Sopenharmony_ci} 441cb0ef41Sopenharmony_ci 451cb0ef41Sopenharmony_ciasync function testSuspend(sessionA, sessionB) { 461cb0ef41Sopenharmony_ci console.log('[test]', 'Breaking in code and verifying events are fired'); 471cb0ef41Sopenharmony_ci await sessionA.waitForNotification('Debugger.paused', 'Initial pause'); 481cb0ef41Sopenharmony_ci sessionA.send({ 'method': 'Debugger.resume' }); 491cb0ef41Sopenharmony_ci 501cb0ef41Sopenharmony_ci await sessionA.waitForNotification('Runtime.consoleAPICalled', 511cb0ef41Sopenharmony_ci 'Console output'); 521cb0ef41Sopenharmony_ci // NOTE(mmarchini): Remove second console.log when 531cb0ef41Sopenharmony_ci // https://bugs.chromium.org/p/v8/issues/detail?id=10287 is fixed. 541cb0ef41Sopenharmony_ci await sessionA.waitForNotification('Runtime.consoleAPICalled', 551cb0ef41Sopenharmony_ci 'Console output'); 561cb0ef41Sopenharmony_ci sessionA.send({ 'method': 'Debugger.pause' }); 571cb0ef41Sopenharmony_ci return Promise.all([ 581cb0ef41Sopenharmony_ci sessionA.waitForNotification('Debugger.paused', 'SessionA paused'), 591cb0ef41Sopenharmony_ci sessionB.waitForNotification('Debugger.paused', 'SessionB paused'), 601cb0ef41Sopenharmony_ci ]); 611cb0ef41Sopenharmony_ci} 621cb0ef41Sopenharmony_ci 631cb0ef41Sopenharmony_ciasync function runTest() { 641cb0ef41Sopenharmony_ci const child = new NodeInstance(undefined, script); 651cb0ef41Sopenharmony_ci 661cb0ef41Sopenharmony_ci const [session1, session2] = 671cb0ef41Sopenharmony_ci await Promise.all([setupSession(child), setupSession(child)]); 681cb0ef41Sopenharmony_ci await testSuspend(session2, session1); 691cb0ef41Sopenharmony_ci console.log('[test]', 'Should shut down after both sessions disconnect'); 701cb0ef41Sopenharmony_ci 711cb0ef41Sopenharmony_ci await session1.runToCompletion(); 721cb0ef41Sopenharmony_ci await session2.send({ 'method': 'Debugger.disable' }); 731cb0ef41Sopenharmony_ci await session2.disconnect(); 741cb0ef41Sopenharmony_ci return child.expectShutdown(); 751cb0ef41Sopenharmony_ci} 761cb0ef41Sopenharmony_ci 771cb0ef41Sopenharmony_cirunTest().then(common.mustCall()); 78