Skip to content

Commit 21153f1

Browse files
tniessentargos
authored andcommitted
test: simplify test-tls-ecdh-auto
Avoid the process 'exit' event handler and use execFile instead of manual stream operations. Refs: #46751 PR-URL: #46911 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com>
1 parent 762dc7c commit 21153f1

1 file changed

Lines changed: 8 additions & 26 deletions

File tree

‎test/parallel/test-tls-ecdh-auto.js‎

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ if (!common.opensslCli)
1212

1313
constassert=require('assert');
1414
consttls=require('tls');
15-
constspawn=require('child_process').spawn;
15+
const{ execFile }=require('child_process');
1616
constfixtures=require('../common/fixtures');
1717

1818
functionloadPEM(n){
@@ -29,33 +29,15 @@ const options = {
2929

3030
constreply='I AM THE WALRUS';// Something recognizable
3131

32-
constserver=tls.createServer(options,function(conn){
32+
constserver=tls.createServer(options,(conn)=>{
3333
conn.end(reply);
34-
});
35-
36-
letgotReply=false;
37-
38-
server.listen(0,function(){
34+
}).listen(0,common.mustCall(()=>{
3935
constargs=['s_client',
4036
'-cipher',`${options.ciphers}`,
41-
'-connect',`127.0.0.1:${this.address().port}`];
42-
43-
constclient=spawn(common.opensslCli,args);
37+
'-connect',`127.0.0.1:${server.address().port}`];
4438

45-
client.stdout.on('data',function(data){
46-
constmessage=data.toString();
47-
if(message.includes(reply))
48-
gotReply=true;
49-
});
50-
51-
client.on('exit',function(code){
52-
assert.strictEqual(code,0);
39+
execFile(common.opensslCli,args,common.mustSucceed((stdout)=>{
40+
assert(stdout.includes(reply));
5341
server.close();
54-
});
55-
56-
client.on('error',assert.ifError);
57-
});
58-
59-
process.on('exit',function(){
60-
assert.ok(gotReply);
61-
});
42+
}));
43+
}));

0 commit comments

Comments
 (0)