Skip to content

Commit a75dfea

Browse files
panvaaduh95
authored andcommitted
test: split process timeout report coverage
Move the blocked Worker case into its own test. Signed-off-by: Filip Skokan <panva.ip@gmail.com> Assisted-by: Codex PR-URL: #66428 Reviewed-By: Stefan Stojanovic <stefan.stojanovic@janeasystems.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 241e8e3 commit a75dfea

2 files changed

Lines changed: 57 additions & 47 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
'use strict';
2+
3+
// Tests --report-on-process-timeout with a blocked Worker.
4+
5+
const common = require('../common');
6+
const assert = require('assert');
7+
const fs = require('fs');
8+
const { spawnSync } = require('child_process');
9+
const fixtures = require('../common/fixtures');
10+
const helper = require('../common/report');
11+
const tmpdir = require('../common/tmpdir');
12+
13+
tmpdir.refresh();
14+
15+
// A Worker thread that is blocked in a synchronous native call cannot
16+
// provide its part of the report. It is left out, so that the report is
17+
// completed before the process is forced to exit.
18+
// If the Worker thread was not blocked yet when the deadline expired, which
19+
// the fixture signals by creating a file, it is included in the report. Run
20+
// the fixture again with a longer timeout in that case.
21+
let child;
22+
let report;
23+
for (let timeout = common.platformTimeout(1000); ; timeout *= 2) {
24+
// Child processes of a previous attempt may still be running, so use a
25+
// different file for each attempt.
26+
const marker = tmpdir.resolve(`blocked-worker.${timeout}.ready`);
27+
child = spawnSync(process.execPath, [
28+
`--process-timeout=${timeout}ms`,
29+
'--report-on-process-timeout',
30+
fixtures.path('process-timeout', 'blocked-worker.js'),
31+
marker,
32+
], { cwd: tmpdir.path, encoding: 'utf8' });
33+
34+
const reports = helper.findReports(child.pid, tmpdir.path);
35+
assert.strictEqual(reports.length, 1, child.stderr);
36+
helper.validate(reports[0], [
37+
['header.event', 'Process timed out (--process-timeout)'],
38+
['header.trigger', 'ProcessTimeout'],
39+
]);
40+
report = JSON.parse(fs.readFileSync(reports[0], 'utf8'));
41+
if ((fs.existsSync(marker) && report.workers.length === 0) ||
42+
timeout >= common.platformTimeout(16000)) {
43+
break;
44+
}
45+
}
46+
47+
assert.strictEqual(child.signal, null);
48+
assert.strictEqual(child.status, 124, child.stderr);
49+
assert.match(child.stderr, /^ {4}Worker \(thread 1, name 'blocked'\)$/m);
50+
// The report is completed before the process is forced to exit, so the
51+
// message about that is printed on its own line.
52+
assert.match(child.stderr, new RegExp(
53+
'^Writing Node\\.js report to file: report\\.\\S+\\.json\\r?\\n' +
54+
'Node\\.js report completed\\r?\\n' +
55+
'\\(node:\\d+\\) The process did not finish exiting within 5000ms after ' +
56+
'--process-timeout expired\\. Forcing exit\\.$', 'm'));
57+
assert.deepStrictEqual(report.workers, []);

‎test/report/test-report-process-timeout.js‎

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const common = require('../common');
66
const assert = require('assert');
77
const fs = require('fs');
88
const { spawnSync } = require('child_process');
9-
const fixtures = require('../common/fixtures');
109
const helper = require('../common/report');
1110
const tmpdir = require('../common/tmpdir');
1211

@@ -46,49 +45,3 @@ helper.validate(reports[0], [
4645

4746
const report = JSON.parse(fs.readFileSync(reports[0], 'utf8'));
4847
assert.match(report.javascriptStack.stack[0], /^at spin \(\[eval\]:1:\d+\)$/);
49-
50-
{
51-
// A Worker thread that is blocked in a synchronous native call cannot
52-
// provide its part of the report. It is left out, so that the report is
53-
// completed before the process is forced to exit.
54-
// If the Worker thread was not blocked yet when the deadline expired, which
55-
// the fixture signals by creating a file, it is included in the report. Run
56-
// the fixture again with a longer timeout in that case.
57-
let child;
58-
let report;
59-
for (let timeout = common.platformTimeout(1000); ; timeout *= 2) {
60-
// Child processes of a previous attempt may still be running, so use a
61-
// different file for each attempt.
62-
const marker = tmpdir.resolve(`blocked-worker.${timeout}.ready`);
63-
child = spawnSync(process.execPath, [
64-
`--process-timeout=${timeout}ms`,
65-
'--report-on-process-timeout',
66-
fixtures.path('process-timeout', 'blocked-worker.js'),
67-
marker,
68-
], { cwd: tmpdir.path, encoding: 'utf8' });
69-
70-
const reports = helper.findReports(child.pid, tmpdir.path);
71-
assert.strictEqual(reports.length, 1, child.stderr);
72-
helper.validate(reports[0], [
73-
['header.event', 'Process timed out (--process-timeout)'],
74-
['header.trigger', 'ProcessTimeout'],
75-
]);
76-
report = JSON.parse(fs.readFileSync(reports[0], 'utf8'));
77-
if ((fs.existsSync(marker) && report.workers.length === 0) ||
78-
timeout >= common.platformTimeout(16000)) {
79-
break;
80-
}
81-
}
82-
83-
assert.strictEqual(child.signal, null);
84-
assert.strictEqual(child.status, 124, child.stderr);
85-
assert.match(child.stderr, /^ {4}Worker \(thread 1, name 'blocked'\)$/m);
86-
// The report is completed before the process is forced to exit, so the
87-
// message about that is printed on its own line.
88-
assert.match(child.stderr, new RegExp(
89-
'^Writing Node\\.js report to file: report\\.\\S+\\.json\\r?\\n' +
90-
'Node\\.js report completed\\r?\\n' +
91-
'\\(node:\\d+\\) The process did not finish exiting within 5000ms after ' +
92-
'--process-timeout expired\\. Forcing exit\\.$', 'm'));
93-
assert.deepStrictEqual(report.workers, []);
94-
}

0 commit comments

Comments
 (0)