diff options
author | James M Snell <jasnell@gmail.com> | 2017-08-03 18:08:11 -0700 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2017-08-07 17:33:59 -0700 |
commit | 7192e913f703c96eddff697c4ba0daef87930776 (patch) | |
tree | bd9083ff6c7d1062285c80695b8b817af5b0c5bd /test/parallel/test-timers-socket-timeout-removes-other-socket-unref-timer.js | |
parent | af70c3b4781d8df928d183580b8075cd566ce0b5 (diff) | |
download | android-node-v8-7192e913f703c96eddff697c4ba0daef87930776.tar.gz android-node-v8-7192e913f703c96eddff697c4ba0daef87930776.tar.bz2 android-node-v8-7192e913f703c96eddff697c4ba0daef87930776.zip |
test: improve multiple timers tests
PR-URL: https://github.com/nodejs/node/pull/14616
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Diffstat (limited to 'test/parallel/test-timers-socket-timeout-removes-other-socket-unref-timer.js')
-rw-r--r-- | test/parallel/test-timers-socket-timeout-removes-other-socket-unref-timer.js | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/test/parallel/test-timers-socket-timeout-removes-other-socket-unref-timer.js b/test/parallel/test-timers-socket-timeout-removes-other-socket-unref-timer.js index 5d57bbaae0..842c818070 100644 --- a/test/parallel/test-timers-socket-timeout-removes-other-socket-unref-timer.js +++ b/test/parallel/test-timers-socket-timeout-removes-other-socket-unref-timer.js @@ -6,6 +6,7 @@ const common = require('../common'); const net = require('net'); +const Countdown = require('../common/countdown'); const clients = []; @@ -19,7 +20,7 @@ const server = net.createServer(function onClient(client) { * the list of unref timers when traversing it, and exposes the * original issue in joyent/node#8897. */ - clients[0].setTimeout(1, function onTimeout() { + clients[0].setTimeout(1, () => { clients[1].setTimeout(0); clients[0].end(); clients[1].end(); @@ -31,19 +32,16 @@ const server = net.createServer(function onClient(client) { } }); -server.listen(0, common.localhostIPv4, function() { - let nbClientsEnded = 0; +server.listen(0, common.localhostIPv4, common.mustCall(() => { + const countdown = new Countdown(2, common.mustCall(() => server.close())); - function addEndedClient(client) { - ++nbClientsEnded; - if (nbClientsEnded === 2) { - server.close(); - } + { + const client = net.connect({ port: server.address().port }); + client.on('end', () => countdown.dec()); } - const client1 = net.connect({ port: this.address().port }); - client1.on('end', addEndedClient); - - const client2 = net.connect({ port: this.address().port }); - client2.on('end', addEndedClient); -}); + { + const client = net.connect({ port: server.address().port }); + client.on('end', () => countdown.dec()); + } +})); |