Path: blob/master/src/packages/backend/conat/test/cluster/remove-node.test.ts
1712 views
/*1What happens when a node is removed from the cluster.2*/34import {5before,6after,7server,8addNodeToDefaultCluster,9wait,10} from "@cocalc/backend/conat/test/setup";1112beforeAll(before);1314describe("setup basic pub/sub test with a 2-node cluster, then remove a node and observe that subscriber vanishes", () => {15let client0, server1, client1;16it("add another node to cluster", async () => {17client0 = server.client();18server1 = await addNodeToDefaultCluster();19client1 = server1.client();20});2122it("checks addresses before deleting server1", () => {23expect(server.clusterAddresses()).toEqual([24server.address(),25server1.address(),26]);27});2829let sub;30it("subscribe", async () => {31sub = await client1.subscribe("cocalc");32});3334it("publish -- message is initially dropped with no receiver because interest doesn't propogate instantly", async () => {35const { count } = await client0.publish("cocalc", "hi");36expect(count).toBe(0);37});3839it("publish after waiting for interest -- this works", async () => {40await client0.waitForInterest("cocalc");41const { count, bytes } = await client0.publish("cocalc", "hi");42expect(count).toBe(1);43expect(bytes).toBe(3);44});4546it("receive", async () => {47const { value } = await sub.next();48expect(value.data).toBe("hi");49});5051it("now kill the second node", async () => {52server1.close();53});5455it("publish -- message should be dropped as soon as the server client0 is connected to notices that server1 is dead", async () => {56await wait({57until: async () => {58const { count } = await client0.publish("cocalc", "hi");59return count == 0;60},61timeout: 3000,62});63});6465it("checks addresses before deleting server1", () => {66expect(server.clusterAddresses()).toEqual([server.address()]);67});68});6970afterAll(after);717273