mirror of
https://github.com/nodejs/node.git
synced 2025-05-04 21:57:12 +00:00

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>
29 lines
597 B
JavaScript
29 lines
597 B
JavaScript
'use strict';
|
|
require('../common');
|
|
var assert = require('assert');
|
|
var net = require('net');
|
|
|
|
var received = '';
|
|
|
|
var server = net.createServer(function(socket) {
|
|
socket.pipe(socket);
|
|
}).listen(0, function() {
|
|
var conn = net.connect(this.address().port);
|
|
conn.setEncoding('utf8');
|
|
conn.write('before');
|
|
conn.on('connect', function() {
|
|
conn.write('after');
|
|
});
|
|
conn.on('data', function(buf) {
|
|
received += buf;
|
|
conn.end();
|
|
});
|
|
conn.on('end', function() {
|
|
server.close();
|
|
});
|
|
});
|
|
|
|
process.on('exit', function() {
|
|
assert.equal(received, 'before' + 'after');
|
|
});
|