Add timeout error

This commit is contained in:
Andras Schmelczer 2026-01-18 22:13:33 +00:00
parent cb2d82ab44
commit 4fb4b498a1
3 changed files with 13 additions and 4 deletions

View file

@ -80,6 +80,5 @@ And to clean up the logs & database files, run `task clean`
- [Sync server](./sync-server/README.md)
a create that has been processed by the server but got lost on the way back will create a 2nd doc if it gets edited
remove force merge everywhere

View file

@ -4,6 +4,7 @@ import { MockAgent } from "./agent/mock-agent";
import { sleep } from "./utils/sleep";
import { v4 as uuidv4 } from "uuid";
import { randomCasing } from "./utils/random-casing";
import { TimeoutError } from "./utils/with-timeout";
const TEST_ITERATIONS = 5;
const MAX_INITIAL_DOCS = 0;
@ -95,7 +96,7 @@ async function runTest({
logger.info(`Finishing up ${client.name}`);
await client.finish();
} catch (err) {
if (!slowFileEvents) {
if (err instanceof TimeoutError || !slowFileEvents) {
throw err;
}
}
@ -107,7 +108,7 @@ async function runTest({
logger.info(`Destroying ${client.name}`);
await client.destroy();
} catch (err) {
if (!slowFileEvents) {
if (err instanceof TimeoutError || !slowFileEvents) {
throw err;
}
}

View file

@ -1,3 +1,5 @@
import { __debug_locks } from "sync-client";
export async function withTimeout<T>(
promise: Promise<T>,
timeoutMs: number,
@ -8,9 +10,16 @@ export async function withTimeout<T>(
new Promise<T>((_, reject) =>
setTimeout(() => {
reject(
new Error(`${operationName} timed out after ${timeoutMs}ms`)
new TimeoutError(`${operationName} timed out after ${timeoutMs}ms ${__debug_locks.map(lock => lock.getDebugString()).join(", ")}`)
);
}, timeoutMs)
)
]);
}
export class TimeoutError extends Error {
constructor(message: string) {
super(message);
this.name = "TimeoutError";
}
}