Skip to content

Commit be90817

Browse files
TrottMylesBorins
authored andcommittedMar 4, 2020
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 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>
1 parent 6b44df2 commit be90817

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed
 

‎test/sequential/test-tls-securepair-client.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function test(keyPath, certPath, check, next) {
6262
const cert = fixtures.readSync(certPath).toString();
6363

6464
const server = spawn(common.opensslCli, ['s_server',
65-
'-accept', common.PORT,
65+
'-accept', 0,
6666
'-cert', fixtures.path(certPath),
6767
'-key', fixtures.path(keyPath)]);
6868
server.stdout.pipe(process.stdout);
@@ -78,10 +78,11 @@ function test(keyPath, certPath, check, next) {
7878
console.log(state);
7979
switch (state) {
8080
case 'WAIT-ACCEPT':
81-
if (/ACCEPT/.test(serverStdoutBuffer)) {
82-
// Give s_server half a second to start up.
83-
setTimeout(startClient, 500);
81+
const matches = serverStdoutBuffer.match(/ACCEPT .*?:(\d+)/);
82+
if (matches) {
83+
const port = matches[1];
8484
state = 'WAIT-HELLO';
85+
startClient(port);
8586
}
8687
break;
8788

@@ -117,7 +118,7 @@ function test(keyPath, certPath, check, next) {
117118
});
118119

119120

120-
function startClient() {
121+
function startClient(port) {
121122
const s = new net.Stream();
122123

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

134-
s.connect(common.PORT);
135+
s.connect(port);
135136

136137
s.on('connect', function() {
137138
console.log('client connected');

0 commit comments

Comments
 (0)
Please sign in to comment.