Skip to content
Merged
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
4 changes: 2 additions & 2 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 21 additions & 13 deletions test/convex/repoIndexing/treeSnapshotContinuation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,24 @@ async function yieldToRuntime(): Promise<void> {
});
}

/**
* Lets the backend run until `done`, bounded by real time rather than by a
* number of steps: a cold first import of the backend modules can take longer
* than any fixed count of fake-time steps. Fake time moves at most
* `maxFakeMs`, so jobs scheduled further out never run on their own. A test
* that uses it needs a timeout above the ten-second deadline.
*/
async function runUntil(done: () => boolean, maxFakeMs: number): Promise<void> {
const deadline = process.hrtime.bigint() + 10_000_000_000n;
Comment thread
hyochan marked this conversation as resolved.
Resolved
let fakeMs = 0;
while (!done() && process.hrtime.bigint() < deadline) {
const step = fakeMs < maxFakeMs ? 1 : 0;
await advanceTestTime(step);
fakeMs += step;
await yieldToRuntime();
}
}

async function advanceTestTime(milliseconds: number): Promise<void> {
if (timerApi.advanceTimersByTimeAsync) {
await timerApi.advanceTimersByTimeAsync(milliseconds);
Expand Down Expand Up @@ -1795,12 +1813,7 @@ describe("repository tree snapshot continuations", () => {
// Let the headerless secondary limit reach the durable retry path. Keeping
// fake time below its one-minute fallback prevents convex-test from
// auto-running the job that this assertion intentionally invokes manually.
for (let attempt = 0; attempt < 20; attempt++) {
await advanceTestTime(1);
if (blobCalls.get("rate-8") === 1) {
break;
}
}
await runUntil(() => blobCalls.get("rate-8") === 1, 20);
expect(blobCalls.get("rate-8")).toBe(1);
await expect(initialIndex).resolves.toMatchObject({
success: true,
Expand Down Expand Up @@ -1832,12 +1845,7 @@ describe("repository tree snapshot continuations", () => {
rateLimitResume: true,
rateLimitRetryToken: deferred!.indexRateLimitRetryToken!,
});
for (let attempt = 0; attempt < 20; attempt++) {
await advanceTestTime(0);
if (successfulRetryPending) {
break;
}
}
await runUntil(() => successfulRetryPending, 0);
expect(successfulRetryPending).toBe(true);
await advanceTestTime(1);
const retryResult = await retry;
Expand All @@ -1852,7 +1860,7 @@ describe("repository tree snapshot continuations", () => {
expect(fileMaps).toHaveLength(10);
expect(blobCalls.get("rate-8")).toBe(2);
expect(blobCalls.get("rate-9")).toBe(1);
});
}, 30_000);

it("refetches after a late blob upload loses the publication fence", async () => {
const t = convexTest(schema, modules);
Expand Down