Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix sequential/test-performance delay #25695

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 20 additions & 47 deletions test/sequential/test-performance.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,42 +56,17 @@ assert(inited < 15000);
assert.strictEqual(performance.nodeTiming.name, 'node');
assert.strictEqual(performance.nodeTiming.entryType, 'node');

let timeoutDelay = 111; // An extra of 111 ms for the first call.

function checkDelay(cb) {
const defaultTimeout = 1;
const timer = setInterval(checkDelay, defaultTimeout);
const timeouts = 10;

const now = getTime();
let resolved = 0;

function checkDelay() {
resolved++;
if (resolved === timeouts) {
clearInterval(timer);
timeoutDelay = getTime() - now;
cb();
}
}
}

function getTime() {
const ts = process.hrtime();
return Math.ceil((ts[0] * 1e3) + (ts[1] / 1e6));
}

const delay = 250;
function checkNodeTiming(props) {
console.log(props);

for (const prop of Object.keys(props)) {
if (props[prop].around !== undefined) {
assert.strictEqual(typeof performance.nodeTiming[prop], 'number');
const delta = performance.nodeTiming[prop] - props[prop].around;
const delay = 1000 + timeoutDelay;
assert(
Math.abs(delta) < delay,
`${prop}: ${Math.abs(delta)} >= ${delay}`
Math.abs(delta) < (props[prop].delay || delay),
`${prop}: ${Math.abs(delta)} >= ${props[prop].delay || delay}`
);
} else {
assert.strictEqual(performance.nodeTiming[prop], props[prop],
Expand All @@ -108,28 +83,26 @@ checkNodeTiming({
duration: { around: performance.now() },
nodeStart: { around: 0 },
v8Start: { around: 0 },
bootstrapComplete: { around: inited },
bootstrapComplete: { around: inited, delay: 2500 },
environment: { around: 0 },
loopStart: -1,
loopExit: -1
});

checkDelay(() => {
setTimeout(() => {
checkNodeTiming({
name: 'node',
entryType: 'node',
startTime: 0,
duration: { around: performance.now() },
nodeStart: { around: 0 },
v8Start: { around: 0 },
bootstrapComplete: { around: inited },
environment: { around: 0 },
loopStart: { around: inited },
loopExit: -1
});
}, 1000);
});
setTimeout(() => {
checkNodeTiming({
name: 'node',
entryType: 'node',
startTime: 0,
duration: { around: performance.now() },
nodeStart: { around: 0 },
v8Start: { around: 0 },
bootstrapComplete: { around: inited, delay: 2500 },
environment: { around: 0 },
loopStart: { around: inited, delay: 2500 },
loopExit: -1
});
}, 1000);

process.on('exit', () => {
checkNodeTiming({
Expand All @@ -139,9 +112,9 @@ process.on('exit', () => {
duration: { around: performance.now() },
nodeStart: { around: 0 },
v8Start: { around: 0 },
bootstrapComplete: { around: inited },
bootstrapComplete: { around: inited, delay: 2500 },
environment: { around: 0 },
loopStart: { around: inited },
loopStart: { around: inited, delay: 2500 },
loopExit: { around: performance.now() }
});
});