node/test/parallel/test-tls-close-error.js
Fedor Indutny 80342f649d tls: use .destroy(err) instead of destroy+emit
Emit errors using `.destroy(err)` instead of `.destroy()` and
`.emit('error', err)`. Otherwise `close` event is emitted with the
`error` argument set to `false`, even if the connection was torn down
because of the error.

See: https://github.com/nodejs/io.js/issues/1119
PR-URL: https://github.com/nodejs/io.js/pull/1711
Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
2015-05-22 13:27:04 +02:00

43 lines
870 B
JavaScript

'use strict';
var assert = require('assert');
var common = require('../common');
if (!common.hasCrypto) {
console.log('1..0 # Skipped: missing crypto');
process.exit();
}
var tls = require('tls');
var fs = require('fs');
var net = require('net');
var errorCount = 0;
var closeCount = 0;
var server = tls.createServer({
key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'),
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem')
}, function(c) {
}).listen(common.PORT, function() {
var c = tls.connect(common.PORT, function() {
assert(false, 'should not be called');
});
c.on('error', function(err) {
errorCount++;
});
c.on('close', function(err) {
if (err)
closeCount++;
server.close();
});
});
process.on('exit', function() {
assert.equal(errorCount, 1);
assert.equal(closeCount, 1);
});