Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b69cac7

Browse filesBrowse 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 <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 0fff04f commit b69cac7
Copy full SHA for b69cac7

File tree

Expand file treeCollapse file tree

1 file changed

+8
-27
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+8
-27
lines changed
Open diff view settings
Collapse file

‎test/parallel/test-cluster-disconnect.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-cluster-disconnect.js
+8-27Lines changed: 8 additions & 27 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.