Skip to content

Commit ade64e6

Browse files
TrottMylesBorins
authored andcommitted
test: refactor test-cluster-disconnect
Replace `process.once('exit', ...)` with `common.mustCall()`. Remove unneeded variable in loop declaration. PR-URL: #11981 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Santiago Gimeno <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 6c803db commit ade64e6

File tree

1 file changed

+8
-27
lines changed

1 file changed

+8
-27
lines changed

test/parallel/test-cluster-disconnect.js

+8-27
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ if (cluster.isWorker) {
2121
const socket = net.connect(port, '127.0.0.1', () => {
2222
// buffer result
2323
let result = '';
24-
socket.on('data', common.mustCall((chunk) => { result += chunk; }));
24+
socket.on('data', (chunk) => { result += chunk; });
2525

2626
// check result
2727
socket.on('end', common.mustCall(() => {
@@ -34,7 +34,7 @@ if (cluster.isWorker) {
3434
const testCluster = function(cb) {
3535
let done = 0;
3636

37-
for (let i = 0, l = servers; i < l; i++) {
37+
for (let i = 0; i < servers; i++) {
3838
testConnection(common.PORT + i, (success) => {
3939
assert.ok(success);
4040
done += 1;
@@ -60,40 +60,21 @@ if (cluster.isWorker) {
6060
}
6161
};
6262

63-
64-
const results = {
65-
start: 0,
66-
test: 0,
67-
disconnect: 0
68-
};
69-
7063
const test = function(again) {
7164
//1. start cluster
72-
startCluster(() => {
73-
results.start += 1;
74-
65+
startCluster(common.mustCall(() => {
7566
//2. test cluster
76-
testCluster(() => {
77-
results.test += 1;
78-
67+
testCluster(common.mustCall(() => {
7968
//3. disconnect cluster
80-
cluster.disconnect(() => {
81-
results.disconnect += 1;
82-
69+
cluster.disconnect(common.mustCall(() => {
8370
// run test again to confirm cleanup
8471
if (again) {
8572
test();
8673
}
87-
});
88-
});
89-
});
74+
}));
75+
}));
76+
}));
9077
};
9178

9279
test(true);
93-
94-
process.once('exit', () => {
95-
assert.strictEqual(results.start, 2);
96-
assert.strictEqual(results.test, 2);
97-
assert.strictEqual(results.disconnect, 2);
98-
});
9980
}

0 commit comments

Comments
 (0)