Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/backend/conat/test/sync/connectivity.test.ts
1712 views
1
/*
2
Tests that various sync functionality works after restarting the conat server.
3
4
pnpm test ./connectivity.test.ts
5
6
*/
7
8
import { dkv } from "@cocalc/backend/conat/sync";
9
import {
10
before,
11
after,
12
restartServer,
13
restartPersistServer,
14
setDefaultTimeouts,
15
} from "@cocalc/backend/conat/test/setup";
16
17
beforeAll(async () => {
18
await before();
19
// some tests below will randomly sometimes take longer than 5s without this:
20
setDefaultTimeouts({ request: 1000, publish: 1000 });
21
});
22
23
jest.setTimeout(10000);
24
describe("test that dkv survives server restart", () => {
25
let kv;
26
const name = `test-${Math.random()}`;
27
28
it("right as it restarts, creates the dkv and does a basic test", async () => {
29
kv = await dkv({ name });
30
kv.a = 10;
31
expect(kv.a).toEqual(10);
32
await kv.save();
33
expect(kv.hasUnsavedChanges()).toBe(false);
34
});
35
36
it("restart the socketio server and confirm that dkv still works", async () => {
37
await restartServer();
38
kv.b = 7;
39
expect(kv.b).toEqual(7);
40
await kv.save();
41
expect(kv.hasUnsavedChanges()).toBe(false);
42
});
43
44
it("restart again (without await) the socketio server and confirm that dkv still works", async () => {
45
restartServer();
46
kv.b = 77;
47
expect(kv.b).toEqual(77);
48
await kv.save();
49
expect(kv.hasUnsavedChanges()).toBe(false);
50
});
51
52
it("restart persist server", async () => {
53
await restartPersistServer();
54
kv.b = 123;
55
expect(kv.b).toEqual(123);
56
await kv.save();
57
expect(kv.hasUnsavedChanges()).toBe(false);
58
});
59
60
jest.setTimeout(10000);
61
it("restart both servers at once", async () => {
62
await Promise.all([restartPersistServer(), restartServer()]);
63
kv.b = 389;
64
expect(kv.b).toEqual(389);
65
await kv.save();
66
expect(kv.hasUnsavedChanges()).toBe(false);
67
});
68
});
69
70
afterAll(after);
71
72