Skip to content
Open
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
46 changes: 46 additions & 0 deletions src/component/worker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,52 @@ describe("transaction limits", () => {
});
});

test("a cycle still drains when its last operation leaves more pending writes than the reserve", async () => {
// Every node stays under the 1 MiB document limit, even mid-split. Deleting
// key 12 merges big nodes: it reads 3.6 MiB and leaves 1.7 MiB more for
// the flush to read. The filler operations before it use up the budget so
// that the check after the last filler passes with less than that left.
const t = initConvexTest({ transactionLimits: true });
await t.run(async (ctx) => {
await getOrCreateTree(ctx.db, {}, 4, false);
});
for (let key = 0; key < 30; key++) {
await t.run(async (ctx) => {
await insertHandler(ctx, { key, value: "x".repeat(200_000) });
});
}
const fillers = 14;
for (let namespace = 0; namespace < fillers; namespace++) {
await t.run(async (ctx) => {
await getOrCreateTree(ctx.db, { namespace }, 4, false);
await insertHandler(ctx, {
key: 0,
value: "x".repeat(400_000),
namespace,
});
});
}
await enqueueRows(t, [
...Array.from({ length: fillers }, (_, namespace) => ({
type: "insert" as const,
key: 1,
value: "y",
namespace,
})),
{ type: "delete", key: 12 },
]);

await drainManually(t);
await t.run(async (ctx) => {
expect(await ctx.db.query("pendingOperations").first()).toBeNull();
expect(await ctx.db.query("deadLetterOperations").first()).toBeNull();
expect((await aggregateBetweenHandler(ctx, {})).count).toEqual(29);
expect(
(await aggregateBetweenHandler(ctx, { namespace: 0 })).count,
).toEqual(2);
});
}, 60_000);

test("an operation too big for a cycle of its own is dead-lettered", async () => {
// A 2.2 MiB budget leaves a cycle half of it. The first 400 KB insert
// fits; the second reads the first's node and rereads it to write it back.
Expand Down
Loading