|
21 | 21 |
|
22 | 22 | 'use strict';
|
23 | 23 |
|
24 |
| -require('../common'); |
| 24 | +const common = require('../common'); |
25 | 25 | const assert = require('assert');
|
26 | 26 |
|
27 |
| -let interval_fired = false; |
28 |
| -let timeout_fired = false; |
29 | 27 | let unref_interval = false;
|
30 | 28 | let unref_timer = false;
|
31 |
| -let unref_callbacks = 0; |
32 | 29 | let checks = 0;
|
33 | 30 |
|
34 | 31 | const LONG_TIME = 10 * 1000;
|
35 | 32 | const SHORT_TIME = 100;
|
36 | 33 |
|
37 |
| -assert.doesNotThrow(function() { |
| 34 | +assert.doesNotThrow(() => { |
38 | 35 | setTimeout(() => {}, 10).unref().ref().unref();
|
39 | 36 | }, 'ref and unref are chainable');
|
40 | 37 |
|
41 |
| -assert.doesNotThrow(function() { |
| 38 | +assert.doesNotThrow(() => { |
42 | 39 | setInterval(() => {}, 10).unref().ref().unref();
|
43 | 40 | }, 'ref and unref are chainable');
|
44 | 41 |
|
45 |
| -setInterval(function() { |
46 |
| - interval_fired = true; |
47 |
| -}, LONG_TIME).unref(); |
| 42 | +setInterval(common.mustNotCall('Interval should not fire'), LONG_TIME).unref(); |
| 43 | +setTimeout(common.mustNotCall('Timer should not fire'), LONG_TIME).unref(); |
48 | 44 |
|
49 |
| -setTimeout(function() { |
50 |
| - timeout_fired = true; |
51 |
| -}, LONG_TIME).unref(); |
52 |
| - |
53 |
| -const interval = setInterval(function() { |
| 45 | +const interval = setInterval(common.mustCall(() => { |
54 | 46 | unref_interval = true;
|
55 | 47 | clearInterval(interval);
|
56 |
| -}, SHORT_TIME); |
| 48 | +}), SHORT_TIME); |
57 | 49 | interval.unref();
|
58 | 50 |
|
59 |
| -setTimeout(function() { |
| 51 | +setTimeout(common.mustCall(() => { |
60 | 52 | unref_timer = true;
|
61 |
| -}, SHORT_TIME).unref(); |
| 53 | +}), SHORT_TIME).unref(); |
62 | 54 |
|
63 |
| -const check_unref = setInterval(function() { |
| 55 | +const check_unref = setInterval(() => { |
64 | 56 | if (checks > 5 || (unref_interval && unref_timer))
|
65 | 57 | clearInterval(check_unref);
|
66 | 58 | checks += 1;
|
67 | 59 | }, 100);
|
68 | 60 |
|
69 |
| -setTimeout(function() { |
70 |
| - unref_callbacks++; |
71 |
| - this.unref(); |
72 |
| -}, SHORT_TIME); |
| 61 | +{ |
| 62 | + const timeout = |
| 63 | + setTimeout(common.mustCall(() => { |
| 64 | + timeout.unref(); |
| 65 | + }), SHORT_TIME); |
| 66 | +} |
73 | 67 |
|
74 |
| -// Should not timeout the test |
75 |
| -setInterval(function() { |
76 |
| - this.unref(); |
77 |
| -}, SHORT_TIME); |
| 68 | +{ |
| 69 | + // Should not timeout the test |
| 70 | + const timeout = |
| 71 | + setInterval(() => timeout.unref(), SHORT_TIME); |
| 72 | +} |
78 | 73 |
|
79 | 74 | // Should not assert on args.Holder()->InternalFieldCount() > 0. See #4261.
|
80 | 75 | {
|
81 | 76 | const t = setInterval(() => {}, 1);
|
82 | 77 | process.nextTick(t.unref.bind({}));
|
83 | 78 | process.nextTick(t.unref.bind(t));
|
84 | 79 | }
|
85 |
| - |
86 |
| -process.on('exit', function() { |
87 |
| - assert.strictEqual(interval_fired, false, |
88 |
| - 'Interval should not fire'); |
89 |
| - assert.strictEqual(timeout_fired, false, |
90 |
| - 'Timeout should not fire'); |
91 |
| - assert.strictEqual(unref_timer, true, |
92 |
| - 'An unrefd timeout should still fire'); |
93 |
| - assert.strictEqual(unref_interval, true, |
94 |
| - 'An unrefd interval should still fire'); |
95 |
| - assert.strictEqual(unref_callbacks, 1, |
96 |
| - 'Callback should only run once'); |
97 |
| -}); |
0 commit comments