mirror of
https://github.com/nodejs/node.git
synced 2026-10-28 10:15:07 +08:00
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: https://github.com/nodejs/node/pull/65351 Refs: https://github.com/nodejs/node/pull/65552 Assisted-by: claude:opus-5 Signed-off-by: Junhwan Choi <devjunsday@gmail.com> PR-URL: https://github.com/nodejs/node/pull/65694 Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
1 parent
8bf65d4beb
commit
d78337f085
8 files changed
+17
-55
No files matched your search
@@ -10,7 +10,7 @@ const fixtures = require('../common/fixtures');
|
||||
common.skipIfInspectorDisabled();
|
||||
|
||||
const assert = require('assert');
|
||||
const { spawnSync } = require('child_process');
|
||||
const { spawnSyncAndExitWithoutError } = require('../common/child_process');
|
||||
|
||||
const tmpdir = require('../common/tmpdir');
|
||||
const {
|
||||
@@ -20,17 +20,13 @@ const {
|
||||
|
||||
{
|
||||
tmpdir.refresh();
|
||||
const output = spawnSync(process.execPath, [
|
||||
spawnSyncAndExitWithoutError(process.execPath, [
|
||||
'--cpu-prof',
|
||||
fixtures.path('workload', 'fibonacci.js'),
|
||||
], {
|
||||
cwd: tmpdir.path,
|
||||
env,
|
||||
});
|
||||
if (output.status !== 0) {
|
||||
console.log(output.stderr.toString());
|
||||
}
|
||||
assert.strictEqual(output.status, 0);
|
||||
const profiles = getCpuProfiles(tmpdir.path);
|
||||
assert.strictEqual(profiles.length, 1);
|
||||
}
|
||||
@@ -8,7 +8,7 @@ common.skipIfInspectorDisabled();
|
||||
|
||||
const assert = require('assert');
|
||||
const fs = require('fs');
|
||||
const { spawnSync } = require('child_process');
|
||||
const { spawnSyncAndExitWithoutError } = require('../common/child_process');
|
||||
|
||||
const tmpdir = require('../common/tmpdir');
|
||||
const {
|
||||
@@ -22,7 +22,7 @@ const {
|
||||
{
|
||||
tmpdir.refresh();
|
||||
const dir = tmpdir.resolve('prof');
|
||||
const output = spawnSync(process.execPath, [
|
||||
const { child: output } = spawnSyncAndExitWithoutError(process.execPath, [
|
||||
'--cpu-prof',
|
||||
'--cpu-prof-interval',
|
||||
kCpuProfInterval,
|
||||
@@ -33,10 +33,6 @@ const {
|
||||
cwd: tmpdir.path,
|
||||
env,
|
||||
});
|
||||
if (output.status !== 0) {
|
||||
console.log(output.stderr.toString());
|
||||
}
|
||||
assert.strictEqual(output.status, 0);
|
||||
assert(fs.existsSync(dir));
|
||||
const profiles = getCpuProfiles(dir);
|
||||
assert.strictEqual(profiles.length, 1);
|
||||
|
||||
@@ -9,7 +9,7 @@ common.skipIfInspectorDisabled();
|
||||
const assert = require('assert');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { spawnSync } = require('child_process');
|
||||
const { spawnSyncAndExitWithoutError } = require('../common/child_process');
|
||||
|
||||
const tmpdir = require('../common/tmpdir');
|
||||
const {
|
||||
@@ -23,7 +23,7 @@ const {
|
||||
tmpdir.refresh();
|
||||
const dir = tmpdir.resolve('prof');
|
||||
const file = path.join(dir, 'test.cpuprofile');
|
||||
const output = spawnSync(process.execPath, [
|
||||
const { child: output } = spawnSyncAndExitWithoutError(process.execPath, [
|
||||
'--cpu-prof',
|
||||
'--cpu-prof-interval',
|
||||
kCpuProfInterval,
|
||||
@@ -36,10 +36,6 @@ const {
|
||||
cwd: tmpdir.path,
|
||||
env,
|
||||
});
|
||||
if (output.status !== 0) {
|
||||
console.log(output.stderr.toString());
|
||||
}
|
||||
assert.strictEqual(output.status, 0);
|
||||
assert(fs.existsSync(dir));
|
||||
const profiles = getCpuProfiles(dir);
|
||||
assert.deepStrictEqual(profiles, [file]);
|
||||
|
||||
@@ -8,7 +8,7 @@ common.skipIfInspectorDisabled();
|
||||
|
||||
const assert = require('assert');
|
||||
const fs = require('fs');
|
||||
const { spawnSync } = require('child_process');
|
||||
const { spawnSyncAndExitWithoutError } = require('../common/child_process');
|
||||
|
||||
const tmpdir = require('../common/tmpdir');
|
||||
const {
|
||||
@@ -21,7 +21,7 @@ const {
|
||||
// relative --cpu-prof-dir
|
||||
{
|
||||
tmpdir.refresh();
|
||||
const output = spawnSync(process.execPath, [
|
||||
const { child: output } = spawnSyncAndExitWithoutError(process.execPath, [
|
||||
'--cpu-prof',
|
||||
'--cpu-prof-interval',
|
||||
kCpuProfInterval,
|
||||
@@ -32,10 +32,6 @@ const {
|
||||
cwd: tmpdir.path,
|
||||
env,
|
||||
});
|
||||
if (output.status !== 0) {
|
||||
console.log(output.stderr.toString());
|
||||
}
|
||||
assert.strictEqual(output.status, 0);
|
||||
const dir = tmpdir.resolve('prof');
|
||||
assert(fs.existsSync(dir));
|
||||
const profiles = getCpuProfiles(dir);
|
||||
|
||||
@@ -8,7 +8,7 @@ common.skipIfInspectorDisabled();
|
||||
|
||||
const assert = require('assert');
|
||||
const fs = require('fs');
|
||||
const { spawnSync } = require('child_process');
|
||||
const { spawnSyncAndExitWithoutError } = require('../common/child_process');
|
||||
|
||||
const tmpdir = require('../common/tmpdir');
|
||||
const {
|
||||
@@ -21,7 +21,7 @@ const {
|
||||
// --cpu-prof-dir with worker
|
||||
{
|
||||
tmpdir.refresh();
|
||||
const output = spawnSync(process.execPath, [
|
||||
const { child: output } = spawnSyncAndExitWithoutError(process.execPath, [
|
||||
'--cpu-prof-interval',
|
||||
kCpuProfInterval,
|
||||
'--cpu-prof-dir',
|
||||
@@ -32,10 +32,6 @@ const {
|
||||
cwd: tmpdir.path,
|
||||
env,
|
||||
});
|
||||
if (output.status !== 0) {
|
||||
console.log(output.stderr.toString());
|
||||
}
|
||||
assert.strictEqual(output.status, 0);
|
||||
const dir = tmpdir.resolve('prof');
|
||||
assert(fs.existsSync(dir));
|
||||
const profiles = getCpuProfiles(dir);
|
||||
|
||||
@@ -9,7 +9,7 @@ const fixtures = require('../common/fixtures');
|
||||
common.skipIfInspectorDisabled();
|
||||
|
||||
const assert = require('assert');
|
||||
const { spawnSync } = require('child_process');
|
||||
const { spawnSyncAndExitWithoutError } = require('../common/child_process');
|
||||
|
||||
const tmpdir = require('../common/tmpdir');
|
||||
const {
|
||||
@@ -21,7 +21,7 @@ const {
|
||||
|
||||
{
|
||||
tmpdir.refresh();
|
||||
const output = spawnSync(process.execPath, [
|
||||
const { child: output } = spawnSyncAndExitWithoutError(process.execPath, [
|
||||
'--cpu-prof',
|
||||
'--cpu-prof-interval',
|
||||
kCpuProfInterval,
|
||||
@@ -30,10 +30,6 @@ const {
|
||||
cwd: tmpdir.path,
|
||||
env,
|
||||
});
|
||||
if (output.status !== 0) {
|
||||
console.log(output.stderr.toString());
|
||||
}
|
||||
assert.strictEqual(output.status, 0);
|
||||
const profiles = getCpuProfiles(tmpdir.path);
|
||||
assert.strictEqual(profiles.length, 1);
|
||||
verifyFrames(output, profiles[0], 'fibonacci.js');
|
||||
|
||||
@@ -10,7 +10,7 @@ common.skipIfInspectorDisabled();
|
||||
const assert = require('assert');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { spawnSync } = require('child_process');
|
||||
const { spawnSyncAndExitWithoutError } = require('../common/child_process');
|
||||
|
||||
const tmpdir = require('../common/tmpdir');
|
||||
const {
|
||||
@@ -24,7 +24,7 @@ const {
|
||||
{
|
||||
tmpdir.refresh();
|
||||
const file = tmpdir.resolve('test.cpuprofile');
|
||||
const output = spawnSync(process.execPath, [
|
||||
const { child: output } = spawnSyncAndExitWithoutError(process.execPath, [
|
||||
'--cpu-prof',
|
||||
'--cpu-prof-interval',
|
||||
kCpuProfInterval,
|
||||
@@ -35,10 +35,6 @@ const {
|
||||
cwd: tmpdir.path,
|
||||
env,
|
||||
});
|
||||
if (output.status !== 0) {
|
||||
console.log(output.stderr.toString());
|
||||
}
|
||||
assert.strictEqual(output.status, 0);
|
||||
const profiles = getCpuProfiles(tmpdir.path);
|
||||
assert.deepStrictEqual(profiles, [file]);
|
||||
verifyFrames(output, file, 'fibonacci.js');
|
||||
@@ -51,7 +47,7 @@ const {
|
||||
const profName = 'CPU.${pid}.cpuprofile';
|
||||
const dir = tmpdir.path;
|
||||
|
||||
const output = spawnSync(process.execPath, [
|
||||
const { child: output } = spawnSyncAndExitWithoutError(process.execPath, [
|
||||
'--cpu-prof',
|
||||
'--cpu-prof-interval',
|
||||
kCpuProfInterval,
|
||||
@@ -63,12 +59,6 @@ const {
|
||||
env,
|
||||
});
|
||||
|
||||
if (output.status !== 0) {
|
||||
console.error(output.stderr.toString());
|
||||
}
|
||||
|
||||
assert.strictEqual(output.status, 0);
|
||||
|
||||
const expectedFile = path.join(dir, `CPU.${output.pid}.cpuprofile`);
|
||||
assert.ok(fs.existsSync(expectedFile), `Expected file ${expectedFile} not found.`);
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ const fixtures = require('../common/fixtures');
|
||||
common.skipIfInspectorDisabled();
|
||||
|
||||
const assert = require('assert');
|
||||
const { spawnSync } = require('child_process');
|
||||
const { spawnSyncAndExitWithoutError } = require('../common/child_process');
|
||||
|
||||
const tmpdir = require('../common/tmpdir');
|
||||
const {
|
||||
@@ -19,7 +19,7 @@ const {
|
||||
|
||||
{
|
||||
tmpdir.refresh();
|
||||
const output = spawnSync(process.execPath, [
|
||||
const { child: output } = spawnSyncAndExitWithoutError(process.execPath, [
|
||||
fixtures.path('workload', 'fibonacci-worker-argv.js'),
|
||||
], {
|
||||
cwd: tmpdir.path,
|
||||
@@ -28,10 +28,6 @@ const {
|
||||
CPU_PROF_INTERVAL: kCpuProfInterval,
|
||||
},
|
||||
});
|
||||
if (output.status !== 0) {
|
||||
console.log(output.stderr.toString());
|
||||
}
|
||||
assert.strictEqual(output.status, 0);
|
||||
const profiles = getCpuProfiles(tmpdir.path);
|
||||
assert.strictEqual(profiles.length, 1);
|
||||
verifyFrames(output, profiles[0], 'fibonacci.js');
|
||||
|
||||
Reference in new issue
Block a user