diff options
author | Rich Trott <rtrott@gmail.com> | 2016-03-28 17:07:22 -0700 |
---|---|---|
committer | Myles Borins <mborins@us.ibm.com> | 2016-04-11 12:45:19 -0400 |
commit | e7877e61b68edb733c51573ec20225df6b12c660 (patch) | |
tree | 333804fcd29d6f613deea3b7c779671379e34d97 | |
parent | c91f3d897a5549edd2b7c4ff82e5e78a1b071de5 (diff) | |
download | nodejs-e7877e61b68edb733c51573ec20225df6b12c660.tar.gz nodejs-e7877e61b68edb733c51573ec20225df6b12c660.tar.bz2 nodejs-e7877e61b68edb733c51573ec20225df6b12c660.zip |
test: fix flaky test-net-socket-timeout-unref
Throw immediately on socket timeout rather than checking boolean in exit
handler.
PR-URL: https://github.com/nodejs/node/pull/6003
Fixes: https://github.com/nodejs/node/issues/5128
Reviewed-By: Myles Borins <myles.borins@gmail.com>
-rw-r--r-- | test/parallel/test-net-socket-timeout-unref.js | 36 |
1 files changed, 16 insertions, 20 deletions
diff --git a/test/parallel/test-net-socket-timeout-unref.js b/test/parallel/test-net-socket-timeout-unref.js index b7ed0ec34..bbc2dffcc 100644 --- a/test/parallel/test-net-socket-timeout-unref.js +++ b/test/parallel/test-net-socket-timeout-unref.js @@ -1,39 +1,35 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var net = require('net'); -var server = net.createServer(function(c) { +// Test that unref'ed sockets with timeouts do not prevent exit. + +const common = require('../common'); +const net = require('net'); + +const server = net.createServer(function(c) { c.write('hello'); c.unref(); }); server.listen(common.PORT); server.unref(); -var timedout = false; var connections = 0; -var sockets = []; -var delays = [8, 5, 3, 6, 2, 4]; +const sockets = []; +const delays = [8, 5, 3, 6, 2, 4]; delays.forEach(function(T) { - var socket = net.createConnection(common.PORT, 'localhost'); - socket.on('connect', function() { + const socket = net.createConnection(common.PORT, 'localhost'); + socket.on('connect', common.mustCall(function() { if (++connections === delays.length) { sockets.forEach(function(s) { - s[0].setTimeout(s[1] * 1000, function() { - timedout = true; - s[0].destroy(); + s.socket.setTimeout(s.timeout, function() { + s.socket.destroy(); + throw new Error('socket timed out unexpectedly'); }); - s[0].unref(); + s.socket.unref(); }); } - }); - - sockets.push([socket, T]); -}); + })); -process.on('exit', function() { - assert.strictEqual(timedout, false, - 'Socket timeout should not hold loop open'); + sockets.push({socket: socket, timeout: T * 1000}); }); |