Skip to content

Commit

Permalink
test: watch mode inspect restart repeatedly
Browse files Browse the repository at this point in the history
PR-URL: #45060
Fixes: #44805
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
MoLow authored and danielleadams committed Jan 3, 2023
1 parent c514751 commit a8030b9
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions test/sequential/test-watch-mode-inspect.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as fixtures from '../common/fixtures.mjs';
import assert from 'node:assert';
import { describe, it } from 'node:test';
import { writeFileSync, readFileSync } from 'node:fs';
import { setTimeout } from 'node:timers/promises';
import { NodeInstance } from '../common/inspector-helper.js';


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

common.skipIfInspectorDisabled();

function restart(file) {
writeFileSync(file, readFileSync(file));
const interval = setInterval(() => writeFileSync(file, readFileSync(file)), 500);
return () => clearInterval(interval);
}

describe('watch mode - inspect', () => {
async function getDebuggedPid(instance, waitForLog = true) {
const session = await instance.connectInspectorSession();
Expand All @@ -29,20 +36,25 @@ describe('watch mode - inspect', () => {
const file = fixtures.path('watch-mode/inspect.js');
const instance = new NodeInstance(['--inspect=0', '--watch'], undefined, file);
let stderr = '';
const stdout = [];
instance.on('stderr', (data) => { stderr += data; });
instance.on('stdout', (data) => { stdout.push(data); });

const pids = [instance.pid];
pids.push(await getDebuggedPid(instance));
instance.resetPort();
writeFileSync(file, readFileSync(file));
const stopRestarting = restart(file);
pids.push(await getDebuggedPid(instance));
stopRestarting();

await setTimeout(common.platformTimeout(500));
await instance.kill();

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

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

0 comments on commit a8030b9

Please sign in to comment.