GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test: fix flaky test-watch-mode-inspect timeout · nodejs/node@d9f4e8e

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • test/sequential
    • test-watch-mode-inspect.mjs
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: test/sequential/test-watch-mode-inspect.mjs
+12-15Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ 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';
76
import { NodeInstance } from '../common/inspector-helper.js';
87

98

@@ -12,10 +11,7 @@ if (common.isIBMi)
1211

1312
common.skipIfInspectorDisabled();
1413

15-
let gettingDebuggedPid = false;
16-
1714
async function getDebuggedPid(instance, waitForLog = true) {
18-
gettingDebuggedPid = true;
1915
const session = await instance.connectInspectorSession();
2016
await session.send({ method: 'Runtime.enable' });
2117
if (waitForLog) {
@@ -25,20 +21,23 @@ async function getDebuggedPid(instance, waitForLog = true) {
2521
'method': 'Runtime.evaluate', 'params': { 'expression': 'process.pid' },
2622
})).result;
2723
session.disconnect();
28-
gettingDebuggedPid = false;
2924
return innerPid;
3025
}
3126

32-
function restart(file) {
27+
// Triggers a single restart and resolves when the restarted child prints "safe to debug now".
28+
function restartAndWaitForReady(file, instance) {
29+
const ready = new Promise((resolve) => {
30+
instance.on('stdout', (data) => {
31+
if (data?.includes('safe to debug now')) {
32+
resolve();
33+
}
34+
});
35+
});
3336
writeFileSync(file, readFileSync(file));
34-
const interval = setInterval(() => {
35-
if (!gettingDebuggedPid) {
36-
writeFileSync(file, readFileSync(file));
37-
}
38-
}, common.platformTimeout(500));
39-
return () => clearInterval(interval);
37+
return ready;
4038
}
4139

40+
4241
describe('watch mode - inspect', () => {
4342
it('should start debugger on inner process', async () => {
4443
const file = fixtures.path('watch-mode/inspect.js');
@@ -51,11 +50,9 @@ describe('watch mode - inspect', () => {
5150
const pids = [instance.pid];
5251
pids.push(await getDebuggedPid(instance));
5352
instance.resetPort();
54-
const stopRestarting = restart(file);
53+
await restartAndWaitForReady(file, instance);
5554
pids.push(await getDebuggedPid(instance));
56-
stopRestarting();
5755

58-
await setTimeout(common.platformTimeout(500));
5956
await instance.kill();
6057

6158
// There should be a process per restart and one per parent process.

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.