diff --git a/test/parallel/test-tls-two-cas-one-string.js b/test/parallel/test-tls-two-cas-one-string.js index ba9b3609c2653d..6ae5945310d9d5 100644 --- a/test/parallel/test-tls-two-cas-one-string.js +++ b/test/parallel/test-tls-two-cas-one-string.js @@ -1,5 +1,6 @@ 'use strict'; +const assert = require('assert'); const common = require('../common'); const tls = require('tls'); const fs = require('fs'); @@ -13,23 +14,37 @@ const cert = const key = fs.readFileSync(`${common.fixturesDir}/keys/agent3-key.pem`, 'utf8'); -function test(ca, next) { - const server = tls.createServer({ ca, cert, key }, function(conn) { - this.close(); - conn.end(); - }); - server.addContext('agent3', { ca, cert, key }); +function test(ca) { + return new Promise(function(resolve, reject) { + const server = tls.createServer(function(conn) { + this.close(); + conn.end(); + }); - const host = common.localhostIPv4; - const port = common.PORT; - server.listen(port, host, function() { - tls.connect({ servername: 'agent3', host, port, ca }); - }); + server.addContext('agent3', { ca, cert, key }); - server.once('close', next); + const host = common.localhostIPv4; + const port = common.PORT; + server.listen(port, host, function() { + var socket = tls.connect({ servername: 'agent3', host, port, ca }); + var socketError = false; + socket.on('error', (e) => { socketError = e; }); + server.once('close', + (e) => { + return socketError ? reject(socketError) : resolve(); + }); + }); + }); } -const array = [ca1, ca2]; -const string = ca1 + '\n' + ca2; -test(array, () => test(string, () => {})); +test(ca1 + '\n' + ca2) + .then(test.bind(null, ca2 + '\n' + ca1)) + .then(test.bind(null, ca1 + ca2)) + .then(test.bind(null, ca2 + ca1)) + .then(test.bind(null, [ca1, ca2])) + .then(test.bind(null, [ca2, ca1])); + +process.on('unhandledRejection', function(reason) { + assert.fail(null, null, reason); +});