mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
0928897798
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 <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>
27 lines
752 B
JavaScript
27 lines
752 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
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 - ALLOWED_MARGIN));
|
|
assert.strictEqual(expected.shift(), name);
|
|
});
|
|
}));
|
|
obs.observe({ entryTypes: ['measure'] });
|
|
|
|
performance.mark('A');
|
|
setTimeout(common.mustCall(() => {
|
|
performance.measure('Start to Now');
|
|
performance.measure('A to Now', 'A');
|
|
|
|
performance.mark('B');
|
|
performance.measure('A to B', 'A', 'B');
|
|
}), DELAY);
|