From 8a68a80a064a7a83a114e69cc40476b098d8223a Mon Sep 17 00:00:00 2001 From: smitley Date: Wed, 14 Sep 2022 13:36:55 -0400 Subject: [PATCH] test: fix test-performance-measure Refs: https://github.com/nodejs/node/issues/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 https://github.com/nodejs/node/issues/42949 this is likely what happened. I have updated the assert.ok test to allow some variation in the test. PR-URL: https://github.com/nodejs/node/pull/44637 Reviewed-By: Luigi Pinca Reviewed-By: Akhil Marsonya Reviewed-By: Antoine du Hamel Reviewed-By: Michael Dawson --- test/parallel/test-performance-measure.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/parallel/test-performance-measure.js b/test/parallel/test-performance-measure.js index e9aaca72bdd824..949258f96e1b2d 100644 --- a/test/parallel/test-performance-measure.js +++ b/test/parallel/test-performance-measure.js @@ -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); }); }));