-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib: remove redundant code, add tests in timers.js
insert() is only called from one place where there is already a check that msecs is greater than or equal to zero, so do not repeat the check inside insert(). timers.active() is not documented and should not be exposed, but since it is exposed for now, let's test it. PR-URL: #3143 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
- Loading branch information
Showing
2 changed files
with
41 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const active = require('timers').active; | ||
|
||
// active() should create timers for these | ||
var legitTimers = [ | ||
{ _idleTimeout: 0 }, | ||
{ _idleTimeout: 1 } | ||
]; | ||
|
||
legitTimers.forEach(function(legit) { | ||
const savedTimeout = legit._idleTimeout; | ||
active(legit); | ||
// active() should mutate these objects | ||
assert(legit._idleTimeout === savedTimeout); | ||
assert(Number.isInteger(legit._idleStart)); | ||
assert(legit._idleNext); | ||
assert(legit._idlePrev); | ||
}); | ||
|
||
|
||
// active() should not create a timer for these | ||
var bogusTimers = [ | ||
{ _idleTimeout: -1 } | ||
]; | ||
|
||
bogusTimers.forEach(function(bogus) { | ||
const savedTimeout = bogus._idleTimeout; | ||
active(bogus); | ||
// active() should not mutate these objects | ||
assert.deepStrictEqual(bogus, {_idleTimeout: savedTimeout}); | ||
}); |