Path: blob/master/src/packages/backend/conat/test/sync/inventory.test.ts
1451 views
/*1Testing basic ops with dkv23DEVELOPMENT:45pnpm test ./inventory.test.ts67*/89import { before, after, client } from "@cocalc/backend/conat/test/setup";1011beforeAll(before);1213describe("test the (partial) inventory method on dkv", () => {14let dkv;15const name = `inventory-dkv`;1617it("creates a kv and grabs the partial inventory", async () => {18dkv = await client.sync.dkv({ name });19const i = await dkv.kv.inventory();20expect(i).toEqual({21bytes: 0,22count: 0,23limits: {24allow_msg_ttl: true,25},26seq: 0,27});28});2930it("set an element and see that updated in the inventory data", async () => {31dkv.a = 5;32const i = await dkv.kv.inventory();33expect(i).toEqual({34bytes: 2,35count: 1,36limits: {37allow_msg_ttl: true,38},39seq: 1,40});41});4243it("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 () => {44delete dkv.a;45const { bytes, count, seq } = await dkv.kv.inventory();46expect({ bytes, count, seq }).toEqual({47bytes: 23,48count: 1,49seq: 2,50});51});5253it("change some limits", async () => {54await dkv.config({ max_age: 100000, max_bytes: 100, max_msg_size: 100 });55const { limits } = await dkv.kv.inventory();56expect(limits).toEqual({57allow_msg_ttl: true,58max_age: 100000,59max_bytes: 100,60max_msg_size: 100,61});62});63});6465describe("test the (partial) inventory method on a dstream", () => {66let dstream;67const name = `inventory-dstream`;6869it("creates a dstream and grabs the partial inventory", async () => {70dstream = await client.sync.dstream({ name });71const i = await dstream.stream.inventory();72expect(i).toEqual({73bytes: 0,74count: 0,75limits: {},76seq: 0,77});78});7980it("publish see that updated in the inventory data", async () => {81dstream.publish(5);82await dstream.save();83const i = await dstream.stream.inventory();84expect(i).toEqual({85bytes: 1,86count: 1,87limits: {},88seq: 1,89});90});9192it("publish some more", async () => {93dstream.push(1, 2, 3, 4);94await dstream.save();95const i = await dstream.stream.inventory();96expect(i).toEqual({97bytes: 5,98count: 5,99limits: {},100seq: 5,101});102});103104it("change some limits", async () => {105await dstream.config({106max_age: 100000,107max_bytes: 100,108max_msg_size: 100,109});110const { limits } = await dstream.stream.inventory();111expect(limits).toEqual({112max_age: 100000,113max_bytes: 100,114max_msg_size: 100,115});116});117});118119afterAll(after);120121122