summaryrefslogtreecommitdiff
path: root/test/tick-processor/test-tick-processor-polyfill-brokenfile.js
blob: f61bdbe9a12510dec324249fd5cf006b94d4c783 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
'use strict';
const common = require('../common');
const { isCPPSymbolsNotMapped } = require('./util');
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();

if (!common.enoughTestCpu)
  common.skip('test is CPU-intensive');

if (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 { spawn, spawnSync } = require('child_process');
const path = require('path');
const { writeFileSync } = 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 = 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;
  writeFileSync(LOG_FILE, content);
  const child = 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);