Skip to content

Commit 7b1c74e

Browse files
DevJunzaduh95
authored andcommitted
test: use spawnSync helpers in cpu-prof tests
The cpu-prof tests hand-rolled a partial version of what test/common/child_process already provides: log the child's stderr when the status is non-zero, then assert the status. That manual version never shows stdout, the signal, or the command that ran, so a CI failure gives less information than the helper would. Replace those blocks with spawnSyncAndExitWithoutError(). Every existing expectation is preserved -- status 0 is still required, and signal null is now checked as well, matching the helper defaults. Only success-path blocks whose assertions map one-to-one onto the helper defaults are converted. Refs: #65351 Refs: #65552 Assisted-by: claude:opus-5 Signed-off-by: Junhwan Choi <devjunsday@gmail.com> PR-URL: #65694 Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 583ee1c commit 7b1c74e

8 files changed

Lines changed: 17 additions & 55 deletions

‎test/sequential/test-cpu-prof-default.js‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const fixtures = require('../common/fixtures');
1010
common.skipIfInspectorDisabled();
1111

1212
const assert = require('assert');
13-
const { spawnSync } = require('child_process');
13+
const { spawnSyncAndExitWithoutError } = require('../common/child_process');
1414

1515
const tmpdir = require('../common/tmpdir');
1616
const {
@@ -20,17 +20,13 @@ const {
2020

2121
{
2222
tmpdir.refresh();
23-
const output = spawnSync(process.execPath, [
23+
spawnSyncAndExitWithoutError(process.execPath, [
2424
'--cpu-prof',
2525
fixtures.path('workload', 'fibonacci.js'),
2626
], {
2727
cwd: tmpdir.path,
2828
env,
2929
});
30-
if (output.status !== 0) {
31-
console.log(output.stderr.toString());
32-
}
33-
assert.strictEqual(output.status, 0);
3430
const profiles = getCpuProfiles(tmpdir.path);
3531
assert.strictEqual(profiles.length, 1);
3632
}

‎test/sequential/test-cpu-prof-dir-absolute.js‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ common.skipIfInspectorDisabled();
88

99
const assert = require('assert');
1010
const fs = require('fs');
11-
const { spawnSync } = require('child_process');
11+
const { spawnSyncAndExitWithoutError } = require('../common/child_process');
1212

1313
const tmpdir = require('../common/tmpdir');
1414
const {
@@ -22,7 +22,7 @@ const {
2222
{
2323
tmpdir.refresh();
2424
const dir = tmpdir.resolve('prof');
25-
const output = spawnSync(process.execPath, [
25+
const { child: output } = spawnSyncAndExitWithoutError(process.execPath, [
2626
'--cpu-prof',
2727
'--cpu-prof-interval',
2828
kCpuProfInterval,
@@ -33,10 +33,6 @@ const {
3333
cwd: tmpdir.path,
3434
env,
3535
});
36-
if (output.status !== 0) {
37-
console.log(output.stderr.toString());
38-
}
39-
assert.strictEqual(output.status, 0);
4036
assert(fs.existsSync(dir));
4137
const profiles = getCpuProfiles(dir);
4238
assert.strictEqual(profiles.length, 1);

‎test/sequential/test-cpu-prof-dir-and-name.js‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ common.skipIfInspectorDisabled();
99
const assert = require('assert');
1010
const fs = require('fs');
1111
const path = require('path');
12-
const { spawnSync } = require('child_process');
12+
const { spawnSyncAndExitWithoutError } = require('../common/child_process');
1313

1414
const tmpdir = require('../common/tmpdir');
1515
const {
@@ -23,7 +23,7 @@ const {
2323
tmpdir.refresh();
2424
const dir = tmpdir.resolve('prof');
2525
const file = path.join(dir, 'test.cpuprofile');
26-
const output = spawnSync(process.execPath, [
26+
const { child: output } = spawnSyncAndExitWithoutError(process.execPath, [
2727
'--cpu-prof',
2828
'--cpu-prof-interval',
2929
kCpuProfInterval,
@@ -36,10 +36,6 @@ const {
3636
cwd: tmpdir.path,
3737
env,
3838
});
39-
if (output.status !== 0) {
40-
console.log(output.stderr.toString());
41-
}
42-
assert.strictEqual(output.status, 0);
4339
assert(fs.existsSync(dir));
4440
const profiles = getCpuProfiles(dir);
4541
assert.deepStrictEqual(profiles, [file]);

‎test/sequential/test-cpu-prof-dir-relative.js‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ common.skipIfInspectorDisabled();
88

99
const assert = require('assert');
1010
const fs = require('fs');
11-
const { spawnSync } = require('child_process');
11+
const { spawnSyncAndExitWithoutError } = require('../common/child_process');
1212

1313
const tmpdir = require('../common/tmpdir');
1414
const {
@@ -21,7 +21,7 @@ const {
2121
// relative --cpu-prof-dir
2222
{
2323
tmpdir.refresh();
24-
const output = spawnSync(process.execPath, [
24+
const { child: output } = spawnSyncAndExitWithoutError(process.execPath, [
2525
'--cpu-prof',
2626
'--cpu-prof-interval',
2727
kCpuProfInterval,
@@ -32,10 +32,6 @@ const {
3232
cwd: tmpdir.path,
3333
env,
3434
});
35-
if (output.status !== 0) {
36-
console.log(output.stderr.toString());
37-
}
38-
assert.strictEqual(output.status, 0);
3935
const dir = tmpdir.resolve('prof');
4036
assert(fs.existsSync(dir));
4137
const profiles = getCpuProfiles(dir);

‎test/sequential/test-cpu-prof-dir-worker.js‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ common.skipIfInspectorDisabled();
88

99
const assert = require('assert');
1010
const fs = require('fs');
11-
const { spawnSync } = require('child_process');
11+
const { spawnSyncAndExitWithoutError } = require('../common/child_process');
1212

1313
const tmpdir = require('../common/tmpdir');
1414
const {
@@ -21,7 +21,7 @@ const {
2121
// --cpu-prof-dir with worker
2222
{
2323
tmpdir.refresh();
24-
const output = spawnSync(process.execPath, [
24+
const { child: output } = spawnSyncAndExitWithoutError(process.execPath, [
2525
'--cpu-prof-interval',
2626
kCpuProfInterval,
2727
'--cpu-prof-dir',
@@ -32,10 +32,6 @@ const {
3232
cwd: tmpdir.path,
3333
env,
3434
});
35-
if (output.status !== 0) {
36-
console.log(output.stderr.toString());
37-
}
38-
assert.strictEqual(output.status, 0);
3935
const dir = tmpdir.resolve('prof');
4036
assert(fs.existsSync(dir));
4137
const profiles = getCpuProfiles(dir);

‎test/sequential/test-cpu-prof-drained.js‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const fixtures = require('../common/fixtures');
99
common.skipIfInspectorDisabled();
1010

1111
const assert = require('assert');
12-
const { spawnSync } = require('child_process');
12+
const { spawnSyncAndExitWithoutError } = require('../common/child_process');
1313

1414
const tmpdir = require('../common/tmpdir');
1515
const {
@@ -21,7 +21,7 @@ const {
2121

2222
{
2323
tmpdir.refresh();
24-
const output = spawnSync(process.execPath, [
24+
const { child: output } = spawnSyncAndExitWithoutError(process.execPath, [
2525
'--cpu-prof',
2626
'--cpu-prof-interval',
2727
kCpuProfInterval,
@@ -30,10 +30,6 @@ const {
3030
cwd: tmpdir.path,
3131
env,
3232
});
33-
if (output.status !== 0) {
34-
console.log(output.stderr.toString());
35-
}
36-
assert.strictEqual(output.status, 0);
3733
const profiles = getCpuProfiles(tmpdir.path);
3834
assert.strictEqual(profiles.length, 1);
3935
verifyFrames(output, profiles[0], 'fibonacci.js');

‎test/sequential/test-cpu-prof-name.js‎

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ common.skipIfInspectorDisabled();
1010
const assert = require('assert');
1111
const fs = require('fs');
1212
const path = require('path');
13-
const { spawnSync } = require('child_process');
13+
const { spawnSyncAndExitWithoutError } = require('../common/child_process');
1414

1515
const tmpdir = require('../common/tmpdir');
1616
const {
@@ -24,7 +24,7 @@ const {
2424
{
2525
tmpdir.refresh();
2626
const file = tmpdir.resolve('test.cpuprofile');
27-
const output = spawnSync(process.execPath, [
27+
const { child: output } = spawnSyncAndExitWithoutError(process.execPath, [
2828
'--cpu-prof',
2929
'--cpu-prof-interval',
3030
kCpuProfInterval,
@@ -35,10 +35,6 @@ const {
3535
cwd: tmpdir.path,
3636
env,
3737
});
38-
if (output.status !== 0) {
39-
console.log(output.stderr.toString());
40-
}
41-
assert.strictEqual(output.status, 0);
4238
const profiles = getCpuProfiles(tmpdir.path);
4339
assert.deepStrictEqual(profiles, [file]);
4440
verifyFrames(output, file, 'fibonacci.js');
@@ -51,7 +47,7 @@ const {
5147
const profName = 'CPU.${pid}.cpuprofile';
5248
const dir = tmpdir.path;
5349

54-
const output = spawnSync(process.execPath, [
50+
const { child: output } = spawnSyncAndExitWithoutError(process.execPath, [
5551
'--cpu-prof',
5652
'--cpu-prof-interval',
5753
kCpuProfInterval,
@@ -63,12 +59,6 @@ const {
6359
env,
6460
});
6561

66-
if (output.status !== 0) {
67-
console.error(output.stderr.toString());
68-
}
69-
70-
assert.strictEqual(output.status, 0);
71-
7262
const expectedFile = path.join(dir, `CPU.${output.pid}.cpuprofile`);
7363
assert.ok(fs.existsSync(expectedFile), `Expected file ${expectedFile} not found.`);
7464

‎test/sequential/test-cpu-prof-worker-argv.js‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const fixtures = require('../common/fixtures');
88
common.skipIfInspectorDisabled();
99

1010
const assert = require('assert');
11-
const { spawnSync } = require('child_process');
11+
const { spawnSyncAndExitWithoutError } = require('../common/child_process');
1212

1313
const tmpdir = require('../common/tmpdir');
1414
const {
@@ -19,7 +19,7 @@ const {
1919

2020
{
2121
tmpdir.refresh();
22-
const output = spawnSync(process.execPath, [
22+
const { child: output } = spawnSyncAndExitWithoutError(process.execPath, [
2323
fixtures.path('workload', 'fibonacci-worker-argv.js'),
2424
], {
2525
cwd: tmpdir.path,
@@ -28,10 +28,6 @@ const {
2828
CPU_PROF_INTERVAL: kCpuProfInterval,
2929
},
3030
});
31-
if (output.status !== 0) {
32-
console.log(output.stderr.toString());
33-
}
34-
assert.strictEqual(output.status, 0);
3531
const profiles = getCpuProfiles(tmpdir.path);
3632
assert.strictEqual(profiles.length, 1);
3733
verifyFrames(output, profiles[0], 'fibonacci.js');

0 commit comments

Comments
 (0)