Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions test/kv.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ test("KV: iterate reverse order", async () => {
// Act: Iterate in reverse
const results: KVTransactionResult<unknown>[] = [];
for await (
const entry of kvStore.iterate(["data"], undefined, { reverse: true })
const entry of kvStore.iterate(["data"], undefined, true)
) {
results.push(entry);
}
Expand All @@ -972,7 +972,7 @@ test("KV: iterate reverse with limit", async () => {
// Act: Iterate in reverse with limit
const results: KVTransactionResult<unknown>[] = [];
for await (
const entry of kvStore.iterate(["data"], 2, { reverse: true })
const entry of kvStore.iterate(["data"], 2, true)
) {
results.push(entry);
}
Expand Down Expand Up @@ -1036,7 +1036,7 @@ test("KV: listAll reverse", async () => {
await kvStore.set(["data", 3], "Value 3");

// Act: List in reverse
const results = await kvStore.listAll(["data"], undefined, { reverse: true });
const results = await kvStore.listAll(["data"], undefined, true);

// Assert: Should return in reverse order
assertEquals(results.length, 3);
Expand Down Expand Up @@ -1225,7 +1225,7 @@ test("KV: has returns true for existing key", async () => {
await kvStore.set(["test"], "value");

// Act
const exists = kvStore.has(["test"]);
const exists = kvStore.count(["test"]) > 0;

// Assert
assertEquals(exists, true);
Expand All @@ -1240,7 +1240,7 @@ test("KV: has returns false for non-existing key", async () => {
await kvStore.open(tempFilePrefix);

// Act
const exists = kvStore.has(["nonexistent"]);
const exists = kvStore.count(["nonexistent"]) > 0;

// Assert
assertEquals(exists, false);
Expand Down
30 changes: 15 additions & 15 deletions test/ledger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,27 +81,27 @@ test("KVLedger: lock acquisition", async () => {
await ledger.open();

// Act: Acquire lock
await ledger.lock();
const lockId = await ledger.lock();

// Assert: Verify lock is acquired
const isLocked = await ledger.verifyLock();
const isLocked = await ledger.verifyLock(lockId);
assertEquals(isLocked, true);

await ledger.unlock();
await ledger.unlock(lockId);
});

test("KVLedger: unlock releases lock", async () => {
// Arrange
const tempFilePrefix = await tempfile();
const ledger = new KVLedger(tempFilePrefix, 100);
await ledger.open();
await ledger.lock();
const lockId = await ledger.lock();

// Act: Release lock
await ledger.unlock();
await ledger.unlock(lockId);

// Assert: Verify lock is released
const isLocked = await ledger.verifyLock();
const isLocked = await ledger.verifyLock(lockId);
assertEquals(isLocked, false);
});

Expand All @@ -110,13 +110,13 @@ test("KVLedger: verifyLock passes after lock", async () => {
const tempFilePrefix = await tempfile();
const ledger = new KVLedger(tempFilePrefix, 100);
await ledger.open();
await ledger.lock();
const lockId = await ledger.lock();

// Act & Assert: Verify should pass
const result = await ledger.verifyLock();
const result = await ledger.verifyLock(lockId);
assertEquals(result, true);

await ledger.unlock();
await ledger.unlock(lockId);
});

test("KVLedger: verifyLock fails when not locked", async () => {
Expand All @@ -125,8 +125,8 @@ test("KVLedger: verifyLock fails when not locked", async () => {
const ledger = new KVLedger(tempFilePrefix, 100);
await ledger.open();

// Act & Assert: Verify should fail without lock
const result = await ledger.verifyLock();
// Act & Assert: Verify should fail without lock (use non-zero lockId)
const result = await ledger.verifyLock(BigInt(12345));
assertEquals(result, false);
});

Expand All @@ -139,13 +139,13 @@ test("KVLedger: multiple lock attempts", async () => {
await ledger2.open();

// Act: First ledger acquires lock
await ledger1.lock();
const lockId = await ledger1.lock();

// Assert: Second ledger should see it's locked
const canLock = await ledger2.verifyLock();
// Assert: Second ledger cannot verify a different lock
const canLock = await ledger2.verifyLock(BigInt(99999));
assertEquals(canLock, false);

await ledger1.unlock();
await ledger1.unlock(lockId);
});

test("KVLedger: cache stores and retrieves transactions", async () => {
Expand Down
6 changes: 3 additions & 3 deletions test/transaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ test("KVTransaction: roundtrip with Date value", async () => {
await decoded.dataFromUint8Array(transaction.data!);

// Assert
assertEquals(decoded.asResult().data.getTime(), value.getTime());
assertEquals((decoded.asResult().data as Date).getTime(), value.getTime());
});

test("KVTransaction: roundtrip with Map value", async () => {
Expand Down Expand Up @@ -183,7 +183,7 @@ test("KVTransaction: roundtrip with Map value", async () => {
await decoded.dataFromUint8Array(transaction.data!);

// Assert
const result = decoded.asResult().data;
const result = decoded.asResult().data as Map<string, string>;
assertEquals(result instanceof Map, true);
assertEquals(result.get("theme"), "dark");
assertEquals(result.get("lang"), "en");
Expand Down Expand Up @@ -218,7 +218,7 @@ test("KVTransaction: roundtrip with Set value", async () => {
await decoded.dataFromUint8Array(transaction.data!);

// Assert
const result = decoded.asResult().data;
const result = decoded.asResult().data as Set<string>;
assertEquals(result instanceof Set, true);
assertEquals(result.has("javascript"), true);
assertEquals(result.has("typescript"), true);
Expand Down
Loading