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 6b45bf3

Browse filesBrowse files
addaleaxBethGriggs
authored andcommitted
test: modernize test-cluster-master-error
Some stylistic changes to bring this more in line with what our tests currently look like, and add a note about general flakiness. PR-URL: #34685 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ricky Zhou <0x19951125@gmail.com>
1 parent 34430ab commit 6b45bf3
Copy full SHA for 6b45bf3

File tree

Expand file treeCollapse file tree

1 file changed

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

1 file changed

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

‎test/parallel/test-cluster-master-error.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-cluster-master-error.js
+8-30Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,11 @@ const totalWorkers = 2;
2929
// Cluster setup
3030
if (cluster.isWorker) {
3131
const http = require('http');
32-
http.Server(() => {
33-
34-
}).listen(0, '127.0.0.1');
35-
32+
http.Server(() => {}).listen(0, '127.0.0.1');
3633
} else if (process.argv[2] === 'cluster') {
37-
3834
// Send PID to testcase process
3935
let forkNum = 0;
4036
cluster.on('fork', common.mustCall(function forkEvent(worker) {
41-
4237
// Send PID
4338
process.send({
4439
cmd: 'worker',
@@ -49,12 +44,11 @@ if (cluster.isWorker) {
4944
if (++forkNum === totalWorkers) {
5045
cluster.removeListener('fork', forkEvent);
5146
}
52-
}));
47+
}, totalWorkers));
5348

5449
// Throw accidental error when all workers are listening
5550
let listeningNum = 0;
5651
cluster.on('listening', common.mustCall(function listeningEvent() {
57-
5852
// When all workers are listening
5953
if (++listeningNum === totalWorkers) {
6054
// Stop listening
@@ -65,21 +59,16 @@ if (cluster.isWorker) {
6559
throw new Error('accidental error');
6660
});
6761
}
68-
69-
}));
62+
}, totalWorkers));
7063

7164
// Startup a basic cluster
7265
cluster.fork();
7366
cluster.fork();
74-
7567
} else {
7668
// This is the testcase
7769

7870
const fork = require('child_process').fork;
7971

80-
let masterExited = false;
81-
let workersExited = false;
82-
8372
// List all workers
8473
const workers = [];
8574

@@ -88,7 +77,6 @@ if (cluster.isWorker) {
8877

8978
// Handle messages from the cluster
9079
master.on('message', common.mustCall((data) => {
91-
9280
// Add worker pid to list and progress tracker
9381
if (data.cmd === 'worker') {
9482
workers.push(data.workerPID);
@@ -97,30 +85,20 @@ if (cluster.isWorker) {
9785

9886
// When cluster is dead
9987
master.on('exit', common.mustCall((code) => {
100-
10188
// Check that the cluster died accidentally (non-zero exit code)
102-
masterExited = !!code;
89+
assert.strictEqual(code, 1);
10390

91+
// XXX(addaleax): The fact that this uses raw PIDs makes the test inherently
92+
// flaky – another process might end up being started right after the
93+
// workers finished and receive the same PID.
10494
const pollWorkers = () => {
10595
// When master is dead all workers should be dead too
106-
let alive = false;
107-
workers.forEach((pid) => alive = common.isAlive(pid));
108-
if (alive) {
96+
if (workers.some((pid) => common.isAlive(pid))) {
10997
setTimeout(pollWorkers, 50);
110-
} else {
111-
workersExited = true;
11298
}
11399
};
114100

115101
// Loop indefinitely until worker exit
116102
pollWorkers();
117103
}));
118-
119-
process.once('exit', () => {
120-
assert(masterExited,
121-
'The master did not die after an error was thrown');
122-
assert(workersExited,
123-
'The workers did not die after an error in the master');
124-
});
125-
126104
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.