• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3
4// The goal of this test is to make sure that, after the regression introduced
5// by 934bfe23a16556d05bfb1844ef4d53e8c9887c3d, the fix preserves the following
6// behavior of unref timers: if two timers are scheduled to fire at the same
7// time, if one unenrolls the other one in its _onTimeout callback, the other
8// one will *not* fire.
9
10// This behavior is a private implementation detail and should not be
11// considered public interface.
12
13require('../common');
14const timers = require('timers');
15const assert = require('assert');
16
17let nbTimersFired = 0;
18
19const foo = {
20  _onTimeout: function() {
21    ++nbTimersFired;
22    timers.unenroll(bar);
23  }
24};
25
26const bar = {
27  _onTimeout: function() {
28    ++nbTimersFired;
29    timers.unenroll(foo);
30  }
31};
32
33timers.enroll(bar, 1);
34timers._unrefActive(bar);
35
36timers.enroll(foo, 1);
37timers._unrefActive(foo);
38
39setTimeout(function() {
40  assert.notStrictEqual(nbTimersFired, 2);
41}, 20);
42