Skip to content

Commit 3644796

Browse files
tniessendanielleadams
authored andcommitted
test: simplify test-tls-alert
Avoid the process 'exit' event handler and use execFile instead of manual stream operations. Refs: #46751 PR-URL: #46805 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent df14944 commit 3644796

1 file changed

Lines changed: 9 additions & 19 deletions

File tree

‎test/parallel/test-tls-alert.js‎

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,10 @@ if (!common.opensslCli)
2828
common.skip('node compiled without OpenSSL CLI.');
2929

3030
constassert=require('assert');
31-
const{spawn}=require('child_process');
31+
const{execFile}=require('child_process');
3232
consttls=require('tls');
3333
constfixtures=require('../common/fixtures');
3434

35-
letsuccess=false;
36-
3735
functionloadPEM(n){
3836
returnfixtures.readKey(`${n}.pem`);
3937
}
@@ -42,21 +40,13 @@ const server = tls.Server({
4240
secureProtocol: 'TLSv1_2_server_method',
4341
key: loadPEM('agent2-key'),
4442
cert: loadPEM('agent2-cert')
45-
},null).listen(0,function(){
43+
},null).listen(0,common.mustCall(()=>{
4644
constargs=['s_client','-quiet','-tls1_1',
47-
'-connect',`127.0.0.1:${this.address().port}`];
45+
'-connect',`127.0.0.1:${server.address().port}`];
4846

49-
constclient=spawn(common.opensslCli,args);
50-
letout='';
51-
client.stderr.setEncoding('utf8');
52-
client.stderr.on('data',function(d){
53-
out+=d;
54-
if(/SSLalertnumber70/.test(out)){
55-
success=true;
56-
server.close();
57-
}
58-
});
59-
});
60-
process.on('exit',function(){
61-
assert(success);
62-
});
47+
execFile(common.opensslCli,args,common.mustCall((err,_,stderr)=>{
48+
assert.strictEqual(err.code,1);
49+
assert.match(stderr,/SSLalertnumber70/);
50+
server.close();
51+
}));
52+
}));

0 commit comments

Comments
 (0)