|
| 1 | +'use strict'; |
| 2 | +const common = require('../common'); |
| 3 | +const tmpdir = require('../common/tmpdir'); |
| 4 | +tmpdir.refresh(); |
| 5 | + |
| 6 | +if (!common.enoughTestCpu) |
| 7 | + common.skip('test is CPU-intensive'); |
| 8 | + |
| 9 | +if (common.isCPPSymbolsNotMapped) { |
| 10 | + common.skip('C++ symbols are not mapped for this OS.'); |
| 11 | +} |
| 12 | + |
| 13 | +// This test will produce a broken profile log. |
| 14 | +// ensure prof-polyfill not stuck in infinite loop |
| 15 | +// and success process |
| 16 | + |
| 17 | + |
| 18 | +const assert = require('assert'); |
| 19 | +const cp = require('child_process'); |
| 20 | +const path = require('path'); |
| 21 | +const fs = require('fs'); |
| 22 | + |
| 23 | +const LOG_FILE = path.join(tmpdir.path, 'tick-processor.log'); |
| 24 | +const RETRY_TIMEOUT = 150; |
| 25 | +const BROKEN_PART = 'tick,'; |
| 26 | +const WARN_REG_EXP = /\(node:\d+\) \[BROKEN_PROFILE_FILE] Warning: Profile file .* is broken/; |
| 27 | +const WARN_DETAIL_REG_EXP = /".*tick," at the file end is broken/; |
| 28 | + |
| 29 | +const code = `function f() { |
| 30 | + this.ts = Date.now(); |
| 31 | + setImmediate(function() { new f(); }); |
| 32 | + }; |
| 33 | + f();`; |
| 34 | + |
| 35 | +const proc = cp.spawn(process.execPath, [ |
| 36 | + '--no_logfile_per_isolate', |
| 37 | + '--logfile=-', |
| 38 | + '--prof', |
| 39 | + '-pe', code |
| 40 | +], { |
| 41 | + stdio: ['ignore', 'pipe', 'inherit'] |
| 42 | +}); |
| 43 | + |
| 44 | +let ticks = ''; |
| 45 | +proc.stdout.on('data', (chunk) => ticks += chunk); |
| 46 | + |
| 47 | + |
| 48 | +function runPolyfill(content) { |
| 49 | + proc.kill(); |
| 50 | + content += BROKEN_PART; |
| 51 | + fs.writeFileSync(LOG_FILE, content); |
| 52 | + const child = cp.spawnSync( |
| 53 | + `${process.execPath}`, |
| 54 | + [ |
| 55 | + '--prof-process', LOG_FILE |
| 56 | + ]); |
| 57 | + assert(WARN_REG_EXP.test(child.stderr.toString())); |
| 58 | + assert(WARN_DETAIL_REG_EXP.test(child.stderr.toString())); |
| 59 | + assert.strictEqual(child.status, 0); |
| 60 | +} |
| 61 | + |
| 62 | +setTimeout(() => runPolyfill(ticks), RETRY_TIMEOUT); |
0 commit comments