Skip to content

Commit d73f214

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 <[email protected]> Reviewed-By: Weijia Wang <[email protected]> Reviewed-By: Yuta Hiroto <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Richard Lau <[email protected]>
1 parent 0dd8ea4 commit d73f214

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

test/parallel/test-tls-pause.js

+15-13
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
const assert = require('assert');
2831
const tls = require('tls');
2932
const fixtures = require('../common/fixtures');
@@ -37,24 +40,23 @@ const bufSize = 1024 * 1024;
3740
let sent = 0;
3841
let received = 0;
3942

40-
const server = tls.Server(options, function(socket) {
43+
const server = 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
let resumed = false;
4952
const client = 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-
function send() {
59+
const send = (() => {
5860
console.error('sending');
5961
const ret = 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)