Skip to content

Commit

Permalink
Merge pull request #17 from mikebryant/add-test-case-partial-prefix-p…
Browse files Browse the repository at this point in the history
…runing

test: Add case for pruning only the older entries
  • Loading branch information
sgwilym authored Apr 21, 2024
2 parents fb419af + d18e8ae commit 85ffc50
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions src/store/store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,66 @@ Deno.test("Store.ingestEntry", async (test) => {
assert(entries[0][1]);
assertEquals(await entries[0][1].bytes(), new Uint8Array([0, 1, 2, 3]));
});

await test.step("replaces older entries with paths prefixed by the new one, but doesn't replace newer entries", async () => {
const store = new TestStore();

await store.set(
{
path: [new Uint8Array([0]), new Uint8Array([1])],
payload: new Uint8Array([0, 1, 0]),
timestamp: BigInt(0),
subspace: alfie,
},
alfie,
);

await store.set(
{
path: [new Uint8Array([0]), new Uint8Array([2])],
payload: new Uint8Array([0, 2, 2]),
timestamp: BigInt(2),
subspace: alfie,
},
alfie,
);

const prefixRes = await store.set(
{
path: [new Uint8Array([0])],
payload: new Uint8Array([0, 2]),
timestamp: BigInt(1),
subspace: alfie,
},
alfie,
);

assert(prefixRes.kind === "success");

const entries = [];

for await (
const entry of store.query({
area: fullArea(),
maxCount: 0,
maxSize: BigInt(0),
}, "path")
) {
entries.push(entry);
}

assertEquals(entries.length, 2);

assert(entries[0]);
assertEquals(entries[0][0].path, [new Uint8Array([0])]);
assert(entries[0][1]);
assertEquals(await entries[0][1].bytes(), new Uint8Array([0, 2]));

assert(entries[1]);
assertEquals(entries[1][0].path, [new Uint8Array([0]), new Uint8Array([2])]);
assert(entries[1][1]);
assertEquals(await entries[1][1].bytes(), new Uint8Array([0, 2, 2]));
});
});

// ==================================
Expand Down

0 comments on commit 85ffc50

Please sign in to comment.