Path: blob/master/src/packages/backend/conat/test/persist/persist-client-restarts.test.ts
1712 views
/*1Tests of persist client.23pnpm test ./persist-client-restarts.test.ts45*/67import {8before,9after,10connect,11restartServer,12restartPersistServer,13wait,14} from "@cocalc/backend/conat/test/setup";15import { stream } from "@cocalc/conat/persist/client";16import { messageData } from "@cocalc/conat/core/client";1718beforeAll(before);1920jest.setTimeout(15000);21describe("restarting the network and/or persist server, but with no delay afterwards", () => {22let client, s1;2324it("creates a client, stream and test data", async () => {25client = connect();26s1 = stream({27client,28user: { hub_id: "x" },29storage: { path: "hub/network" },30});31await s1.set({32key: "test",33messageData: messageData("data"),34});35const mesg = await s1.get({ key: "test" });36expect(mesg.data).toBe("data");37});3839it("restart conat networking", async () => {40await restartServer();41});4243it("it start working again after restart of socketio server only, though we expect some errors", async () => {44try {45await s1.get({ key: "test", timeout: 500 });46} catch {}47await wait({48until: async () => {49try {50await s1.get({ key: "test", timeout: 500 });51return true;52} catch {53return false;54}55},56});57const mesg = await s1.get({ key: "test" });58expect(mesg.data).toBe("data");59});6061it("restarts just persist server", () => {62restartPersistServer();63});6465it("it starts working again after restart after persist server only, though we expect some errors", async () => {66await wait({67until: async () => {68try {69await s1.set({70key: "test-5",71messageData: messageData("data", { headers: { foo: "bar" } }),72timeout: 500,73});74return true;75} catch (err) {76return false;77}78},79});80const mesg = await s1.get({ key: "test-5" });81expect(mesg.data).toBe("data");82});8384it("restarts BOTH the socketio server and the persist server", () => {85restartServer();86restartPersistServer();87});8889it("it starts working again after restart of BOTH servers, though we expect some errors", async () => {90await wait({91timeout: 15000,92until: async () => {93try {94await s1.set({95key: "test-10",96messageData: messageData("data", { headers: { foo: "bar" } }),97timeout: 500,98});99return true;100} catch (err) {101return false;102}103},104});105const mesg = await s1.get({ key: "test-10" });106expect(mesg.data).toBe("data");107});108});109110afterAll(after);111112113