Skip to content

Commit 0da19a4

Browse files
committed
dofs: Cover hasObjects probe batching
1 parent 01c66cc commit 0da19a4

1 file changed

Lines changed: 24 additions & 4 deletions

File tree

packages/dofs/src/sync/fetch.test.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { describe, expect, it } from "vitest";
22

33
import { withDB } from "../fs/with-db.js";
4-
import { createFileSync, chunksOf, writeFile, writeRangeSync } from "../fs/writeFile.js";
4+
import { chunksOf, createFileSync, writeFile, writeRangeSync } from "../fs/writeFile.js";
5+
import { initializeSchema } from "../schema/index.js";
6+
import { Database } from "../storage.js";
7+
import { SQLiteTestStorage } from "../testing.js";
8+
import type { DurableObjectStorageLike, SQLCursorLike } from "../types.js";
59
import { stageBlob } from "./blobs.js";
610
import { coalesceChanges } from "./coalesce.js";
711
import { fetchChanges, fetchObjects, hasObjects } from "./fetch.js";
@@ -130,8 +134,22 @@ describe("hasObjects", () => {
130134
});
131135
});
132136

133-
it("probes more objects than Durable Object SQLite accepts in one query", async () => {
134-
await withDB(async (db) => {
137+
it("probes more objects than Durable Object SQLite accepts in one query", () => {
138+
const storage = new SQLiteTestStorage();
139+
const limitedStorage: DurableObjectStorageLike = {
140+
sql: {
141+
exec<Row extends object>(query: string, ...bindings: unknown[]): SQLCursorLike<Row> {
142+
if (bindings.length > 100) {
143+
throw new Error(`too many SQLite bindings: ${bindings.length}`);
144+
}
145+
return storage.sql.exec<Row>(query, ...bindings);
146+
},
147+
},
148+
transactionSync: (closure) => storage.transactionSync(closure),
149+
};
150+
const db = new Database(limitedStorage);
151+
initializeSchema(db, () => 1000);
152+
try {
135153
const hashes: Uint8Array[] = [];
136154
for (let i = 0; i < 101; i++) {
137155
const bytes = new TextEncoder().encode(`object-${i}`);
@@ -141,7 +159,9 @@ describe("hasObjects", () => {
141159
}
142160

143161
expect(hasObjects(db, hashes)).toEqual(hashes);
144-
});
162+
} finally {
163+
storage.close();
164+
}
145165
});
146166

147167
it("preserves input order and duplicates across mixed inputs", async () => {

0 commit comments

Comments
 (0)