Skip to content

Commit

Permalink
test: remove common.port from test-tls-securepair-client
Browse files Browse the repository at this point in the history
OpenSSL s_server accepts port 0 as an indicator to use an open port
provided by the operating system. Use that instead of common.PORT in the
test.

Remove 500ms delay added in 8e46167.
Hopefully the race condition in OpenSSL s_server has been fixed and/or
the change to port 0 means that the server is listening by the time
the ACCEPT text is printed and the setTimeout() is no longer necessary.

PR-URL: #32024
Reviewed-By: Ben Coe <bencoe@gmail.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
  • Loading branch information
Trott committed Mar 2, 2020
1 parent a0c3c4d commit 9ac42f1
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions test/sequential/test-tls-securepair-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function test(keyPath, certPath, check, next) {
const cert = fixtures.readSync(certPath).toString();

const server = spawn(common.opensslCli, ['s_server',
'-accept', common.PORT,
'-accept', 0,
'-cert', fixtures.path(certPath),
'-key', fixtures.path(keyPath)]);
server.stdout.pipe(process.stdout);
Expand All @@ -78,10 +78,11 @@ function test(keyPath, certPath, check, next) {
console.log(state);
switch (state) {
case 'WAIT-ACCEPT':
if (/ACCEPT/.test(serverStdoutBuffer)) {
// Give s_server half a second to start up.
setTimeout(startClient, 500);
const matches = serverStdoutBuffer.match(/ACCEPT .*?:(\d+)/);
if (matches) {
const port = matches[1];
state = 'WAIT-HELLO';
startClient(port);
}
break;

Expand Down Expand Up @@ -117,7 +118,7 @@ function test(keyPath, certPath, check, next) {
});


function startClient() {
function startClient(port) {
const s = new net.Stream();

const sslcontext = tls.createSecureContext({ key, cert });
Expand All @@ -131,7 +132,7 @@ function test(keyPath, certPath, check, next) {
pair.encrypted.pipe(s);
s.pipe(pair.encrypted);

s.connect(common.PORT);
s.connect(port);

s.on('connect', function() {
console.log('client connected');
Expand Down

0 comments on commit 9ac42f1

Please sign in to comment.