diff options
author | Anatoli Papirovski <anatoli.papirovski@postmates.com> | 2019-01-24 23:07:25 -0800 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2019-01-25 19:02:40 -0800 |
commit | d1d357d3adcf91d1203af53a2dc9b2682246c83f (patch) | |
tree | e32436bda512e952feac07051df0aa99a06eaec2 /test/sequential | |
parent | 303585eb293e1d6aa2c13d2cf47fa7285732237f (diff) | |
download | android-node-v8-d1d357d3adcf91d1203af53a2dc9b2682246c83f.tar.gz android-node-v8-d1d357d3adcf91d1203af53a2dc9b2682246c83f.tar.bz2 android-node-v8-d1d357d3adcf91d1203af53a2dc9b2682246c83f.zip |
test: fix sequential/test-performance delay
PR-URL: https://github.com/nodejs/node/pull/25695
Fixes: https://github.com/nodejs/node/issues/23291
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Diffstat (limited to 'test/sequential')
-rw-r--r-- | test/sequential/test-performance.js | 67 |
1 files changed, 20 insertions, 47 deletions
diff --git a/test/sequential/test-performance.js b/test/sequential/test-performance.js index 72b78bea58..825cf85ef5 100644 --- a/test/sequential/test-performance.js +++ b/test/sequential/test-performance.js @@ -56,31 +56,7 @@ 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); @@ -88,10 +64,9 @@ function checkNodeTiming(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], @@ -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({ @@ -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() } }); }); |