mirror of
https://github.com/nodejs/node.git
synced 2025-05-13 10:54:13 +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>
47 lines
974 B
JavaScript
47 lines
974 B
JavaScript
'use strict';
|
|
var common = require('../common');
|
|
var assert = require('assert');
|
|
|
|
if (!common.hasCrypto) {
|
|
common.skip('missing crypto');
|
|
return;
|
|
}
|
|
var tls = require('tls');
|
|
|
|
var net = require('net');
|
|
var fs = require('fs');
|
|
|
|
var options = {
|
|
key: fs.readFileSync(common.fixturesDir + '/test_key.pem'),
|
|
cert: fs.readFileSync(common.fixturesDir + '/test_cert.pem')
|
|
};
|
|
|
|
var bonkers = Buffer.alloc(1024 * 1024, 42);
|
|
|
|
var server = tls.createServer(options, function(c) {
|
|
|
|
}).listen(0, function() {
|
|
var client = net.connect(this.address().port, function() {
|
|
client.write(bonkers);
|
|
});
|
|
|
|
var once = false;
|
|
|
|
var writeAgain = setTimeout(function() {
|
|
client.write(bonkers);
|
|
});
|
|
|
|
client.on('error', function(err) {
|
|
if (!once) {
|
|
clearTimeout(writeAgain);
|
|
once = true;
|
|
client.destroy();
|
|
server.close();
|
|
}
|
|
});
|
|
|
|
client.on('close', function(hadError) {
|
|
assert.strictEqual(hadError, true, 'Client never errored');
|
|
});
|
|
});
|