Skip to content

Commit a45c2db

Browse files
committed
test: refactor test-cluster-disconnect
Replace `process.once('exit', ...)` with `common.mustCall()`. Remove unneeded variable in loop declaration. PR-URL: nodejs#11981 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 9ff7ed2 commit a45c2db

File tree

1 file changed

+8
-27
lines changed

1 file changed

+8
-27
lines changed

test/parallel/test-cluster-disconnect.js

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ if (cluster.isWorker) {
4242
const socket = net.connect(port, '127.0.0.1', () => {
4343
// buffer result
4444
let result = '';
45-
socket.on('data', common.mustCall((chunk) => { result += chunk; }));
45+
socket.on('data', (chunk) => { result += chunk; });
4646

4747
// check result
4848
socket.on('end', common.mustCall(() => {
@@ -55,7 +55,7 @@ if (cluster.isWorker) {
5555
const testCluster = function(cb) {
5656
let done = 0;
5757

58-
for (let i = 0, l = servers; i < l; i++) {
58+
for (let i = 0; i < servers; i++) {
5959
testConnection(common.PORT + i, (success) => {
6060
assert.ok(success);
6161
done += 1;
@@ -81,40 +81,21 @@ if (cluster.isWorker) {
8181
}
8282
};
8383

84-
85-
const results = {
86-
start: 0,
87-
test: 0,
88-
disconnect: 0
89-
};
90-
9184
const test = function(again) {
9285
//1. start cluster
93-
startCluster(() => {
94-
results.start += 1;
95-
86+
startCluster(common.mustCall(() => {
9687
//2. test cluster
97-
testCluster(() => {
98-
results.test += 1;
99-
88+
testCluster(common.mustCall(() => {
10089
//3. disconnect cluster
101-
cluster.disconnect(() => {
102-
results.disconnect += 1;
103-
90+
cluster.disconnect(common.mustCall(() => {
10491
// run test again to confirm cleanup
10592
if (again) {
10693
test();
10794
}
108-
});
109-
});
110-
});
95+
}));
96+
}));
97+
}));
11198
};
11299

113100
test(true);
114-
115-
process.once('exit', () => {
116-
assert.strictEqual(results.start, 2);
117-
assert.strictEqual(results.test, 2);
118-
assert.strictEqual(results.disconnect, 2);
119-
});
120101
}

0 commit comments

Comments
 (0)