Skip to content

Commit

Permalink
test: do not assume tls handshake order
Browse files Browse the repository at this point in the history
Do not assume that server handshake event happens before client, it is
not guaranteed.

PR-URL: #25508
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
sam-github authored and addaleax committed Feb 7, 2019
1 parent cc6b30f commit 639dc07
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions test/parallel/test-tls-alpn-server-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ function runTest(clientsOptions, serverOptions, cb) {
serverOptions.key = loadPEM('agent2-key');
serverOptions.cert = loadPEM('agent2-cert');
const results = [];
let index = 0;
let clientIndex = 0;
let serverIndex = 0;
const server = tls.createServer(serverOptions, function(c) {
results[index].server = { ALPN: c.alpnProtocol };
results[serverIndex++].server = { ALPN: c.alpnProtocol };
});

server.listen(0, serverIP, function() {
Expand All @@ -38,16 +39,18 @@ function runTest(clientsOptions, serverOptions, cb) {
opt.host = serverIP;
opt.rejectUnauthorized = false;

results[index] = {};
results[clientIndex] = {};
const client = tls.connect(opt, function() {
results[index].client = { ALPN: client.alpnProtocol };
client.destroy();
results[clientIndex].client = { ALPN: client.alpnProtocol };
client.end();
if (options.length) {
index++;
clientIndex++;
connectClient(options);
} else {
server.close();
cb(results);
server.on('close', () => {
cb(results);
});
}
});
}
Expand Down

0 comments on commit 639dc07

Please sign in to comment.