2018-02-11 03:50:31 +00:00
|
|
|
'use strict';
|
|
|
|
const common = require('../common');
|
2018-08-22 15:14:31 +00:00
|
|
|
const { isCPPSymbolsNotMapped } = require('./util');
|
2018-02-11 03:50:31 +00:00
|
|
|
const tmpdir = require('../common/tmpdir');
|
|
|
|
tmpdir.refresh();
|
|
|
|
|
2018-08-22 15:14:31 +00:00
|
|
|
if (isCPPSymbolsNotMapped) {
|
2018-02-11 03:50:31 +00:00
|
|
|
common.skip('C++ symbols are not mapped for this OS.');
|
|
|
|
}
|
|
|
|
|
|
|
|
// This test will produce a broken profile log.
|
|
|
|
// ensure prof-polyfill not stuck in infinite loop
|
|
|
|
// and success process
|
|
|
|
|
|
|
|
|
|
|
|
const assert = require('assert');
|
2018-11-17 21:38:44 +00:00
|
|
|
const { spawn, spawnSync } = require('child_process');
|
|
|
|
const { writeFileSync } = require('fs');
|
2018-02-11 03:50:31 +00:00
|
|
|
|
2023-08-21 16:41:53 +00:00
|
|
|
const LOG_FILE = tmpdir.resolve('tick-processor.log');
|
2018-02-11 03:50:31 +00:00
|
|
|
const RETRY_TIMEOUT = 150;
|
|
|
|
const BROKEN_PART = 'tick,';
|
|
|
|
const WARN_REG_EXP = /\(node:\d+\) \[BROKEN_PROFILE_FILE] Warning: Profile file .* is broken/;
|
|
|
|
const WARN_DETAIL_REG_EXP = /".*tick," at the file end is broken/;
|
|
|
|
|
|
|
|
const code = `function f() {
|
|
|
|
this.ts = Date.now();
|
|
|
|
setImmediate(function() { new f(); });
|
|
|
|
};
|
|
|
|
f();`;
|
|
|
|
|
2018-11-17 21:38:44 +00:00
|
|
|
const proc = spawn(process.execPath, [
|
2018-02-11 03:50:31 +00:00
|
|
|
'--no_logfile_per_isolate',
|
|
|
|
'--logfile=-',
|
|
|
|
'--prof',
|
2021-03-26 15:51:08 +00:00
|
|
|
'-pe', code,
|
2018-02-11 03:50:31 +00:00
|
|
|
], {
|
2022-11-17 13:02:11 +00:00
|
|
|
stdio: ['ignore', 'pipe', 'inherit'],
|
2018-02-11 03:50:31 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
let ticks = '';
|
|
|
|
proc.stdout.on('data', (chunk) => ticks += chunk);
|
|
|
|
|
|
|
|
|
|
|
|
function runPolyfill(content) {
|
|
|
|
proc.kill();
|
|
|
|
content += BROKEN_PART;
|
2018-11-17 21:38:44 +00:00
|
|
|
writeFileSync(LOG_FILE, content);
|
|
|
|
const child = spawnSync(
|
2018-02-11 03:50:31 +00:00
|
|
|
`${process.execPath}`,
|
|
|
|
[
|
2021-03-26 15:51:08 +00:00
|
|
|
'--prof-process', LOG_FILE,
|
2018-02-11 03:50:31 +00:00
|
|
|
]);
|
2021-08-29 08:14:22 +00:00
|
|
|
assert.match(child.stderr.toString(), WARN_REG_EXP);
|
|
|
|
assert.match(child.stderr.toString(), WARN_DETAIL_REG_EXP);
|
2018-02-11 03:50:31 +00:00
|
|
|
assert.strictEqual(child.status, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
setTimeout(() => runPolyfill(ticks), RETRY_TIMEOUT);
|