-
Notifications
You must be signed in to change notification settings - Fork 30.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
inspector: rewrite inspector test helper
Helper was rewritten to rely on promises instead of manually written queue and callbacks. This simplifies the code and makes it easier to maintain and extend. PR-URL: #14797 Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent
3f44989
commit cf195cc
Showing
22 changed files
with
868 additions
and
1,119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
common.skipIfInspectorDisabled(); | ||
const assert = require('assert'); | ||
const { NodeInstance } = require('./inspector-helper.js'); | ||
const path = require('path'); | ||
|
||
const script = path.join(path.dirname(module.filename), 'global-function.js'); | ||
|
||
async function setupDebugger(session) { | ||
console.log('[test]', 'Setting up a debugger'); | ||
const commands = [ | ||
{ 'method': 'Runtime.enable' }, | ||
{ 'method': 'Debugger.enable' }, | ||
{ 'method': 'Debugger.setAsyncCallStackDepth', | ||
'params': { 'maxDepth': 0 } }, | ||
{ 'method': 'Runtime.runIfWaitingForDebugger' }, | ||
]; | ||
session.send(commands); | ||
await session.waitForNotification('Runtime.consoleAPICalled'); | ||
} | ||
|
||
async function breakOnLine(session) { | ||
console.log('[test]', 'Breaking in the code'); | ||
const commands = [ | ||
{ 'method': 'Debugger.setBreakpointByUrl', | ||
'params': { 'lineNumber': 9, | ||
'url': script, | ||
'columnNumber': 0, | ||
'condition': '' | ||
} | ||
}, | ||
{ 'method': 'Runtime.evaluate', | ||
'params': { 'expression': 'sum()', | ||
'objectGroup': 'console', | ||
'includeCommandLineAPI': true, | ||
'silent': false, | ||
'contextId': 1, | ||
'returnByValue': false, | ||
'generatePreview': true, | ||
'userGesture': true, | ||
'awaitPromise': false | ||
} | ||
} | ||
]; | ||
session.send(commands); | ||
await session.waitForBreakOnLine(9, script); | ||
} | ||
|
||
async function stepOverConsoleStatement(session) { | ||
console.log('[test]', 'Step over console statement and test output'); | ||
session.send({ 'method': 'Debugger.stepOver' }); | ||
await session.waitForConsoleOutput('log', [0, 3]); | ||
await session.waitForNotification('Debugger.paused'); | ||
} | ||
|
||
async function runTests() { | ||
const child = new NodeInstance(['--inspect=0'], undefined, script); | ||
const session = await child.connectInspectorSession(); | ||
await setupDebugger(session); | ||
await breakOnLine(session); | ||
await stepOverConsoleStatement(session); | ||
await session.runToCompletion(); | ||
assert.strictEqual(0, (await child.expectShutdown()).exitCode); | ||
} | ||
|
||
common.crashOnUnhandledRejection(); | ||
runTests(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
|
||
common.skipIfInspectorDisabled(); | ||
|
||
const assert = require('assert'); | ||
const { mainScriptPath, | ||
NodeInstance } = require('./inspector-helper.js'); | ||
|
||
async function testBreakpointOnStart(session) { | ||
const commands = [ | ||
{ 'method': 'Runtime.enable' }, | ||
{ 'method': 'Debugger.enable' }, | ||
{ 'method': 'Debugger.setPauseOnExceptions', | ||
'params': { 'state': 'none' } }, | ||
{ 'method': 'Debugger.setAsyncCallStackDepth', | ||
'params': { 'maxDepth': 0 } }, | ||
{ 'method': 'Profiler.enable' }, | ||
{ 'method': 'Profiler.setSamplingInterval', | ||
'params': { 'interval': 100 } }, | ||
{ 'method': 'Debugger.setBlackboxPatterns', | ||
'params': { 'patterns': [] } }, | ||
{ 'method': 'Runtime.runIfWaitingForDebugger' } | ||
]; | ||
|
||
session.send(commands); | ||
await session.waitForBreakOnLine(0, mainScriptPath); | ||
} | ||
|
||
async function runTests() { | ||
const child = new NodeInstance(['--inspect', '--debug-brk']); | ||
const session = await child.connectInspectorSession(); | ||
|
||
await testBreakpointOnStart(session); | ||
await session.runToCompletion(); | ||
|
||
assert.strictEqual(55, (await child.expectShutdown()).exitCode); | ||
} | ||
|
||
common.crashOnUnhandledRejection(); | ||
runTests(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
common.skipIfInspectorDisabled(); | ||
const { strictEqual } = require('assert'); | ||
const { NodeInstance } = require('./inspector-helper.js'); | ||
|
||
async function testNoServerNoCrash() { | ||
console.log('Test there\'s no crash stopping server that was not started'); | ||
const instance = new NodeInstance([], | ||
`process._debugEnd(); | ||
process.exit(42);`); | ||
strictEqual(42, (await instance.expectShutdown()).exitCode); | ||
} | ||
|
||
async function testNoSessionNoCrash() { | ||
console.log('Test there\'s no crash stopping server without connecting'); | ||
const instance = new NodeInstance('--inspect=0', | ||
'process._debugEnd();process.exit(42);'); | ||
strictEqual(42, (await instance.expectShutdown()).exitCode); | ||
} | ||
|
||
async function testSessionNoCrash() { | ||
console.log('Test there\'s no crash stopping server after connecting'); | ||
const script = `process._debugEnd(); | ||
process._debugProcess(process.pid); | ||
setTimeout(() => { | ||
console.log("Done"); | ||
process.exit(42); | ||
});`; | ||
|
||
const instance = new NodeInstance('--inspect-brk=0', script); | ||
const session = await instance.connectInspectorSession(); | ||
await session.send({ 'method': 'Runtime.runIfWaitingForDebugger' }); | ||
await session.waitForServerDisconnect(); | ||
strictEqual(42, (await instance.expectShutdown()).exitCode); | ||
} | ||
|
||
async function runTest() { | ||
await testNoServerNoCrash(); | ||
await testNoSessionNoCrash(); | ||
await testSessionNoCrash(); | ||
} | ||
|
||
common.crashOnUnhandledRejection(); | ||
|
||
runTest(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
|
||
common.skipIfInspectorDisabled(); | ||
|
||
const assert = require('assert'); | ||
const { NodeInstance } = require('./inspector-helper.js'); | ||
const path = require('path'); | ||
|
||
const script = path.join(common.fixturesDir, 'throws_error.js'); | ||
|
||
async function testBreakpointOnStart(session) { | ||
console.log('[test]', | ||
'Verifying debugger stops on start (--inspect-brk option)'); | ||
const commands = [ | ||
{ 'method': 'Runtime.enable' }, | ||
{ 'method': 'Debugger.enable' }, | ||
{ 'method': 'Debugger.setPauseOnExceptions', | ||
'params': { 'state': 'none' } }, | ||
{ 'method': 'Debugger.setAsyncCallStackDepth', | ||
'params': { 'maxDepth': 0 } }, | ||
{ 'method': 'Profiler.enable' }, | ||
{ 'method': 'Profiler.setSamplingInterval', | ||
'params': { 'interval': 100 } }, | ||
{ 'method': 'Debugger.setBlackboxPatterns', | ||
'params': { 'patterns': [] } }, | ||
{ 'method': 'Runtime.runIfWaitingForDebugger' } | ||
]; | ||
|
||
await session.send(commands); | ||
await session.waitForBreakOnLine(0, script); | ||
} | ||
|
||
|
||
async function runTest() { | ||
const child = new NodeInstance(undefined, undefined, script); | ||
const session = await child.connectInspectorSession(); | ||
await testBreakpointOnStart(session); | ||
await session.runToCompletion(); | ||
assert.strictEqual(1, (await child.expectShutdown()).exitCode); | ||
} | ||
|
||
common.crashOnUnhandledRejection(); | ||
|
||
runTest(); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
|
||
common.skipIfInspectorDisabled(); | ||
|
||
const assert = require('assert'); | ||
const { NodeInstance } = require('./inspector-helper.js'); | ||
const os = require('os'); | ||
|
||
const ip = pickIPv4Address(); | ||
|
||
if (!ip) | ||
common.skip('No IP address found'); | ||
|
||
function checkIpAddress(ip, response) { | ||
const res = response[0]; | ||
const wsUrl = res['webSocketDebuggerUrl']; | ||
assert.ok(wsUrl); | ||
const match = wsUrl.match(/^ws:\/\/(.*):\d+\/(.*)/); | ||
assert.strictEqual(ip, match[1]); | ||
assert.strictEqual(res['id'], match[2]); | ||
assert.strictEqual(ip, res['devtoolsFrontendUrl'].match(/.*ws=(.*):\d+/)[1]); | ||
} | ||
|
||
function pickIPv4Address() { | ||
for (const i of [].concat(...Object.values(os.networkInterfaces()))) { | ||
if (i.family === 'IPv4' && i.address !== '127.0.0.1') | ||
return i.address; | ||
} | ||
} | ||
|
||
async function test() { | ||
const instance = new NodeInstance('--inspect-brk=0.0.0.0:0'); | ||
try { | ||
checkIpAddress(ip, await instance.httpGet(ip, '/json/list')); | ||
} catch (error) { | ||
if (error.code === 'EHOSTUNREACH') { | ||
common.printSkipMessage('Unable to connect to self'); | ||
} else { | ||
throw error; | ||
} | ||
} | ||
instance.kill(); | ||
} | ||
|
||
common.crashOnUnhandledRejection(); | ||
|
||
test(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
common.skipIfInspectorDisabled(); | ||
const helper = require('./inspector-helper.js'); | ||
const { NodeInstance } = require('./inspector-helper.js'); | ||
|
||
function shouldShutDown(session) { | ||
session | ||
.sendInspectorCommands([ | ||
{ 'method': 'Debugger.enable' }, | ||
{ 'method': 'Debugger.pause' }, | ||
]) | ||
.disconnect(true); | ||
} | ||
|
||
function runTests(harness) { | ||
async function runTests() { | ||
const script = 'setInterval(() => {debugger;}, 60000);'; | ||
const node = new NodeInstance('--inspect=0', script); | ||
// 1 second wait to make sure the inferior began running the script | ||
setTimeout(() => harness.runFrontendSession([shouldShutDown]).kill(), 1000); | ||
await new Promise((resolve) => setTimeout(() => resolve(), 1000)); | ||
const session = await node.connectInspectorSession(); | ||
await session.send([ | ||
{ 'method': 'Debugger.enable' }, | ||
{ 'method': 'Debugger.pause' } | ||
]); | ||
session.disconnect(); | ||
node.kill(); | ||
} | ||
|
||
const script = 'setInterval(() => {debugger;}, 60000);'; | ||
helper.startNodeForInspectorTest(runTests, '--inspect', script); | ||
common.crashOnUnhandledRejection(); | ||
runTests(); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
common.skipIfInspectorDisabled(); | ||
const assert = require('assert'); | ||
const { NodeInstance } = require('./inspector-helper.js'); | ||
|
||
async function runTests() { | ||
const child = new NodeInstance(['--inspect=0'], | ||
`let c = 0; | ||
const interval = setInterval(() => { | ||
console.log(new Object()); | ||
if (c++ === 10) | ||
clearInterval(interval); | ||
}, 10);`); | ||
const session = await child.connectInspectorSession(); | ||
|
||
session.send([ | ||
{ 'method': 'Profiler.setSamplingInterval', 'params': { 'interval': 100 } }, | ||
{ 'method': 'Profiler.enable' }, | ||
{ 'method': 'Runtime.runIfWaitingForDebugger' }, | ||
{ 'method': 'Profiler.start' }]); | ||
while (await child.nextStderrString() !== | ||
'Waiting for the debugger to disconnect...'); | ||
await session.send({ 'method': 'Profiler.stop' }); | ||
session.disconnect(); | ||
assert.strictEqual(0, (await child.expectShutdown()).exitCode); | ||
} | ||
|
||
common.crashOnUnhandledRejection(); | ||
runTests(); |
File renamed without changes.