0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-timers-unref-remove-other-unref-timers-only-one-fires.js
Gibson Fahnestock 7a0e462f9f test: use eslint to fix var->const/let
Manually fix issues that eslint --fix couldn't do automatically.

PR-URL: https://github.com/nodejs/node/pull/10685
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
2017-01-11 11:43:52 +00:00

42 lines
947 B
JavaScript

'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.
*/
require('../common');
const timers = require('timers');
const assert = require('assert');
let nbTimersFired = 0;
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() {
assert.notStrictEqual(nbTimersFired, 2);
}, 20);