Skip to content

Commit acfb29c

Browse files
BridgeARtargos
authored andcommitted
test: harden sequential/test-performance
1) This adds a better error logging so we are able to address further failures easier. 2) It adds a extra epsilon so the test runs into less issues in case the machine is under heavy load. 3) The epsilon in increased if the CPU is under heavy load. 4) The total startup epsilon was reduced due to recent startup time improvements. PR-URL: #22404 Fixes: #19197 Refs: nodejs/reliability#14 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
1 parent 38b0c1f commit acfb29c

File tree

1 file changed

+51
-18
lines changed

1 file changed

+51
-18
lines changed

test/sequential/test-performance.js

+51-18
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ assert(performance);
1111
assert(performance.nodeTiming);
1212
assert.strictEqual(typeof performance.timeOrigin, 'number');
1313
// Use a fairly large epsilon value, since we can only guarantee that the node
14-
// process started up in 20 seconds.
15-
assert(Math.abs(performance.timeOrigin - Date.now()) < 20000);
14+
// process started up in 15 seconds.
15+
assert(Math.abs(performance.timeOrigin - Date.now()) < 15000);
1616

1717
const inited = performance.now();
18-
assert(inited < 20000);
18+
assert(inited < 15000);
1919

2020
{
2121
// Should work without throwing any errors
@@ -56,12 +56,43 @@ assert(inited < 20000);
5656
assert.strictEqual(performance.nodeTiming.name, 'node');
5757
assert.strictEqual(performance.nodeTiming.entryType, 'node');
5858

59+
let timeoutDelay = 111; // An extra of 111 ms for the first call.
60+
61+
function checkDelay(cb) {
62+
const defaultTimeout = 1;
63+
const timer = setInterval(checkDelay, defaultTimeout);
64+
const timeouts = 10;
65+
66+
const now = getTime();
67+
let resolved = 0;
68+
69+
function checkDelay() {
70+
resolved++;
71+
if (resolved === timeouts) {
72+
clearInterval(timer);
73+
timeoutDelay = getTime() - now;
74+
cb();
75+
}
76+
}
77+
}
78+
79+
function getTime() {
80+
const ts = process.hrtime();
81+
return Math.ceil((ts[0] * 1e3) + (ts[1] / 1e6));
82+
}
83+
5984
function checkNodeTiming(props) {
85+
console.log(props);
86+
6087
for (const prop of Object.keys(props)) {
6188
if (props[prop].around !== undefined) {
6289
assert.strictEqual(typeof performance.nodeTiming[prop], 'number');
6390
const delta = performance.nodeTiming[prop] - props[prop].around;
64-
assert(Math.abs(delta) < 1000);
91+
const delay = 1000 + timeoutDelay;
92+
assert(
93+
Math.abs(delta) < delay,
94+
`${prop}: ${Math.abs(delta)} >= ${delay}`
95+
);
6596
} else {
6697
assert.strictEqual(performance.nodeTiming[prop], props[prop],
6798
`mismatch for performance property ${prop}: ` +
@@ -83,20 +114,22 @@ checkNodeTiming({
83114
loopExit: -1
84115
});
85116

86-
setTimeout(() => {
87-
checkNodeTiming({
88-
name: 'node',
89-
entryType: 'node',
90-
startTime: 0,
91-
duration: { around: performance.now() },
92-
nodeStart: { around: 0 },
93-
v8Start: { around: 0 },
94-
bootstrapComplete: { around: inited },
95-
environment: { around: 0 },
96-
loopStart: { around: inited },
97-
loopExit: -1
98-
});
99-
}, 2000);
117+
checkDelay(() => {
118+
setTimeout(() => {
119+
checkNodeTiming({
120+
name: 'node',
121+
entryType: 'node',
122+
startTime: 0,
123+
duration: { around: performance.now() },
124+
nodeStart: { around: 0 },
125+
v8Start: { around: 0 },
126+
bootstrapComplete: { around: inited },
127+
environment: { around: 0 },
128+
loopStart: { around: inited },
129+
loopExit: -1
130+
});
131+
}, 1000);
132+
});
100133

101134
process.on('exit', () => {
102135
checkNodeTiming({

0 commit comments

Comments
 (0)