summaryrefslogtreecommitdiff
path: root/test/parallel/test-socket-write-after-fin.js
diff options
context:
space:
mode:
authorBrian White <mscdex@mscdex.net>2016-05-29 03:06:56 -0400
committerEvan Lucas <evanlucas@me.com>2016-06-15 18:12:31 -0500
commiteded11705b30b8e07df3f17af2661ebf0fc8ec6b (patch)
treef435a43645c4095a92add479a6b31e7621836e26 /test/parallel/test-socket-write-after-fin.js
parent27ed7fc56c24cac8bc2622a39e8902a888d984e5 (diff)
downloadnode-new-eded11705b30b8e07df3f17af2661ebf0fc8ec6b.tar.gz
test: use random ports where possible
This helps to prevent issues where a failed test can keep a bound socket open long enough to cause other tests to fail with EADDRINUSE because the same port number is used. PR-URL: https://github.com/nodejs/node/pull/7045 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Rod Vagg <rod@vagg.org>
Diffstat (limited to 'test/parallel/test-socket-write-after-fin.js')
-rw-r--r--test/parallel/test-socket-write-after-fin.js42
1 files changed, 21 insertions, 21 deletions
diff --git a/test/parallel/test-socket-write-after-fin.js b/test/parallel/test-socket-write-after-fin.js
index ea8ac27b59..f7e3d5fe4e 100644
--- a/test/parallel/test-socket-write-after-fin.js
+++ b/test/parallel/test-socket-write-after-fin.js
@@ -1,5 +1,5 @@
'use strict';
-var common = require('../common');
+require('../common');
var assert = require('assert');
var net = require('net');
var serverData = '';
@@ -18,27 +18,27 @@ var server = net.createServer({ allowHalfOpen: true }, function(sock) {
server.close();
});
});
-server.listen(common.PORT);
+server.listen(0, function() {
+ var sock = net.connect(this.address().port);
+ sock.setEncoding('utf8');
+ sock.on('data', function(c) {
+ clientData += c;
+ });
-var sock = net.connect(common.PORT);
-sock.setEncoding('utf8');
-sock.on('data', function(c) {
- clientData += c;
-});
+ sock.on('end', function() {
+ gotClientEnd = true;
+ });
-sock.on('end', function() {
- gotClientEnd = true;
-});
+ process.on('exit', function() {
+ assert.equal(serverData, clientData);
+ assert.equal(serverData, 'hello1hello2hello3\nTHUNDERMUSCLE!');
+ assert(gotClientEnd);
+ assert(gotServerEnd);
+ console.log('ok');
+ });
-process.on('exit', function() {
- assert.equal(serverData, clientData);
- assert.equal(serverData, 'hello1hello2hello3\nTHUNDERMUSCLE!');
- assert(gotClientEnd);
- assert(gotServerEnd);
- console.log('ok');
+ sock.write('hello1');
+ sock.write('hello2');
+ sock.write('hello3\n');
+ sock.end('THUNDERMUSCLE!');
});
-
-sock.write('hello1');
-sock.write('hello2');
-sock.write('hello3\n');
-sock.end('THUNDERMUSCLE!');