From a5bff1fa63e25d890fee0ceb67d965ffb924755e Mon Sep 17 00:00:00 2001 From: juggernaut451 Date: Sun, 11 Feb 2018 21:39:05 +0530 Subject: [PATCH 1/3] refactoring test-tls-pause with arrow function & adding description --- test/parallel/test-tls-pause.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/test/parallel/test-tls-pause.js b/test/parallel/test-tls-pause.js index 75c2832f7332f8..352e0bb3903cb6 100644 --- a/test/parallel/test-tls-pause.js +++ b/test/parallel/test-tls-pause.js @@ -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 send + const assert = require('assert'); const tls = require('tls'); const fixtures = require('../common/fixtures'); @@ -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, (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, () => { let resumed = false; const client = tls.connect({ - port: this.address().port, + port: server.address().port, rejectUnauthorized: false - }, function() { + }, () => { console.error('connected'); client.pause(); console.error('paused'); - send(); - function send() { + let send = (() => { console.error('sending'); const ret = client.write(Buffer.allocUnsafe(bufSize)); console.error(`write => ${ret}`); @@ -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; @@ -85,6 +87,6 @@ server.listen(0, function() { }); }); -process.on('exit', function() { +process.on('exit', () => { assert.strictEqual(sent, received); }); From 762231d751816de79f728a12e0fee426ee10e756 Mon Sep 17 00:00:00 2001 From: juggernaut451 Date: Sun, 11 Feb 2018 22:49:22 +0530 Subject: [PATCH 2/3] Adding common.mustCall over callbacks --- test/parallel/test-tls-pause.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/parallel/test-tls-pause.js b/test/parallel/test-tls-pause.js index 352e0bb3903cb6..ae688b8135984c 100644 --- a/test/parallel/test-tls-pause.js +++ b/test/parallel/test-tls-pause.js @@ -40,23 +40,23 @@ const bufSize = 1024 * 1024; let sent = 0; let received = 0; -const server = tls.Server(options, (socket) => { +const server = tls.Server(options, common.mustCall((socket) => { socket.pipe(socket); socket.on('data', (c) => { console.error('data', c.length); }); -}); +})); server.listen(0, () => { let resumed = false; const client = tls.connect({ port: server.address().port, rejectUnauthorized: false - }, () => { + }, common.mustCall(() => { console.error('connected'); client.pause(); console.error('paused'); - let send = (() => { + const send = (() => { console.error('sending'); const ret = client.write(Buffer.allocUnsafe(bufSize)); console.error(`write => ${ret}`); @@ -72,7 +72,7 @@ server.listen(0, () => { client.resume(); console.error('resumed', client); })(); - }); + })); client.on('data', (data) => { console.error('data'); assert.ok(resumed); From b00845012dab9f3c266e21e2809cc8228b00c09a Mon Sep 17 00:00:00 2001 From: juggernaut451 Date: Wed, 14 Feb 2018 12:28:05 +0530 Subject: [PATCH 3/3] test: refactor parallel/test-tls-pause --- test/parallel/test-tls-pause.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/parallel/test-tls-pause.js b/test/parallel/test-tls-pause.js index ae688b8135984c..a6130cd4331f62 100644 --- a/test/parallel/test-tls-pause.js +++ b/test/parallel/test-tls-pause.js @@ -25,7 +25,7 @@ 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 send +// is same as what it was sent const assert = require('assert'); const tls = require('tls'); @@ -47,7 +47,7 @@ const server = tls.Server(options, common.mustCall((socket) => { }); })); -server.listen(0, () => { +server.listen(0, common.mustCall(() => { let resumed = false; const client = tls.connect({ port: server.address().port, @@ -85,7 +85,7 @@ server.listen(0, () => { server.close(); } }); -}); +})); process.on('exit', () => { assert.strictEqual(sent, received);