summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorRich Trott <rtrott@gmail.com>2015-09-30 22:18:36 -0700
committerRich Trott <rtrott@gmail.com>2015-10-06 08:28:07 -0700
commit070aac4a87a04380463da4f3730568c3bf5bf729 (patch)
treecc7da56e4d18dfc06c435808fdf0becbd9d55711 /test
parent6ad458b752e2c2818244714e499e560f6e668c87 (diff)
downloadnode-new-070aac4a87a04380463da4f3730568c3bf5bf729.tar.gz
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: https://github.com/nodejs/node/pull/3143 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/parallel/test-timers-active.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/test/parallel/test-timers-active.js b/test/parallel/test-timers-active.js
new file mode 100644
index 0000000000..9162406848
--- /dev/null
+++ b/test/parallel/test-timers-active.js
@@ -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});
+});