-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunner.js
More file actions
52 lines (49 loc) · 1.27 KB
/
runner.js
File metadata and controls
52 lines (49 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const { fork } = require("child_process");
let clients = [];
let finalReplicas = [];
let clientsCounter = 0;
let inputFiles1 = [
"input-file-1.txt",
"input-file-2.txt",
"input-file-3.txt",
"input-file-4.txt",
"input-file-5.txt",
"input-file-6.txt",
"input-file-7.txt",
"input-file-8.txt",
"input-file-9.txt",
"input-file-10.txt",
];
let inputFiles2 = [
"input-file-11.txt",
"input-file-12.txt"
];
let inputFiles3 = [
"input-file-31.txt",
"input-file-32.txt",
"input-file-33.txt"
];
inputFiles1.map(fileName => {
const client = fork("client.js", [`inputs/${fileName}`]);
clientsCounter++;
client.on("message", message => finalReplicas.push(message));
clients.push(client);
});
clients.map(client =>
client.on("close", code => {
clientsCounter--;
if (clientsCounter === 0)
checkReplicas();
})
);
const checkReplicas = () => {
const result = finalReplicas.every((replica, index, arr) => replica === arr[0]);
if (result)
console.log("All replicas are equal! replica: " + finalReplicas[0]);
else {
console.log("Not all replicas are equal, replicas:");
finalReplicas.map((replica, id) =>
console.log(`Client ${id}: ${replica}`)
);
}
};