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>
52 lines
1 KiB
JavaScript
52 lines
1 KiB
JavaScript
'use strict';
|
|
var common = require('../common');
|
|
var assert = require('assert');
|
|
|
|
if (!common.hasCrypto) {
|
|
common.skip('missing crypto');
|
|
return;
|
|
}
|
|
var tls = require('tls');
|
|
|
|
var fs = require('fs');
|
|
var path = require('path');
|
|
|
|
var cert = fs.readFileSync(path.join(common.fixturesDir, 'test_cert.pem'));
|
|
var key = fs.readFileSync(path.join(common.fixturesDir, 'test_key.pem'));
|
|
|
|
var errorEmitted = false;
|
|
|
|
var server = tls.createServer({
|
|
cert: cert,
|
|
key: key
|
|
}, function(c) {
|
|
// Nop
|
|
setTimeout(function() {
|
|
c.end();
|
|
server.close();
|
|
}, 20);
|
|
}).listen(0, function() {
|
|
var conn = tls.connect({
|
|
cert: cert,
|
|
key: key,
|
|
rejectUnauthorized: false,
|
|
port: this.address().port
|
|
}, function() {
|
|
setTimeout(function() {
|
|
conn.destroy();
|
|
}, 20);
|
|
});
|
|
|
|
// SSL_write() call's return value, when called 0 bytes, should not be
|
|
// treated as error.
|
|
conn.end('');
|
|
|
|
conn.on('error', function(err) {
|
|
console.log(err);
|
|
errorEmitted = true;
|
|
});
|
|
});
|
|
|
|
process.on('exit', function() {
|
|
assert.ok(!errorEmitted);
|
|
});
|