Skip to content

Commit cacefac

Browse files
committed
test: use libuv clock for immediate queue test
Use getLibuvNow() when waiting for the timeout to expire. Date.now() may have different precision from libuv's clock, causing the immediate queue to run an extra iteration on platforms with coarse timers. Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com> Assisted-by: codex:gpt-5.6-sol
1 parent 8a1ca0f commit cacefac

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

test/parallel/test-timers-immediate-queue.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@
1919
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
2020
// USE OR OTHER DEALINGS IN THE SOFTWARE.
2121

22+
// Flags: --expose-internals --no-warnings
23+
2224
'use strict';
2325
require('../common');
2426
const assert = require('assert');
27+
const { internalBinding } = require('internal/test/binding');
28+
const timersBinding = internalBinding('timers');
2529

2630
// setImmediate should run clear its queued cbs once per event loop turn
2731
// but immediates queued while processing the current queue should happen
@@ -38,8 +42,8 @@ const QUEUE = 10;
3842
function run() {
3943
if (hit === 0) {
4044
setTimeout(() => { ticked = true; }, 1);
41-
const now = Date.now();
42-
while (Date.now() - now < 2);
45+
const now = timersBinding.getLibuvNow();
46+
while (timersBinding.getLibuvNow() - now < 2);
4347
}
4448

4549
if (ticked) return;

0 commit comments

Comments
 (0)