tools: fix flakiness in test-tick-processor · nodejs/node@519caba

@@ -6,32 +6,48 @@ var cp = require('child_process');

66

var common = require('../common');

7788

common.refreshTmpDir();

9-109

process.chdir(common.tmpDir);

11-

cp.execFileSync(process.execPath, ['-prof', '-pe',

12-

'function foo(n) {' +

13-

'require(\'vm\').runInDebugContext(\'Debug\');' +

14-

'return n < 2 ? n : setImmediate(function() { foo(n-1) + foo(n-2);}); };' +

15-

'setTimeout(function() { process.exit(0); }, 2000);' +

16-

'foo(40);']);

17-

var matches = fs.readdirSync(common.tmpDir).filter(function(file) {

18-

return /^isolate-/.test(file);

19-

});

20-

if (matches.length != 1) {

21-

assert.fail('There should be a single log file.');

22-

}

23-

var log = matches[0];

2410

var processor =

2511

path.join(common.testDir, '..', 'tools', 'v8-prof', getScriptName());

26-

var out = cp.execSync(processor + ' ' + log, {encoding: 'utf8'});

27-

assert(out.match(/LazyCompile.*foo/));

12+

// Unknown checked for to prevent flakiness, if pattern is not found,

13+

// then a large number of unknown ticks should be present

14+

runTest(/LazyCompile.*\[eval\]:1|.*% UNKNOWN/,

15+

`function f() {

16+

for (var i = 0; i < 1000000; i++) {

17+

i++;

18+

}

19+

setImmediate(function() { f(); });

20+

};

21+

setTimeout(function() { process.exit(0); }, 2000);

22+

f();`);

2823

if (process.platform === 'win32' ||

2924

process.platform === 'sunos' ||

3025

process.platform === 'freebsd') {

3126

console.log('1..0 # Skipped: C++ symbols are not mapped for this os.');

3227

return;

3328

}

34-

assert(out.match(/RunInDebugContext/));

29+

runTest(/RunInDebugContext/,

30+

`function f() {

31+

require(\'vm\').runInDebugContext(\'Debug\');

32+

setImmediate(function() { f(); });

33+

};

34+

setTimeout(function() { process.exit(0); }, 2000);

35+

f();`);

36+37+

function runTest(pattern, code) {

38+

cp.execFileSync(process.execPath, ['-prof', '-pe', code]);

39+

var matches = fs.readdirSync(common.tmpDir).filter(function(file) {

40+

return /^isolate-/.test(file);

41+

});

42+

if (matches.length != 1) {

43+

assert.fail('There should be a single log file.');

44+

}

45+

var log = matches[0];

46+

var out = cp.execSync(processor + ' --call-graph-size=10 ' + log,

47+

{encoding: 'utf8'});

48+

assert(out.match(pattern));

49+

fs.unlinkSync(log);

50+

}

35513652

function getScriptName() {

3753

switch (process.platform) {