2014-12-19 00:36:21 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The goal of this test is to make sure that, after the regression introduced
|
|
|
|
* by 934bfe23a16556d05bfb1844ef4d53e8c9887c3d, the fix preserves the following
|
|
|
|
* behavior of unref timers: if two timers are scheduled to fire at the same
|
|
|
|
* time, if one unenrolls the other one in its _onTimeout callback, the other
|
|
|
|
* one will *not* fire.
|
|
|
|
*
|
|
|
|
* This behavior is a private implementation detail and should not be
|
|
|
|
* considered public interface.
|
|
|
|
*/
|
2015-12-24 01:02:12 +01:00
|
|
|
require('../common');
|
2014-12-19 00:36:21 +01:00
|
|
|
const timers = require('timers');
|
|
|
|
const assert = require('assert');
|
|
|
|
|
2017-01-08 14:19:00 +01:00
|
|
|
let nbTimersFired = 0;
|
2014-12-19 00:36:21 +01:00
|
|
|
|
|
|
|
const foo = {
|
|
|
|
_onTimeout: function() {
|
|
|
|
++nbTimersFired;
|
|
|
|
timers.unenroll(bar);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const bar = {
|
|
|
|
_onTimeout: function() {
|
|
|
|
++nbTimersFired;
|
|
|
|
timers.unenroll(foo);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
timers.enroll(bar, 1);
|
|
|
|
timers._unrefActive(bar);
|
|
|
|
|
|
|
|
timers.enroll(foo, 1);
|
|
|
|
timers._unrefActive(foo);
|
|
|
|
|
|
|
|
setTimeout(function() {
|
2016-12-30 16:09:13 +01:00
|
|
|
assert.notStrictEqual(nbTimersFired, 2);
|
2014-12-19 00:36:21 +01:00
|
|
|
}, 20);
|