Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: watch mode inspect restart repeatedly #45060

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 17 additions & 5 deletions test/sequential/test-watch-mode-inspect.mjs
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