0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-28 06:28:40 +01:00
nodejs/test/sequential/test-timers-set-interval-excludes-callback-duration.js
cjihrig aa363c49ea
test: remove common.busyLoop()
This commit replaces common.busyLoop() with sleep().

PR-URL: https://github.com/nodejs/node/pull/30787
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
2019-12-06 22:03:00 -05:00

26 lines
577 B
JavaScript

// Flags: --expose-internals
'use strict';
require('../common');
const assert = require('assert');
const { sleep } = require('internal/util');
let cntr = 0;
let first;
const t = setInterval(() => {
cntr++;
if (cntr === 1) {
sleep(100);
// Ensure that the event loop passes before the second interval
setImmediate(() => assert.strictEqual(cntr, 1));
first = Date.now();
} else if (cntr === 2) {
assert(Date.now() - first < 100);
clearInterval(t);
}
}, 100);
const t2 = setInterval(() => {
if (cntr === 2) {
clearInterval(t2);
}
}, 100);