Skip to content

Commit ffa7b50

Browse files
juggernaut451MylesBorins
authored andcommitted
test: refactor parallel/test-tls-pause
Use arrow functions and common.mustCall() and add a description. PR-URL: #18714 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Weijia Wang <starkwang@126.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com>
1 parent 399ba4b commit ffa7b50

1 file changed

Lines changed: 15 additions & 13 deletions

File tree

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ const common = require('../common');
2424
if(!common.hasCrypto)
2525
common.skip('missing crypto');
2626

27+
// This test ensures that the data received over tls-server after pause
28+
// is same as what it was sent
29+
2730
constassert=require('assert');
2831
consttls=require('tls');
2932
constfixtures=require('../common/fixtures');
@@ -37,24 +40,23 @@ const bufSize = 1024 * 1024;
3740
letsent=0;
3841
letreceived=0;
3942

40-
constserver=tls.Server(options,function(socket){
43+
constserver=tls.Server(options,common.mustCall((socket)=>{
4144
socket.pipe(socket);
42-
socket.on('data',function(c){
45+
socket.on('data',(c)=>{
4346
console.error('data',c.length);
4447
});
45-
});
48+
}));
4649

47-
server.listen(0,function(){
50+
server.listen(0,common.mustCall(()=>{
4851
letresumed=false;
4952
constclient=tls.connect({
50-
port: this.address().port,
53+
port: server.address().port,
5154
rejectUnauthorized: false
52-
},function(){
55+
},common.mustCall(()=>{
5356
console.error('connected');
5457
client.pause();
5558
console.error('paused');
56-
send();
57-
functionsend(){
59+
constsend=(()=>{
5860
console.error('sending');
5961
constret=client.write(Buffer.allocUnsafe(bufSize));
6062
console.error(`write => ${ret}`);
@@ -69,9 +71,9 @@ server.listen(0, function() {
6971
resumed=true;
7072
client.resume();
7173
console.error('resumed',client);
72-
}
73-
});
74-
client.on('data',function(data){
74+
})();
75+
}));
76+
client.on('data',(data)=>{
7577
console.error('data');
7678
assert.ok(resumed);
7779
received+=data.length;
@@ -83,8 +85,8 @@ server.listen(0, function() {
8385
server.close();
8486
}
8587
});
86-
});
88+
}));
8789

88-
process.on('exit',function(){
90+
process.on('exit',()=>{
8991
assert.strictEqual(sent,received);
9092
});

0 commit comments

Comments
 (0)