mirror of
https://github.com/nodejs/node.git
synced 2026-10-28 18:25:13 +08:00
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>
69 lines
1.7 KiB
JavaScript
69 lines
1.7 KiB
JavaScript
'use strict';
|
|
|
|
// This tests that --cpu-prof-name can be used to specify the
|
|
// name of the generated CPU profile.
|
|
|
|
const common = require('../common');
|
|
const fixtures = require('../common/fixtures');
|
|
common.skipIfInspectorDisabled();
|
|
|
|
const assert = require('assert');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const { spawnSyncAndExitWithoutError } = require('../common/child_process');
|
|
|
|
const tmpdir = require('../common/tmpdir');
|
|
const {
|
|
getCpuProfiles,
|
|
kCpuProfInterval,
|
|
env,
|
|
verifyFrames,
|
|
} = require('../common/cpu-prof');
|
|
|
|
// --cpu-prof-name
|
|
{
|
|
tmpdir.refresh();
|
|
const file = tmpdir.resolve('test.cpuprofile');
|
|
const { child: output } = spawnSyncAndExitWithoutError(process.execPath, [
|
|
'--cpu-prof',
|
|
'--cpu-prof-interval',
|
|
kCpuProfInterval,
|
|
'--cpu-prof-name',
|
|
'test.cpuprofile',
|
|
fixtures.path('workload', 'fibonacci.js'),
|
|
], {
|
|
cwd: tmpdir.path,
|
|
env,
|
|
});
|
|
const profiles = getCpuProfiles(tmpdir.path);
|
|
assert.deepStrictEqual(profiles, [file]);
|
|
verifyFrames(output, file, 'fibonacci.js');
|
|
}
|
|
|
|
// --cpu-prof-name with ${pid} placeholder
|
|
{
|
|
tmpdir.refresh();
|
|
// eslint-disable-next-line no-template-curly-in-string
|
|
const profName = 'CPU.${pid}.cpuprofile';
|
|
const dir = tmpdir.path;
|
|
|
|
const { child: output } = spawnSyncAndExitWithoutError(process.execPath, [
|
|
'--cpu-prof',
|
|
'--cpu-prof-interval',
|
|
kCpuProfInterval,
|
|
'--cpu-prof-name',
|
|
profName,
|
|
fixtures.path('workload', 'fibonacci.js'),
|
|
], {
|
|
cwd: dir,
|
|
env,
|
|
});
|
|
|
|
const expectedFile = path.join(dir, `CPU.${output.pid}.cpuprofile`);
|
|
assert.ok(fs.existsSync(expectedFile), `Expected file ${expectedFile} not found.`);
|
|
|
|
verifyFrames(output, expectedFile, 'fibonacci.js');
|
|
|
|
fs.unlinkSync(expectedFile);
|
|
}
|