test: refactor test-cluster-disconnect
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 <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>
This commit is contained in:
parent
9ff7ed23cd
commit
a45c2db4b6
@ -42,7 +42,7 @@ if (cluster.isWorker) {
|
|||||||
const socket = net.connect(port, '127.0.0.1', () => {
|
const socket = net.connect(port, '127.0.0.1', () => {
|
||||||
// buffer result
|
// buffer result
|
||||||
let result = '';
|
let result = '';
|
||||||
socket.on('data', common.mustCall((chunk) => { result += chunk; }));
|
socket.on('data', (chunk) => { result += chunk; });
|
||||||
|
|
||||||
// check result
|
// check result
|
||||||
socket.on('end', common.mustCall(() => {
|
socket.on('end', common.mustCall(() => {
|
||||||
@ -55,7 +55,7 @@ if (cluster.isWorker) {
|
|||||||
const testCluster = function(cb) {
|
const testCluster = function(cb) {
|
||||||
let done = 0;
|
let done = 0;
|
||||||
|
|
||||||
for (let i = 0, l = servers; i < l; i++) {
|
for (let i = 0; i < servers; i++) {
|
||||||
testConnection(common.PORT + i, (success) => {
|
testConnection(common.PORT + i, (success) => {
|
||||||
assert.ok(success);
|
assert.ok(success);
|
||||||
done += 1;
|
done += 1;
|
||||||
@ -81,40 +81,21 @@ if (cluster.isWorker) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const results = {
|
|
||||||
start: 0,
|
|
||||||
test: 0,
|
|
||||||
disconnect: 0
|
|
||||||
};
|
|
||||||
|
|
||||||
const test = function(again) {
|
const test = function(again) {
|
||||||
//1. start cluster
|
//1. start cluster
|
||||||
startCluster(() => {
|
startCluster(common.mustCall(() => {
|
||||||
results.start += 1;
|
|
||||||
|
|
||||||
//2. test cluster
|
//2. test cluster
|
||||||
testCluster(() => {
|
testCluster(common.mustCall(() => {
|
||||||
results.test += 1;
|
|
||||||
|
|
||||||
//3. disconnect cluster
|
//3. disconnect cluster
|
||||||
cluster.disconnect(() => {
|
cluster.disconnect(common.mustCall(() => {
|
||||||
results.disconnect += 1;
|
|
||||||
|
|
||||||
// run test again to confirm cleanup
|
// run test again to confirm cleanup
|
||||||
if (again) {
|
if (again) {
|
||||||
test();
|
test();
|
||||||
}
|
}
|
||||||
});
|
}));
|
||||||
});
|
}));
|
||||||
});
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
test(true);
|
test(true);
|
||||||
|
|
||||||
process.once('exit', () => {
|
|
||||||
assert.strictEqual(results.start, 2);
|
|
||||||
assert.strictEqual(results.test, 2);
|
|
||||||
assert.strictEqual(results.disconnect, 2);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user