Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/backend/conat/test/sync/inventory.test.ts
1451 views
1
/*
2
Testing basic ops with dkv
3
4
DEVELOPMENT:
5
6
pnpm test ./inventory.test.ts
7
8
*/
9
10
import { before, after, client } from "@cocalc/backend/conat/test/setup";
11
12
beforeAll(before);
13
14
describe("test the (partial) inventory method on dkv", () => {
15
let dkv;
16
const name = `inventory-dkv`;
17
18
it("creates a kv and grabs the partial inventory", async () => {
19
dkv = await client.sync.dkv({ name });
20
const i = await dkv.kv.inventory();
21
expect(i).toEqual({
22
bytes: 0,
23
count: 0,
24
limits: {
25
allow_msg_ttl: true,
26
},
27
seq: 0,
28
});
29
});
30
31
it("set an element and see that updated in the inventory data", async () => {
32
dkv.a = 5;
33
const i = await dkv.kv.inventory();
34
expect(i).toEqual({
35
bytes: 2,
36
count: 1,
37
limits: {
38
allow_msg_ttl: true,
39
},
40
seq: 1,
41
});
42
});
43
44
it("delete an element and see that count does NOT change, because of the tombstone; bytes are larger though since it has to contain the tombstone (in a header)", async () => {
45
delete dkv.a;
46
const { bytes, count, seq } = await dkv.kv.inventory();
47
expect({ bytes, count, seq }).toEqual({
48
bytes: 23,
49
count: 1,
50
seq: 2,
51
});
52
});
53
54
it("change some limits", async () => {
55
await dkv.config({ max_age: 100000, max_bytes: 100, max_msg_size: 100 });
56
const { limits } = await dkv.kv.inventory();
57
expect(limits).toEqual({
58
allow_msg_ttl: true,
59
max_age: 100000,
60
max_bytes: 100,
61
max_msg_size: 100,
62
});
63
});
64
});
65
66
describe("test the (partial) inventory method on a dstream", () => {
67
let dstream;
68
const name = `inventory-dstream`;
69
70
it("creates a dstream and grabs the partial inventory", async () => {
71
dstream = await client.sync.dstream({ name });
72
const i = await dstream.stream.inventory();
73
expect(i).toEqual({
74
bytes: 0,
75
count: 0,
76
limits: {},
77
seq: 0,
78
});
79
});
80
81
it("publish see that updated in the inventory data", async () => {
82
dstream.publish(5);
83
await dstream.save();
84
const i = await dstream.stream.inventory();
85
expect(i).toEqual({
86
bytes: 1,
87
count: 1,
88
limits: {},
89
seq: 1,
90
});
91
});
92
93
it("publish some more", async () => {
94
dstream.push(1, 2, 3, 4);
95
await dstream.save();
96
const i = await dstream.stream.inventory();
97
expect(i).toEqual({
98
bytes: 5,
99
count: 5,
100
limits: {},
101
seq: 5,
102
});
103
});
104
105
it("change some limits", async () => {
106
await dstream.config({
107
max_age: 100000,
108
max_bytes: 100,
109
max_msg_size: 100,
110
});
111
const { limits } = await dstream.stream.inventory();
112
expect(limits).toEqual({
113
max_age: 100000,
114
max_bytes: 100,
115
max_msg_size: 100,
116
});
117
});
118
});
119
120
afterAll(after);
121
122