From d73f214380b442391c2e7d55ec91c483d82ca510 Mon Sep 17 00:00:00 2001 From: juggernaut451 Date: Sun, 11 Feb 2018 21:39:05 +0530 Subject: [PATCH] test: refactor parallel/test-tls-pause Use arrow functions and common.mustCall() and add a description. PR-URL: https://github.com/nodejs/node/pull/18714 Reviewed-By: Anna Henningsen Reviewed-By: Weijia Wang Reviewed-By: Yuta Hiroto Reviewed-By: Luigi Pinca Reviewed-By: James M Snell Reviewed-By: Richard Lau --- test/parallel/test-tls-pause.js | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/test/parallel/test-tls-pause.js b/test/parallel/test-tls-pause.js index 75c2832f7332f8..a6130cd4331f62 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 sent + 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, 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}`); @@ -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; @@ -83,8 +85,8 @@ server.listen(0, function() { server.close(); } }); -}); +})); -process.on('exit', function() { +process.on('exit', () => { assert.strictEqual(sent, received); });