Skip to content

Commit 80dc417

Browse files
committed
test: fix tick-processor tests
This reduces the runtime significantly and fixes the tests to run on the CI. It is significantly more robust by accepting some fallbacks. Therefore they are moved out of pummel to sequential.
1 parent 1c7b5db commit 80dc417

12 files changed

+185
-196
lines changed

test/common/tick-processor.js

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
'use strict';
2+
3+
const {
4+
isWindows,
5+
isSunOS,
6+
isAIX,
7+
isLinuxPPCBE,
8+
isFreeBSD,
9+
skip
10+
} = require('../common');
11+
12+
const fs = require('fs');
13+
const cp = require('child_process');
14+
const path = require('path');
15+
16+
const tmpdir = require('./tmpdir');
17+
tmpdir.refresh();
18+
19+
const LOG_FILE = path.join(tmpdir.path, 'tick-processor.log');
20+
const START_PROF_PROCESS_TIMEOUT = 400;
21+
22+
let running = 0;
23+
let ran = 0;
24+
25+
// The tick processor is not supported on all platforms.
26+
function isCPPSymbolsNotMapped() {
27+
if (isWindows || isSunOS || isAIX || isLinuxPPCBE || isFreeBSD) {
28+
skip('C++ symbols are not mapped for this OS.');
29+
return true;
30+
}
31+
return false;
32+
}
33+
34+
function runTest(test) {
35+
if (isCPPSymbolsNotMapped()) {
36+
return;
37+
}
38+
39+
ran++;
40+
running = 0;
41+
const proc = cp.spawn(process.execPath, [
42+
'--no_logfile_per_isolate',
43+
'--logfile=-',
44+
'--prof',
45+
'-pe', test.code
46+
], {
47+
stdio: [ 'ignore', 'pipe', 'inherit' ]
48+
});
49+
50+
let ticks = '';
51+
proc.stdout.on('data', (chunk) => ticks += chunk);
52+
53+
// Check if the pattern is already there or not.
54+
setTimeout(() => {
55+
if (running === 0) {
56+
match(test, proc, () => ticks);
57+
}
58+
}, START_PROF_PROCESS_TIMEOUT);
59+
60+
proc.on('exit', () => {
61+
running++;
62+
if (running === 1) {
63+
match(test, proc, () => ticks);
64+
}
65+
});
66+
}
67+
68+
function match(test, parent, ticks) {
69+
running++;
70+
71+
const { pattern, profProcessFlags: flags = [] } = test;
72+
// Store current ticks log
73+
fs.writeFileSync(LOG_FILE, ticks());
74+
75+
const proc = cp.spawn(process.execPath, [
76+
'--prof-process',
77+
'--call-graph-size=10',
78+
...flags,
79+
LOG_FILE
80+
], {
81+
stdio: [ 'ignore', 'pipe', 'inherit' ]
82+
});
83+
84+
let out = '';
85+
86+
proc.stdout.on('data', (chunk) => out += chunk);
87+
proc.stdout.once('end', () => {
88+
proc.once('exit', () => {
89+
fs.unlinkSync(LOG_FILE);
90+
91+
// Retry after timeout
92+
if (!pattern.test(out)) {
93+
running--;
94+
// If the profiling is done without match, try up to ten times again
95+
// and then fail.
96+
if (running === 1) {
97+
if (ran < 10) {
98+
return runTest(test);
99+
}
100+
console.error(out);
101+
throw new Error(`${pattern} Failed`);
102+
}
103+
return;
104+
}
105+
106+
parent.stdout.removeAllListeners();
107+
parent.kill();
108+
});
109+
110+
proc.stdout.removeAllListeners();
111+
proc.kill();
112+
});
113+
}
114+
115+
module.exports = {
116+
runTest,
117+
isCPPSymbolsNotMapped
118+
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
require('../common');
3+
4+
const base = require('../common/tick-processor');
5+
6+
base.runTest({
7+
// If the C++ symbols are not detected by the OS, no JS is going to be
8+
// executed.
9+
pattern: /Builtin: ObjectKeys| \d [0-6]\.\d% [0-6]\.\d% JavaScript/,
10+
code: `let add = 0;
11+
const obj = { a: 5 };
12+
function f() {
13+
for (var i = 0; i < 4e6; i++) {
14+
obj.a = i;
15+
add += Object.keys(obj).length;
16+
}
17+
return add;
18+
};
19+
f();`
20+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
require('../common');
3+
4+
const base = require('../common/tick-processor');
5+
6+
base.runTest({
7+
// If the C++ symbols are not mapped to the OS they can end up as `UNKNOWN` or
8+
// no JS is executed at all.
9+
pattern: /MakeContext|\d\d\.\d% UNKNOWN|0 0\.0% 0\.0% JavaScript|[7-9]\d\.\d% [7-9]\d\.\d% write/,
10+
code: `function f() {
11+
for (var i = 0; i < 5e2; i++) {
12+
require('vm').createContext({});
13+
}
14+
};
15+
f();`
16+
});

test/tick-processor/test-tick-processor-polyfill-brokenfile.js renamed to test/sequential/test-tick-processor-polyfill-brokenfile.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,39 @@
11
'use strict';
2-
const common = require('../common');
3-
const { isCPPSymbolsNotMapped } = require('./util');
4-
const tmpdir = require('../common/tmpdir');
5-
tmpdir.refresh();
2+
const { skip } = require('../common');
63

7-
if (!common.enoughTestCpu)
8-
common.skip('test is CPU-intensive');
4+
const { isCPPSymbolsNotMapped } = require('../common/tick-processor');
95

106
if (isCPPSymbolsNotMapped) {
11-
common.skip('C++ symbols are not mapped for this OS.');
7+
skip('C++ symbols are not mapped for this OS.');
128
}
139

10+
const tmpdir = require('../common/tmpdir');
11+
tmpdir.refresh();
12+
1413
// This test will produce a broken profile log.
1514
// ensure prof-polyfill not stuck in infinite loop
1615
// and success process
1716

18-
1917
const assert = require('assert');
2018
const { spawn, spawnSync } = require('child_process');
2119
const path = require('path');
2220
const { writeFileSync } = require('fs');
2321

2422
const LOG_FILE = path.join(tmpdir.path, 'tick-processor.log');
25-
const RETRY_TIMEOUT = 150;
23+
const RETRY_TIMEOUT = 250;
2624
const BROKEN_PART = 'tick,';
2725
const WARN_REG_EXP = /\(node:\d+\) \[BROKEN_PROFILE_FILE] Warning: Profile file .* is broken/;
2826
const WARN_DETAIL_REG_EXP = /".*tick," at the file end is broken/;
2927

30-
const code = `function f() {
31-
this.ts = Date.now();
32-
setImmediate(function() { new f(); });
33-
};
34-
f();`;
28+
const code = `
29+
let add = 0;
30+
function f() {
31+
for (var i = 0; i < 1e3; i++) {
32+
add += Date.now();
33+
}
34+
return add;
35+
};
36+
f();`;
3537

3638
const proc = spawn(process.execPath, [
3739
'--no_logfile_per_isolate',
@@ -45,7 +47,6 @@ const proc = spawn(process.execPath, [
4547
let ticks = '';
4648
proc.stdout.on('data', (chunk) => ticks += chunk);
4749

48-
4950
function runPolyfill(content) {
5051
proc.kill();
5152
content += BROKEN_PART;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict';
2+
require('../common');
3+
4+
const base = require('../common/tick-processor');
5+
6+
base.runTest({
7+
pattern: /^{/,
8+
code: `function f() {
9+
for (var i = 0; i < 5e2; i++) {
10+
require('vm').createContext({});
11+
}
12+
};
13+
f();`,
14+
profProcessFlags: ['--preprocess']
15+
});

test/tick-processor/test-tick-processor-builtin.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

test/tick-processor/test-tick-processor-cpp-core.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

test/tick-processor/test-tick-processor-preprocess-flag.js

Lines changed: 0 additions & 22 deletions
This file was deleted.

test/tick-processor/test-tick-processor-unknown.js

Lines changed: 0 additions & 28 deletions
This file was deleted.

test/tick-processor/testcfg.py

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)