Skip to content

Commit 0bb6dea

Browse files
author
Bar Admoni
committed
Make the assersion in the test and not in the end
as suggested by @bnoordhuis
1 parent ba01ed1 commit 0bb6dea

File tree

1 file changed

+12
-59
lines changed

1 file changed

+12
-59
lines changed

test/parallel/test-cluster-worker-kill-signal.js

Lines changed: 12 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -18,44 +18,6 @@ if (cluster.isWorker) {
1818

1919
} else if (cluster.isMaster) {
2020
const KILL_SIGNAL = 'SIGKILL';
21-
const expectedResults = {
22-
emitDisconnect: {
23-
value: 1,
24-
message: "the worker did not emit 'disconnect'"
25-
},
26-
emitExit: {
27-
value: 1,
28-
message: "the worker did not emit 'exit'"
29-
},
30-
state: {
31-
value: 'disconnected',
32-
message: 'the worker state is incorrect'
33-
},
34-
exitedAfter: {
35-
value: false,
36-
message: 'the .exitedAfterDisconnect flag is incorrect'
37-
},
38-
died: {
39-
value: true,
40-
message: 'the worker is still running'
41-
},
42-
exitCode: {
43-
value: null,
44-
message: 'the worker exited w/ incorrect exitCode'
45-
},
46-
signalCode: {
47-
value: KILL_SIGNAL,
48-
message: 'the worker exited w/ incorrect signalCode'
49-
},
50-
numberOfWorkers: {
51-
value: 0,
52-
message: 'the number of workers running is wrong'
53-
},
54-
};
55-
const results = {
56-
emitDisconnect: 0,
57-
emitExit: 0
58-
};
5921

6022
// Start worker
6123
const worker = cluster.fork();
@@ -67,30 +29,21 @@ if (cluster.isWorker) {
6729

6830
// Check worker events and properties
6931
worker.on('disconnect', common.mustCall(() => {
70-
results.emitDisconnect += 1;
71-
results.exitedAfter = worker.exitedAfterDisconnect;
72-
results.state = worker.state;
73-
}));
32+
assert.strictEqual(worker.exitedAfterDisconnect, false);
33+
assert.strictEqual(worker.state, 'disconnected');
34+
}, 1));
7435

7536
// Check that the worker died
7637
worker.once('exit', common.mustCall((exitCode, signalCode) => {
77-
// Setting the results
78-
results.exitCode = exitCode;
79-
results.signalCode = signalCode;
80-
results.emitExit += 1;
81-
results.died = !common.isAlive(worker.process.pid);
82-
results.numberOfWorkers = Object.keys(cluster.workers).length;
83-
}));
38+
const isWorkerProcessStillAlive = common.isAlive(worker.process.pid);
39+
const numOfRunningWorkers = Object.keys(cluster.workers).length;
8440

85-
cluster.on('exit', common.mustCall(() => {
86-
// Checking if the results are as expected
87-
for (const [key, expected] of Object.entries(expectedResults)) {
88-
const actual = results[key];
41+
assert.strictEqual(exitCode, null);
42+
assert.strictEqual(signalCode, KILL_SIGNAL);
43+
assert.strictEqual(isWorkerProcessStillAlive, false);
44+
assert.strictEqual(numOfRunningWorkers, 0);
45+
}, 1));
8946

90-
assert.strictEqual(
91-
actual, expected.value,
92-
`${expected.message} [expected: ${expected.value} / actual: ${actual}]`
93-
);
94-
}
95-
}));
47+
// Check if the cluster was killed as well
48+
cluster.on('exit', common.mustCall(() => {}, 1));
9649
}

0 commit comments

Comments
 (0)