| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,9 +23,6 @@ | |||
| 23 | 23 | const common = require('../common'); | |
| 24 | 24 | const assert = require('assert'); | |
| 25 | 25 | ||
| 26 | - let immediateC; | ||
| 27 | - let immediateD; | ||
| 28 | - | ||
| 29 | 26 | let mainFinished = false; | |
| 30 | 27 | ||
| 31 | 28 | setImmediate(common.mustCall(function() { | |
@@ -35,17 +32,12 @@ setImmediate(common.mustCall(function() { | |||
| 35 | 32 | ||
| 36 | 33 | const immediateB = setImmediate(common.mustNotCall()); | |
| 37 | 34 | ||
| 38 | - setImmediate(function(x, y, z) { | ||
| 39 | - immediateC = [x, y, z]; | ||
| 40 | - }, 1, 2, 3); | ||
| 41 | - | ||
| 42 | - setImmediate(function(x, y, z, a, b) { | ||
| 43 | - immediateD = [x, y, z, a, b]; | ||
| 44 | - }, 1, 2, 3, 4, 5); | ||
| 35 | + setImmediate(common.mustCall((...args) => { | ||
| 36 | + assert.deepStrictEqual(args, [1, 2, 3]); | ||
| 37 | + }), 1, 2, 3); | ||
| 45 | 38 | ||
| 46 | - process.on('exit', function() { | ||
| 47 | - assert.deepStrictEqual(immediateC, [1, 2, 3], 'immediateC args should match'); | ||
| 48 | - assert.deepStrictEqual(immediateD, [1, 2, 3, 4, 5], '5 args should match'); | ||
| 49 | - }); | ||
| 39 | + setImmediate(common.mustCall((...args) => { | ||
| 40 | + assert.deepStrictEqual(args, [1, 2, 3, 4, 5]); | ||
| 41 | + }), 1, 2, 3, 4, 5); | ||
| 50 | 42 | ||
| 51 | 43 | mainFinished = true; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,7 +20,7 @@ | |||
| 20 | 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. | |
| 21 | 21 | ||
| 22 | 22 | 'use strict'; | |
| 23 | - require('../common'); | ||
| 23 | + const common = require('../common'); | ||
| 24 | 24 | ||
| 25 | 25 | /* | |
| 26 | 26 | * This test makes sure that non-integer timer delays do not make the process | |
@@ -39,13 +39,11 @@ require('../common'); | |||
| 39 | 39 | */ | |
| 40 | 40 | ||
| 41 | 41 | const TIMEOUT_DELAY = 1.1; | |
| 42 | - const NB_TIMEOUTS_FIRED = 50; | ||
| 42 | + let N = 50; | ||
| 43 | 43 | ||
| 44 | - let nbTimeoutFired = 0; | ||
| 45 | - const interval = setInterval(function() { | ||
| 46 | - ++nbTimeoutFired; | ||
| 47 | - if (nbTimeoutFired === NB_TIMEOUTS_FIRED) { | ||
| 44 | + const interval = setInterval(common.mustCall(() => { | ||
| 45 | + if (--N === 0) { | ||
| 48 | 46 | clearInterval(interval); | |
| 49 | 47 | process.exit(0); | |
| 50 | 48 | } | |
| 51 | - }, TIMEOUT_DELAY); | ||
| 49 | + }, N), TIMEOUT_DELAY); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,6 +6,7 @@ | |||
| 6 | 6 | ||
| 7 | 7 | const common = require('../common'); | |
| 8 | 8 | const net = require('net'); | |
| 9 | + const Countdown = require('../common/countdown'); | ||
| 9 | 10 | ||
| 10 | 11 | const clients = []; | |
| 11 | 12 | ||
@@ -19,7 +20,7 @@ const server = net.createServer(function onClient(client) { | |||
| 19 | 20 | * the list of unref timers when traversing it, and exposes the | |
| 20 | 21 | * original issue in joyent/node#8897. | |
| 21 | 22 | */ | |
| 22 | - clients[0].setTimeout(1, function onTimeout() { | ||
| 23 | + clients[0].setTimeout(1, () => { | ||
| 23 | 24 | clients[1].setTimeout(0); | |
| 24 | 25 | clients[0].end(); | |
| 25 | 26 | clients[1].end(); | |
@@ -31,19 +32,16 @@ const server = net.createServer(function onClient(client) { | |||
| 31 | 32 | } | |
| 32 | 33 | }); | |
| 33 | 34 | ||
| 34 | - server.listen(0, common.localhostIPv4, function() { | ||
| 35 | - let nbClientsEnded = 0; | ||
| 35 | + server.listen(0, common.localhostIPv4, common.mustCall(() => { | ||
| 36 | + const countdown = new Countdown(2, common.mustCall(() => server.close())); | ||
| 36 | 37 | ||
| 37 | - function addEndedClient(client) { | ||
| 38 | - ++nbClientsEnded; | ||
| 39 | - if (nbClientsEnded === 2) { | ||
| 40 | - server.close(); | ||
| 41 | - } | ||
| 38 | + { | ||
| 39 | + const client = net.connect({ port: server.address().port }); | ||
| 40 | + client.on('end', () => countdown.dec()); | ||
| 42 | 41 | } | |
| 43 | 42 | ||
| 44 | - const client1 = net.connect({ port: this.address().port }); | ||
| 45 | - client1.on('end', addEndedClient); | ||
| 46 | - | ||
| 47 | - const client2 = net.connect({ port: this.address().port }); | ||
| 48 | - client2.on('end', addEndedClient); | ||
| 49 | - }); | ||
| 43 | + { | ||
| 44 | + const client = net.connect({ port: server.address().port }); | ||
| 45 | + client.on('end', () => countdown.dec()); | ||
| 46 | + } | ||
| 47 | + })); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,27 +1,14 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | - require('../common'); | ||
| 3 | - const assert = require('assert'); | ||
| 2 | + const common = require('../common'); | ||
| 4 | 3 | ||
| 5 | - let called = 0; | ||
| 6 | - let closed = 0; | ||
| 7 | - | ||
| 8 | - const timeout = setTimeout(function() { | ||
| 9 | - called++; | ||
| 10 | - }, 10); | ||
| 4 | + const timeout = setTimeout(common.mustCall(), 10); | ||
| 11 | 5 | timeout.unref(); | |
| 12 | 6 | ||
| 13 | 7 | // Wrap `close` method to check if the handle was closed | |
| 14 | 8 | const close = timeout._handle.close; | |
| 15 | - timeout._handle.close = function() { | ||
| 16 | - closed++; | ||
| 9 | + timeout._handle.close = common.mustCall(function() { | ||
| 17 | 10 | return close.apply(this, arguments); | |
| 18 | - }; | ||
| 11 | + }); | ||
| 19 | 12 | ||
| 20 | 13 | // Just to keep process alive and let previous timer's handle die | |
| 21 | - setTimeout(function() { | ||
| 22 | - }, 50); | ||
| 23 | - | ||
| 24 | - process.on('exit', function() { | ||
| 25 | - assert.strictEqual(called, 1); | ||
| 26 | - assert.strictEqual(closed, 1); | ||
| 27 | - }); | ||
| 14 | + setTimeout(() => {}, 50); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,77 +21,59 @@ | |||
| 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 | - }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,23 +5,20 @@ | |||
| 5 | 5 | const common = require('../common'); | |
| 6 | 6 | ||
| 7 | 7 | const TEST_DURATION = common.platformTimeout(1000); | |
| 8 | - const N = 3; | ||
| 9 | - let nbIntervalFired = 0; | ||
| 8 | + let N = 3; | ||
| 10 | 9 | ||
| 11 | - const keepOpen = setTimeout(() => { | ||
| 12 | - console.error('[FAIL] Interval fired %d/%d times.', nbIntervalFired, N); | ||
| 13 | - throw new Error('Test timed out. keepOpen was not canceled.'); | ||
| 14 | - }, TEST_DURATION); | ||
| 10 | + const keepOpen = | ||
| 11 | + setTimeout( | ||
| 12 | + common.mustNotCall('Test timed out. keepOpen was not canceled.'), | ||
| 13 | + TEST_DURATION); | ||
| 15 | 14 | ||
| 16 | - const timer = setInterval(() => { | ||
| 17 | - ++nbIntervalFired; | ||
| 18 | - if (nbIntervalFired === N) { | ||
| 15 | + const timer = setInterval(common.mustCall(() => { | ||
| 16 | + if (--N === 0) { | ||
| 19 | 17 | clearInterval(timer); | |
| 20 | - timer._onTimeout = () => { | ||
| 21 | - throw new Error('Unrefd interval fired after being cleared.'); | ||
| 22 | - }; | ||
| 18 | + timer._onTimeout = | ||
| 19 | + common.mustNotCall('Unrefd interal fired after being cleared'); | ||
| 23 | 20 | clearTimeout(keepOpen); | |
| 24 | 21 | } | |
| 25 | - }, 1); | ||
| 22 | + }, N), 1); | ||
| 26 | 23 | ||
| 27 | 24 | timer.unref(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,20 +1,7 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | ||
| 3 | - require('../common'); | ||
| 4 | - const assert = require('assert'); | ||
| 3 | + const common = require('../common'); | ||
| 5 | 4 | ||
| 6 | - let once = 0; | ||
| 7 | - | ||
| 8 | - process.on('beforeExit', () => { | ||
| 9 | - if (once > 1) | ||
| 10 | - throw new RangeError('beforeExit should only have been called once!'); | ||
| 11 | - | ||
| 12 | - setTimeout(() => {}, 1).unref(); | ||
| 13 | - once++; | ||
| 14 | - }); | ||
| 15 | - | ||
| 16 | - process.on('exit', (code) => { | ||
| 17 | - if (code !== 0) return; | ||
| 18 | - | ||
| 19 | - assert.strictEqual(once, 1); | ||
| 20 | - }); | ||
| 5 | + process.on('beforeExit', common.mustCall(() => { | ||
| 6 | + setTimeout(common.mustNotCall(), 1).unref(); | ||
| 7 | + })); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,18 +36,14 @@ const assert = require('assert'); | |||
| 36 | 36 | } | |
| 37 | 37 | ||
| 38 | 38 | { | |
| 39 | - let ncalled = 0; | ||
| 39 | + let ncalled = 3; | ||
| 40 | 40 | ||
| 41 | - const iv = setInterval(f, 0, 'foo', 'bar', 'baz'); | ||
| 42 | - | ||
| 43 | - function f(a, b, c) { | ||
| 41 | + const f = common.mustCall((a, b, c) => { | ||
| 44 | 42 | assert.strictEqual(a, 'foo'); | |
| 45 | 43 | assert.strictEqual(b, 'bar'); | |
| 46 | 44 | assert.strictEqual(c, 'baz'); | |
| 47 | - if (++ncalled === 3) clearTimeout(iv); | ||
| 48 | - } | ||
| 45 | + if (--ncalled === 0) clearTimeout(iv); | ||
| 46 | + }, ncalled); | ||
| 49 | 47 | ||
| 50 | - process.on('exit', function() { | ||
| 51 | - assert.strictEqual(ncalled, 3); | ||
| 52 | - }); | ||
| 48 | + const iv = setInterval(f, 0, 'foo', 'bar', 'baz'); | ||
| 53 | 49 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments