forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tools, test: fix prof polyfill readline
`node --prof foo.js` may not print the full profile log file, leaving the last line broken (for example `tick,`. When that happens, `readline` will be stuck in an infinite loop. This patch fixes it. Also introduced `common.isCPPSymbolsNotMapped` to avoid duplicated code on tick-processor tests. PR-URL: nodejs#18641 Reviewed-By: Khaidi Chu <i@2333.moe> Reviewed-By: Matheus Marchini <matheus@sthima.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
- Loading branch information
Showing
7 changed files
with
86 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
test/tick-processor/test-tick-processor-polyfill-brokenfile.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const tmpdir = require('../common/tmpdir'); | ||
tmpdir.refresh(); | ||
|
||
if (!common.enoughTestCpu) | ||
common.skip('test is CPU-intensive'); | ||
|
||
if (common.isCPPSymbolsNotMapped) { | ||
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'); | ||
const cp = require('child_process'); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
|
||
const LOG_FILE = path.join(tmpdir.path, 'tick-processor.log'); | ||
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();`; | ||
|
||
const proc = cp.spawn(process.execPath, [ | ||
'--no_logfile_per_isolate', | ||
'--logfile=-', | ||
'--prof', | ||
'-pe', code | ||
], { | ||
stdio: ['ignore', 'pipe', 'inherit'] | ||
}); | ||
|
||
let ticks = ''; | ||
proc.stdout.on('data', (chunk) => ticks += chunk); | ||
|
||
|
||
function runPolyfill(content) { | ||
proc.kill(); | ||
content += BROKEN_PART; | ||
fs.writeFileSync(LOG_FILE, content); | ||
const child = cp.spawnSync( | ||
`${process.execPath}`, | ||
[ | ||
'--prof-process', LOG_FILE | ||
]); | ||
assert(WARN_REG_EXP.test(child.stderr.toString())); | ||
assert(WARN_DETAIL_REG_EXP.test(child.stderr.toString())); | ||
assert.strictEqual(child.status, 0); | ||
} | ||
|
||
setTimeout(() => runPolyfill(ticks), RETRY_TIMEOUT); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters