Skip to content

Commit

Permalink
test: refactor parallel/test-tls-pause
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
juggernaut451 authored and BridgeAR committed Feb 17, 2018
1 parent ef7f5a1 commit c9b42c4
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions test/parallel/test-tls-pause.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');

// This test ensures that the data received over tls-server after pause
// is same as what it was sent

const assert = require('assert');
const tls = require('tls');
const fixtures = require('../common/fixtures');
Expand All @@ -37,24 +40,23 @@ const bufSize = 1024 * 1024;
let sent = 0;
let received = 0;

const server = tls.Server(options, function(socket) {
const server = tls.Server(options, common.mustCall((socket) => {
socket.pipe(socket);
socket.on('data', function(c) {
socket.on('data', (c) => {
console.error('data', c.length);
});
});
}));

server.listen(0, function() {
server.listen(0, common.mustCall(() => {
let resumed = false;
const client = tls.connect({
port: this.address().port,
port: server.address().port,
rejectUnauthorized: false
}, function() {
}, common.mustCall(() => {
console.error('connected');
client.pause();
console.error('paused');
send();
function send() {
const send = (() => {
console.error('sending');
const ret = client.write(Buffer.allocUnsafe(bufSize));
console.error(`write => ${ret}`);
Expand All @@ -69,9 +71,9 @@ server.listen(0, function() {
resumed = true;
client.resume();
console.error('resumed', client);
}
});
client.on('data', function(data) {
})();
}));
client.on('data', (data) => {
console.error('data');
assert.ok(resumed);
received += data.length;
Expand All @@ -83,8 +85,8 @@ server.listen(0, function() {
server.close();
}
});
});
}));

process.on('exit', function() {
process.on('exit', () => {
assert.strictEqual(sent, received);
});

0 comments on commit c9b42c4

Please sign in to comment.