mirror of
https://github.com/nodejs/node.git
synced 2025-05-06 16:46:56 +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>
45 lines
853 B
JavaScript
45 lines
853 B
JavaScript
'use strict';
|
|
require('../common');
|
|
var net = require('net');
|
|
var assert = require('assert');
|
|
|
|
var timeoutCount = 0;
|
|
|
|
var server = net.createServer(function(stream) {
|
|
stream.setTimeout(100);
|
|
|
|
stream.resume();
|
|
|
|
stream.on('timeout', function() {
|
|
console.log('timeout');
|
|
// try to reset the timeout.
|
|
stream.write('WHAT.');
|
|
// don't worry, the socket didn't *really* time out, we're just thinking
|
|
// it did.
|
|
timeoutCount += 1;
|
|
});
|
|
|
|
stream.on('end', function() {
|
|
console.log('server side end');
|
|
stream.end();
|
|
});
|
|
});
|
|
|
|
server.listen(0, function() {
|
|
var c = net.createConnection(this.address().port);
|
|
|
|
c.on('data', function() {
|
|
c.end();
|
|
});
|
|
|
|
c.on('end', function() {
|
|
console.log('client side end');
|
|
server.close();
|
|
});
|
|
});
|
|
|
|
|
|
process.on('exit', function() {
|
|
assert.equal(1, timeoutCount);
|
|
});
|