From 041885ebd0acb4240684fbe4f3832e7d1df077b8 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Tue, 28 Mar 2023 00:03:40 +0200 Subject: [PATCH] test: use --port=0 in debugger tests that do not have to work on 9229 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To avoid failures when there is another running process occupying the port 9229 which may happen if there is a stale process, use the --port argument of node-inspect to use a random port in tests that don't have to work on port 9229. The following tests are not touched: - test-debugger-custom-port: tests a specific port - test-debugger-debug-brk: tests a specific port - test-debugger-invalid-args: tests other inspect combinations - test-debugger-pid: node-inspect does not support -p and --port together - test-debugger-launch: tests that default port is 9229 PR-URL: https://github.com/nodejs/node/pull/47274 Refs: https://github.com/nodejs/node/issues/47146 Reviewed-By: Colin Ihrig Reviewed-By: Michaƫl Zasso Reviewed-By: Luigi Pinca Reviewed-By: Moshe Atlow Reviewed-By: James M Snell --- test/sequential/test-debugger-auto-resume.mjs | 2 +- test/sequential/test-debugger-backtrace.js | 2 +- test/sequential/test-debugger-break.js | 2 +- test/sequential/test-debugger-breakpoint-exists.js | 2 +- test/sequential/test-debugger-clear-breakpoints.js | 2 +- test/sequential/test-debugger-exceptions.js | 2 +- test/sequential/test-debugger-exec-scope.mjs | 2 +- test/sequential/test-debugger-exec.js | 2 +- test/sequential/test-debugger-heap-profiler.js | 2 +- test/sequential/test-debugger-help.mjs | 2 +- test/sequential/test-debugger-launch.mjs | 1 + test/sequential/test-debugger-list.js | 2 +- test/sequential/test-debugger-low-level.js | 2 +- test/sequential/test-debugger-object-type-remote-object.js | 2 +- test/sequential/test-debugger-preserve-breaks.js | 2 +- test/sequential/test-debugger-profile-command.js | 2 +- test/sequential/test-debugger-profile.js | 2 +- test/sequential/test-debugger-repeat-last.js | 2 +- test/sequential/test-debugger-restart-message.js | 2 +- test/sequential/test-debugger-run-after-quit-restart.js | 2 +- test/sequential/test-debugger-sb-before-load.js | 2 +- test/sequential/test-debugger-scripts.js | 2 +- test/sequential/test-debugger-set-context-line-number.mjs | 2 +- test/sequential/test-debugger-use-strict.js | 2 +- test/sequential/test-debugger-watch-validation.js | 2 +- test/sequential/test-debugger-watchers.mjs | 2 +- 26 files changed, 26 insertions(+), 25 deletions(-) diff --git a/test/sequential/test-debugger-auto-resume.mjs b/test/sequential/test-debugger-auto-resume.mjs index e2f18d6e2bc79b..077258907d136b 100644 --- a/test/sequential/test-debugger-auto-resume.mjs +++ b/test/sequential/test-debugger-auto-resume.mjs @@ -21,7 +21,7 @@ addLibraryPath(process.env); }; env.NODE_INSPECT_RESUME_ON_START = '1'; - const cli = startCLI([script], [], { + const cli = startCLI(['--port=0', script], [], { env, }); diff --git a/test/sequential/test-debugger-backtrace.js b/test/sequential/test-debugger-backtrace.js index c189cb3f5b22e6..f66cc11d70a918 100644 --- a/test/sequential/test-debugger-backtrace.js +++ b/test/sequential/test-debugger-backtrace.js @@ -13,7 +13,7 @@ const path = require('path'); { const scriptFullPath = fixtures.path('debugger', 'backtrace.js'); const script = path.relative(process.cwd(), scriptFullPath); - const cli = startCLI([script]); + const cli = startCLI(['--port=0', script]); async function runTest() { try { diff --git a/test/sequential/test-debugger-break.js b/test/sequential/test-debugger-break.js index 1d92331d4e1013..65b4355cfe7bc2 100644 --- a/test/sequential/test-debugger-break.js +++ b/test/sequential/test-debugger-break.js @@ -11,7 +11,7 @@ const path = require('path'); const scriptFullPath = fixtures.path('debugger', 'break.js'); const script = path.relative(process.cwd(), scriptFullPath); -const cli = startCLI([script]); +const cli = startCLI(['--port=0', script]); (async () => { await cli.waitForInitialBreak(); diff --git a/test/sequential/test-debugger-breakpoint-exists.js b/test/sequential/test-debugger-breakpoint-exists.js index e2efa8182e4ade..872fad2d82400c 100644 --- a/test/sequential/test-debugger-breakpoint-exists.js +++ b/test/sequential/test-debugger-breakpoint-exists.js @@ -9,7 +9,7 @@ const startCLI = require('../common/debugger'); // Test for "Breakpoint at specified location already exists" error. const script = fixtures.path('debugger', 'three-lines.js'); -const cli = startCLI([script]); +const cli = startCLI(['--port=0', script]); (async () => { try { diff --git a/test/sequential/test-debugger-clear-breakpoints.js b/test/sequential/test-debugger-clear-breakpoints.js index 91349e105a1160..74623ec4371331 100644 --- a/test/sequential/test-debugger-clear-breakpoints.js +++ b/test/sequential/test-debugger-clear-breakpoints.js @@ -13,7 +13,7 @@ const path = require('path'); { const scriptFullPath = fixtures.path('debugger', 'break.js'); const script = path.relative(process.cwd(), scriptFullPath); - const cli = startCLI([script]); + const cli = startCLI(['--port=0', script]); function onFatal(error) { cli.quit(); diff --git a/test/sequential/test-debugger-exceptions.js b/test/sequential/test-debugger-exceptions.js index 3f75161a6b6e3d..7f3e192251e924 100644 --- a/test/sequential/test-debugger-exceptions.js +++ b/test/sequential/test-debugger-exceptions.js @@ -13,7 +13,7 @@ const path = require('path'); { const scriptFullPath = fixtures.path('debugger', 'exceptions.js'); const script = path.relative(process.cwd(), scriptFullPath); - const cli = startCLI([script]); + const cli = startCLI(['--port=0', script]); (async () => { try { diff --git a/test/sequential/test-debugger-exec-scope.mjs b/test/sequential/test-debugger-exec-scope.mjs index 08b37e279556f2..3e4241cd018fc4 100644 --- a/test/sequential/test-debugger-exec-scope.mjs +++ b/test/sequential/test-debugger-exec-scope.mjs @@ -7,7 +7,7 @@ import startCLI from '../common/debugger.js'; import assert from 'assert'; -const cli = startCLI([path('debugger/backtrace.js')]); +const cli = startCLI(['--port=0', path('debugger/backtrace.js')]); try { await cli.waitForInitialBreak(); diff --git a/test/sequential/test-debugger-exec.js b/test/sequential/test-debugger-exec.js index 3d4bb9ff63ab91..51bc7497345ba2 100644 --- a/test/sequential/test-debugger-exec.js +++ b/test/sequential/test-debugger-exec.js @@ -8,7 +8,7 @@ const startCLI = require('../common/debugger'); const assert = require('assert'); -const cli = startCLI([fixtures.path('debugger/alive.js')]); +const cli = startCLI(['--port=0', fixtures.path('debugger/alive.js')]); async function waitInitialBreak() { try { diff --git a/test/sequential/test-debugger-heap-profiler.js b/test/sequential/test-debugger-heap-profiler.js index dfec0fe10d5a36..1237c33f7f4567 100644 --- a/test/sequential/test-debugger-heap-profiler.js +++ b/test/sequential/test-debugger-heap-profiler.js @@ -17,7 +17,7 @@ const filename = path.join(tmpdir.path, 'node.heapsnapshot'); // Heap profiler take snapshot. { const opts = { cwd: tmpdir.path }; - const cli = startCLI([fixtures.path('debugger/empty.js')], [], opts); + const cli = startCLI(['--port=0', fixtures.path('debugger/empty.js')], [], opts); async function waitInitialBreak() { try { diff --git a/test/sequential/test-debugger-help.mjs b/test/sequential/test-debugger-help.mjs index 64f569831fba5e..a4e659113bf79c 100644 --- a/test/sequential/test-debugger-help.mjs +++ b/test/sequential/test-debugger-help.mjs @@ -7,7 +7,7 @@ import startCLI from '../common/debugger.js'; import assert from 'assert'; -const cli = startCLI([path('debugger', 'empty.js')]); +const cli = startCLI(['--port=0', path('debugger', 'empty.js')]); try { await cli.waitForInitialBreak(); diff --git a/test/sequential/test-debugger-launch.mjs b/test/sequential/test-debugger-launch.mjs index 9d4016c1f5d5e4..d501d0f9eb21eb 100644 --- a/test/sequential/test-debugger-launch.mjs +++ b/test/sequential/test-debugger-launch.mjs @@ -1,6 +1,7 @@ import { skipIfInspectorDisabled } from '../common/index.mjs'; skipIfInspectorDisabled(); +// This must be in sequential because we check that the default port is 9229. import { path } from '../common/fixtures.mjs'; import startCLI from '../common/debugger.js'; diff --git a/test/sequential/test-debugger-list.js b/test/sequential/test-debugger-list.js index 594874e140b306..6f2e36e763a651 100644 --- a/test/sequential/test-debugger-list.js +++ b/test/sequential/test-debugger-list.js @@ -8,7 +8,7 @@ const startCLI = require('../common/debugger'); const assert = require('assert'); -const cli = startCLI([fixtures.path('debugger/three-lines.js')]); +const cli = startCLI(['--port=0', fixtures.path('debugger/three-lines.js')]); (async () => { await cli.waitForInitialBreak(); diff --git a/test/sequential/test-debugger-low-level.js b/test/sequential/test-debugger-low-level.js index 93c8e1b625591d..31f67849f54748 100644 --- a/test/sequential/test-debugger-low-level.js +++ b/test/sequential/test-debugger-low-level.js @@ -9,7 +9,7 @@ const assert = require('assert'); // Debugger agent direct access. { - const cli = startCLI([fixtures.path('debugger/three-lines.js')]); + const cli = startCLI(['--port=0', fixtures.path('debugger/three-lines.js')]); const scriptPattern = /^\* (\d+): \S+debugger(?:\/|\\)three-lines\.js/m; async function testDebuggerLowLevel() { diff --git a/test/sequential/test-debugger-object-type-remote-object.js b/test/sequential/test-debugger-object-type-remote-object.js index 7404eae3963447..a055e8ce0fb9e4 100644 --- a/test/sequential/test-debugger-object-type-remote-object.js +++ b/test/sequential/test-debugger-object-type-remote-object.js @@ -8,7 +8,7 @@ const startCLI = require('../common/debugger'); const assert = require('assert'); -const cli = startCLI([fixtures.path('debugger/empty.js')]); +const cli = startCLI(['--port=0', fixtures.path('debugger/empty.js')]); (async () => { await cli.waitForInitialBreak(); diff --git a/test/sequential/test-debugger-preserve-breaks.js b/test/sequential/test-debugger-preserve-breaks.js index bb0eba961432ec..00168c570d6b7c 100644 --- a/test/sequential/test-debugger-preserve-breaks.js +++ b/test/sequential/test-debugger-preserve-breaks.js @@ -14,7 +14,7 @@ const script = path.relative(process.cwd(), scriptFullPath); // Run after quit. const runTest = async () => { - const cli = startCLI([script]); + const cli = startCLI(['--port=0', script]); try { await cli.waitForInitialBreak(); await cli.waitForPrompt(); diff --git a/test/sequential/test-debugger-profile-command.js b/test/sequential/test-debugger-profile-command.js index 06818c2132d9c5..da81dfc6e10569 100644 --- a/test/sequential/test-debugger-profile-command.js +++ b/test/sequential/test-debugger-profile-command.js @@ -10,7 +10,7 @@ const assert = require('assert'); const fs = require('fs'); const path = require('path'); -const cli = startCLI([fixtures.path('debugger/empty.js')]); +const cli = startCLI(['--port=0', fixtures.path('debugger/empty.js')]); const rootDir = path.resolve(__dirname, '..', '..'); diff --git a/test/sequential/test-debugger-profile.js b/test/sequential/test-debugger-profile.js index bf4a69720022cd..6cd0fc9d88d399 100644 --- a/test/sequential/test-debugger-profile.js +++ b/test/sequential/test-debugger-profile.js @@ -14,7 +14,7 @@ function delay(ms) { // Profiles. { - const cli = startCLI([fixtures.path('debugger/empty.js')]); + const cli = startCLI(['--port=0', fixtures.path('debugger/empty.js')]); function onFatal(error) { cli.quit(); diff --git a/test/sequential/test-debugger-repeat-last.js b/test/sequential/test-debugger-repeat-last.js index 5bdcc7dc8c8642..9a9b8eecdc710d 100644 --- a/test/sequential/test-debugger-repeat-last.js +++ b/test/sequential/test-debugger-repeat-last.js @@ -8,7 +8,7 @@ const fixture = path('debugger-repeat-last.js'); const args = [ 'inspect', - `--port=${common.PORT}`, + '--port=0', fixture, ]; diff --git a/test/sequential/test-debugger-restart-message.js b/test/sequential/test-debugger-restart-message.js index 190d0c18ccc081..e4001b47ee2df4 100644 --- a/test/sequential/test-debugger-restart-message.js +++ b/test/sequential/test-debugger-restart-message.js @@ -14,7 +14,7 @@ const startCLI = require('../common/debugger'); // Using `restart` should result in only one "Connect/For help" message. { const script = fixtures.path('debugger', 'three-lines.js'); - const cli = startCLI([script]); + const cli = startCLI(['--port=0', script]); const listeningRegExp = /Debugger listening on/g; diff --git a/test/sequential/test-debugger-run-after-quit-restart.js b/test/sequential/test-debugger-run-after-quit-restart.js index a9da07dcdff8bd..2c56f7227aed69 100644 --- a/test/sequential/test-debugger-run-after-quit-restart.js +++ b/test/sequential/test-debugger-run-after-quit-restart.js @@ -13,7 +13,7 @@ const path = require('path'); { const scriptFullPath = fixtures.path('debugger', 'three-lines.js'); const script = path.relative(process.cwd(), scriptFullPath); - const cli = startCLI([script]); + const cli = startCLI(['--port=0', script]); function onFatal(error) { cli.quit(); diff --git a/test/sequential/test-debugger-sb-before-load.js b/test/sequential/test-debugger-sb-before-load.js index e2267156b7420b..416147b4bb64c5 100644 --- a/test/sequential/test-debugger-sb-before-load.js +++ b/test/sequential/test-debugger-sb-before-load.js @@ -17,7 +17,7 @@ const script = path.relative(process.cwd(), scriptFullPath); const otherScriptFullPath = fixtures.path('debugger', 'cjs', 'other.js'); const otherScript = path.relative(process.cwd(), otherScriptFullPath); -const cli = startCLI([script]); +const cli = startCLI(['--port=0', script]); (async () => { await cli.waitForInitialBreak(); diff --git a/test/sequential/test-debugger-scripts.js b/test/sequential/test-debugger-scripts.js index b0f611bd1c6491..83f578cf1cabbb 100644 --- a/test/sequential/test-debugger-scripts.js +++ b/test/sequential/test-debugger-scripts.js @@ -11,7 +11,7 @@ const assert = require('assert'); // List scripts. { const script = fixtures.path('debugger', 'three-lines.js'); - const cli = startCLI([script]); + const cli = startCLI(['--port=0', script]); (async () => { try { diff --git a/test/sequential/test-debugger-set-context-line-number.mjs b/test/sequential/test-debugger-set-context-line-number.mjs index adb6d9ab9e52b0..5c6e281c1d3b4a 100644 --- a/test/sequential/test-debugger-set-context-line-number.mjs +++ b/test/sequential/test-debugger-set-context-line-number.mjs @@ -7,7 +7,7 @@ import startCLI from '../common/debugger.js'; import assert from 'assert'; const script = path('debugger', 'twenty-lines.js'); -const cli = startCLI([script]); +const cli = startCLI(['--port=0', script]); function onFatal(error) { cli.quit(); diff --git a/test/sequential/test-debugger-use-strict.js b/test/sequential/test-debugger-use-strict.js index ae82a9fc82352b..dce928697659ea 100644 --- a/test/sequential/test-debugger-use-strict.js +++ b/test/sequential/test-debugger-use-strict.js @@ -11,7 +11,7 @@ const assert = require('assert'); // Test for files that start with strict directive. { const script = fixtures.path('debugger', 'use-strict.js'); - const cli = startCLI([script]); + const cli = startCLI(['--port=0', script]); function onFatal(error) { cli.quit(); diff --git a/test/sequential/test-debugger-watch-validation.js b/test/sequential/test-debugger-watch-validation.js index 46307c18d55526..2ccd889646729d 100644 --- a/test/sequential/test-debugger-watch-validation.js +++ b/test/sequential/test-debugger-watch-validation.js @@ -8,7 +8,7 @@ const startCLI = require('../common/debugger'); const assert = require('assert'); -const cli = startCLI([fixtures.path('debugger/break.js')]); +const cli = startCLI(['--port=0', fixtures.path('debugger/break.js')]); (async () => { await cli.waitForInitialBreak(); diff --git a/test/sequential/test-debugger-watchers.mjs b/test/sequential/test-debugger-watchers.mjs index 4ff7ea00a22258..d2492cde67c84e 100644 --- a/test/sequential/test-debugger-watchers.mjs +++ b/test/sequential/test-debugger-watchers.mjs @@ -7,7 +7,7 @@ import startCLI from '../common/debugger.js'; import assert from 'assert'; const script = path('debugger', 'break.js'); -const cli = startCLI([script]); +const cli = startCLI(['--port=0', script]); function onFatal(error) { cli.quit();