|
| 1 | +// Copyright Joyent, Inc. and other Node contributors. |
| 2 | +// |
| 3 | +// Permission is hereby granted, free of charge, to any person obtaining a |
| 4 | +// copy of this software and associated documentation files (the |
| 5 | +// "Software"), to deal in the Software without restriction, including |
| 6 | +// without limitation the rights to use, copy, modify, merge, publish, |
| 7 | +// distribute, sublicense, and/or sell copies of the Software, and to permit |
| 8 | +// persons to whom the Software is furnished to do so, subject to the |
| 9 | +// following conditions: |
| 10 | +// |
| 11 | +// The above copyright notice and this permission notice shall be included |
| 12 | +// in all copies or substantial portions of the Software. |
| 13 | +// |
| 14 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 15 | +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 16 | +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN |
| 17 | +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| 18 | +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 19 | +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
| 20 | +// USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 21 | + |
| 22 | +/* |
| 23 | + * The goal of this test is to make sure that, after the regression introduced |
| 24 | + * by 934bfe23a16556d05bfb1844ef4d53e8c9887c3d, the fix preserves the following |
| 25 | + * behavior of unref timers: if two timers are scheduled to fire at the same |
| 26 | + * time, if one unenrolls the other one in its _onTimeout callback, the other |
| 27 | + * one will *not* fire. |
| 28 | + */ |
| 29 | +var timers = require('timers'); |
| 30 | +var assert = require('assert'); |
| 31 | + |
| 32 | +var nbTimersFired = 0; |
| 33 | + |
| 34 | +var foo = new function() { |
| 35 | + this._onTimeout = function() { |
| 36 | + ++nbTimersFired; |
| 37 | + timers.unenroll(bar); |
| 38 | + }; |
| 39 | +}(); |
| 40 | + |
| 41 | +var bar = new function() { |
| 42 | + this._onTimeout = function() { |
| 43 | + ++nbTimersFired; |
| 44 | + timers.unenroll(foo); |
| 45 | + }; |
| 46 | +}(); |
| 47 | + |
| 48 | +timers.enroll(bar, 1); |
| 49 | +timers._unrefActive(bar); |
| 50 | + |
| 51 | +timers.enroll(foo, 1); |
| 52 | +timers._unrefActive(foo); |
| 53 | + |
| 54 | +setTimeout(function() { |
| 55 | + assert.notEqual(nbTimersFired, 2); |
| 56 | +}, 20); |
0 commit comments