common.js needs to be loaded in all tests so that there is checking for variable leaks and possibly other things. However, it does not need to be assigned to a variable if nothing in common.js is referred to elsewhere in the test. The main tradeoff for this bit of code churn is that it gets the code base most of the way to being able to enable the no-unused-vars rule in eslint. (The non-tooling benefit is that it lessens cognitive load when reading tests as it is an immediate indication that none of the functions or properties in common.js will be used by the test.) PR-URL: https://github.com/nodejs/node/pull/4563 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
51 lines
1.4 KiB
JavaScript
51 lines
1.4 KiB
JavaScript
'use strict';
|
|
|
|
/*
|
|
* This test is aimed at making sure that unref timers queued with
|
|
* timers._unrefActive work correctly.
|
|
*
|
|
* Basically, it queues one timer in the unref queue, and then queues
|
|
* it again each time its timeout callback is fired until the callback
|
|
* has been called ten times.
|
|
*
|
|
* At that point, it unenrolls the unref timer so that its timeout callback
|
|
* is not fired ever again.
|
|
*
|
|
* Finally, a ref timeout is used with a delay large enough to make sure that
|
|
* all 10 timeouts had the time to expire.
|
|
*/
|
|
|
|
require('../common');
|
|
const timers = require('timers');
|
|
const assert = require('assert');
|
|
|
|
var someObject = {};
|
|
var nbTimeouts = 0;
|
|
|
|
/*
|
|
* libuv 0.10.x uses GetTickCount on Windows to implement timers, which uses
|
|
* system's timers whose resolution is between 10 and 16ms. See
|
|
* http://msdn.microsoft.com/en-us/library/windows/desktop/ms724408.aspx
|
|
* for more information. That's the lowest resolution for timers across all
|
|
* supported platforms. We're using it as the lowest common denominator,
|
|
* and thus expect 5 timers to be able to fire in under 100 ms.
|
|
*/
|
|
const N = 5;
|
|
const TEST_DURATION = 100;
|
|
|
|
timers.unenroll(someObject);
|
|
timers.enroll(someObject, 1);
|
|
|
|
someObject._onTimeout = function _onTimeout() {
|
|
++nbTimeouts;
|
|
|
|
if (nbTimeouts === N) timers.unenroll(someObject);
|
|
|
|
timers._unrefActive(someObject);
|
|
};
|
|
|
|
timers._unrefActive(someObject);
|
|
|
|
setTimeout(function() {
|
|
assert.equal(nbTimeouts, N);
|
|
}, TEST_DURATION);
|