Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/backend/conat/test/persist/persist-dstream.test.ts
1451 views
1
/*
2
Testing things about dstream that involve persistence.
3
*/
4
5
import {
6
before,
7
after,
8
connect,
9
delay,
10
} from "@cocalc/backend/conat/test/setup";
11
12
beforeAll(before);
13
14
describe("create a dstream, write data, close it, then open it again and see data persisted", () => {
15
let client;
16
const name = "foo";
17
it("create clients and a document", async () => {
18
client = connect();
19
const v = await client.sync.dstream({ name });
20
v.publish("x");
21
await v.save();
22
v.close();
23
});
24
25
it("opening again and see that it persisted", async () => {
26
const v = await client.sync.dstream({ name });
27
expect(v.getAll()).toEqual(["x"]);
28
});
29
});
30
31
// this is here because I had a bug in the syncRefCache that this exposed.
32
describe("just like above, create a dstream, write data, close it, then open it again and see data persisted -- **but do it all in the same function**", () => {
33
let client;
34
const name = "foo2";
35
it("create clients and a document", async () => {
36
client = connect();
37
const v = await client.sync.dstream({ name });
38
v.publish("x");
39
await v.save();
40
v.close();
41
const w = await client.sync.dstream({ name });
42
expect(w.getAll()).toEqual(["x"]);
43
w.close();
44
});
45
});
46
47
afterAll(async () => {
48
await delay(100);
49
after();
50
});
51
52