Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/backend/conat/test/cluster/remove-node.test.ts
1712 views
1
/*
2
What happens when a node is removed from the cluster.
3
*/
4
5
import {
6
before,
7
after,
8
server,
9
addNodeToDefaultCluster,
10
wait,
11
} from "@cocalc/backend/conat/test/setup";
12
13
beforeAll(before);
14
15
describe("setup basic pub/sub test with a 2-node cluster, then remove a node and observe that subscriber vanishes", () => {
16
let client0, server1, client1;
17
it("add another node to cluster", async () => {
18
client0 = server.client();
19
server1 = await addNodeToDefaultCluster();
20
client1 = server1.client();
21
});
22
23
it("checks addresses before deleting server1", () => {
24
expect(server.clusterAddresses()).toEqual([
25
server.address(),
26
server1.address(),
27
]);
28
});
29
30
let sub;
31
it("subscribe", async () => {
32
sub = await client1.subscribe("cocalc");
33
});
34
35
it("publish -- message is initially dropped with no receiver because interest doesn't propogate instantly", async () => {
36
const { count } = await client0.publish("cocalc", "hi");
37
expect(count).toBe(0);
38
});
39
40
it("publish after waiting for interest -- this works", async () => {
41
await client0.waitForInterest("cocalc");
42
const { count, bytes } = await client0.publish("cocalc", "hi");
43
expect(count).toBe(1);
44
expect(bytes).toBe(3);
45
});
46
47
it("receive", async () => {
48
const { value } = await sub.next();
49
expect(value.data).toBe("hi");
50
});
51
52
it("now kill the second node", async () => {
53
server1.close();
54
});
55
56
it("publish -- message should be dropped as soon as the server client0 is connected to notices that server1 is dead", async () => {
57
await wait({
58
until: async () => {
59
const { count } = await client0.publish("cocalc", "hi");
60
return count == 0;
61
},
62
timeout: 3000,
63
});
64
});
65
66
it("checks addresses before deleting server1", () => {
67
expect(server.clusterAddresses()).toEqual([server.address()]);
68
});
69
});
70
71
afterAll(after);
72
73