Skip to content

Commit

Permalink
test: fix test-performance-measure
Browse files Browse the repository at this point in the history
Refs: nodejs/node#42949

Looking at the documentation for setTimeout
(https://nodejs.org/api/timers.html#settimeoutcallback-delay-args)
there is no guarantee that setTimeout won't complete early.

From the failure of nodejs/node#42949 this
is likely what happened.

I have updated the assert.ok test to allow some variation in
the test.

PR-URL: nodejs/node#44637
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Akhil Marsonya <akhil.marsonya27@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
  • Loading branch information
smitley authored and guangwong committed Jan 3, 2023
1 parent 3e1ebf1 commit 4c626d1
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion test/parallel/test-performance-measure.js
Expand Up @@ -5,11 +5,12 @@ const assert = require('assert');

const { PerformanceObserver, performance } = require('perf_hooks');
const DELAY = 1000;
const ALLOWED_MARGIN = 10;

const expected = ['Start to Now', 'A to Now', 'A to B'];
const obs = new PerformanceObserver(common.mustCall((items) => {
items.getEntries().forEach(({ name, duration }) => {
assert.ok(duration > DELAY);
assert.ok(duration > (DELAY - ALLOWED_MARGIN));
assert.strictEqual(expected.shift(), name);
});
}));
Expand Down

0 comments on commit 4c626d1

Please sign in to comment.