From a45c2db4b67a95f40f66852dd35e45ae9677df05 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Tue, 21 Mar 2017 21:48:21 -0700 Subject: [PATCH] test: refactor test-cluster-disconnect MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace `process.once('exit', ...)` with `common.mustCall()`. Remove unneeded variable in loop declaration. PR-URL: https://github.com/nodejs/node/pull/11981 Reviewed-By: James M Snell Reviewed-By: Michaƫl Zasso Reviewed-By: Colin Ihrig Reviewed-By: Santiago Gimeno Reviewed-By: Luigi Pinca --- test/parallel/test-cluster-disconnect.js | 35 ++++++------------------ 1 file changed, 8 insertions(+), 27 deletions(-) diff --git a/test/parallel/test-cluster-disconnect.js b/test/parallel/test-cluster-disconnect.js index a4772d1ad6..0f43b4ef59 100644 --- a/test/parallel/test-cluster-disconnect.js +++ b/test/parallel/test-cluster-disconnect.js @@ -42,7 +42,7 @@ if (cluster.isWorker) { const socket = net.connect(port, '127.0.0.1', () => { // buffer result let result = ''; - socket.on('data', common.mustCall((chunk) => { result += chunk; })); + socket.on('data', (chunk) => { result += chunk; }); // check result socket.on('end', common.mustCall(() => { @@ -55,7 +55,7 @@ if (cluster.isWorker) { const testCluster = function(cb) { let done = 0; - for (let i = 0, l = servers; i < l; i++) { + for (let i = 0; i < servers; i++) { testConnection(common.PORT + i, (success) => { assert.ok(success); done += 1; @@ -81,40 +81,21 @@ if (cluster.isWorker) { } }; - - const results = { - start: 0, - test: 0, - disconnect: 0 - }; - const test = function(again) { //1. start cluster - startCluster(() => { - results.start += 1; - + startCluster(common.mustCall(() => { //2. test cluster - testCluster(() => { - results.test += 1; - + testCluster(common.mustCall(() => { //3. disconnect cluster - cluster.disconnect(() => { - results.disconnect += 1; - + cluster.disconnect(common.mustCall(() => { // run test again to confirm cleanup if (again) { test(); } - }); - }); - }); + })); + })); + })); }; test(true); - - process.once('exit', () => { - assert.strictEqual(results.start, 2); - assert.strictEqual(results.test, 2); - assert.strictEqual(results.disconnect, 2); - }); }