Skip to content

Commit 35903e6

Browse files
MoLowdanielleadams
authored andcommitted
test: watch mode inspect restart repeatedly
PR-URL: #45060 Fixes: #44805 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 728efef commit 35903e6

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

test/sequential/test-watch-mode-inspect.mjs

+17-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as fixtures from '../common/fixtures.mjs';
33
import assert from 'node:assert';
44
import { describe, it } from 'node:test';
55
import { writeFileSync, readFileSync } from 'node:fs';
6+
import { setTimeout } from 'node:timers/promises';
67
import { NodeInstance } from '../common/inspector-helper.js';
78

89

@@ -11,6 +12,12 @@ if (common.isIBMi)
1112

1213
common.skipIfInspectorDisabled();
1314

15+
function restart(file) {
16+
writeFileSync(file, readFileSync(file));
17+
const interval = setInterval(() => writeFileSync(file, readFileSync(file)), 500);
18+
return () => clearInterval(interval);
19+
}
20+
1421
describe('watch mode - inspect', () => {
1522
async function getDebuggedPid(instance, waitForLog = true) {
1623
const session = await instance.connectInspectorSession();
@@ -29,20 +36,25 @@ describe('watch mode - inspect', () => {
2936
const file = fixtures.path('watch-mode/inspect.js');
3037
const instance = new NodeInstance(['--inspect=0', '--watch'], undefined, file);
3138
let stderr = '';
39+
const stdout = [];
3240
instance.on('stderr', (data) => { stderr += data; });
41+
instance.on('stdout', (data) => { stdout.push(data); });
3342

3443
const pids = [instance.pid];
3544
pids.push(await getDebuggedPid(instance));
3645
instance.resetPort();
37-
writeFileSync(file, readFileSync(file));
46+
const stopRestarting = restart(file);
3847
pids.push(await getDebuggedPid(instance));
48+
stopRestarting();
3949

50+
await setTimeout(common.platformTimeout(500));
4051
await instance.kill();
4152

42-
// There should be 3 pids (one parent + 2 restarts).
43-
// Message about Debugger should only appear twice.
44-
assert.strictEqual(stderr.match(/Debugger listening on ws:\/\//g).length, 2);
45-
assert.strictEqual(new Set(pids).size, 3);
53+
// There should be a process per restart and one per parent process.
54+
// Message about Debugger should appear once per restart.
55+
const restarts = stdout.filter((line) => line === 'safe to debug now').length;
56+
assert.strictEqual(stderr.match(/Debugger listening on ws:\/\//g).length, restarts);
57+
assert.strictEqual(new Set(pids).size, restarts + 1);
4658
});
4759

4860
it('should prevent attaching debugger with SIGUSR1 to outer process', { skip: common.isWindows }, async () => {

0 commit comments

Comments
 (0)