From 9ac42f1be42f162ec9cf6bb56e817d7b210a6db9 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sat, 29 Feb 2020 09:48:44 -0800 Subject: [PATCH] test: remove common.port from test-tls-securepair-client 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 8e461673c44cb550a7aadc20f0af6453810f1b18. 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: https://github.com/nodejs/node/pull/32024 Reviewed-By: Ben Coe Reviewed-By: Sam Roberts --- test/sequential/test-tls-securepair-client.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/test/sequential/test-tls-securepair-client.js b/test/sequential/test-tls-securepair-client.js index c450410baf9..d5e2b7b7d2b 100644 --- a/test/sequential/test-tls-securepair-client.js +++ b/test/sequential/test-tls-securepair-client.js @@ -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); @@ -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; @@ -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 }); @@ -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');