diff options
author | Roman Reiss <me@silverwind.io> | 2015-03-21 17:39:35 +0100 |
---|---|---|
committer | Roman Reiss <me@silverwind.io> | 2015-03-26 17:31:20 +0100 |
commit | caf0b36de33ad4991e3f21ed088a84c68cb0662d (patch) | |
tree | 454cf78b27bec9591c8b133e96bb066d31126cbe /test | |
parent | 2ccc8f3970cd1ed78585be37c8d912f3ccf56cd0 (diff) | |
download | node-new-caf0b36de33ad4991e3f21ed088a84c68cb0662d.tar.gz |
timers: assure setTimeout callback only runs once
Calling this.unref() during the callback of SetTimeout caused the
callback to get executed twice because unref() didn't expect to be
called during that time and did not stop the ref()ed Timeout but
did start a new timer. This commit prevents the new timer creation
when the callback was already called.
Fixes: https://github.com/iojs/io.js/issues/1191
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
PR-URL: https://github.com/iojs/io.js/pull/1231
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-timers-unref.js | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/test/parallel/test-timers-unref.js b/test/parallel/test-timers-unref.js index 9434dbbd36..2f750228a4 100644 --- a/test/parallel/test-timers-unref.js +++ b/test/parallel/test-timers-unref.js @@ -5,6 +5,7 @@ var interval_fired = false, timeout_fired = false, unref_interval = false, unref_timer = false, + unref_callbacks = 0, interval, check_unref, checks = 0; var LONG_TIME = 10 * 1000; @@ -34,6 +35,16 @@ check_unref = setInterval(function() { checks += 1; }, 100); +setTimeout(function() { + unref_callbacks++; + this.unref(); +}, SHORT_TIME); + +// Should not timeout the test +setInterval(function() { + this.unref(); +}, SHORT_TIME); + // Should not assert on args.Holder()->InternalFieldCount() > 0. See #4261. (function() { var t = setInterval(function() {}, 1); @@ -46,4 +57,5 @@ process.on('exit', function() { assert.strictEqual(timeout_fired, false, 'Timeout should not fire'); assert.strictEqual(unref_timer, true, 'An unrefd timeout should still fire'); assert.strictEqual(unref_interval, true, 'An unrefd interval should still fire'); + assert.strictEqual(unref_callbacks, 1, 'Callback should only run once'); }); |