Start fixing tests

This commit is contained in:
Andras Schmelczer 2026-01-24 11:00:55 +00:00
parent 727b6b7ed5
commit 7fcd0f0bfa
19 changed files with 210 additions and 218 deletions

View file

@ -17,7 +17,7 @@ export class MockAgent extends MockClient {
// The renamed file finding algorithm isn't too smart so we can't both update and rename the same file
private readonly doNotTouchWhileOffline: string[] = [];
private lastSyncEnabledState: boolean = true;
private lastSyncEnabledState = true;
public constructor(
initialSettings: Partial<SyncSettings>,
@ -107,14 +107,12 @@ export class MockAgent extends MockClient {
public async waitUntilSynced(): Promise<void> {
await withTimeout(
(async (): Promise<void> => {
this.client.setSetting("isSyncEnabled", true);
await this.client.setSetting("isSyncEnabled", true);
await this.client.waitUntilFinished();
})(),
TIMEOUT_MS,
"waitUntilSynced()"
);
}
public async act(): Promise<void> {

View file

@ -83,13 +83,13 @@ export class MockClient extends debugging.InMemoryFileSystem {
.map((part) => part.trim());
const newParts = newContent.split(" ").map((part) => part.trim());
existingParts.forEach((part) =>
// all changes should be additive
{
assert(
newParts.includes(part),
`Part ${part} not found in new content: ${newContent}`
);
}
// all changes should be additive
{
assert(
newParts.includes(part),
`Part ${part} not found in new content: ${newContent}`
);
}
);
}

View file

@ -80,8 +80,6 @@ async function runTest({
await utils.awaitAll(clients.map(async (client) => client.init()));
for (let i = 0; i < iterations; i++) {
logger.info(`Iteration ${i + 1}/${iterations}`);
await utils.awaitAll(clients.map(async (client) => client.act()));
@ -184,7 +182,7 @@ process.on("uncaughtException", (error) => {
}
logger.error(`Error - uncaught exception: ${error}`);
if (error instanceof Error && error.stack) {
if (error instanceof Error && error.stack != null) {
logger.error(error.stack);
}
process.exit(1);
@ -215,7 +213,7 @@ process.on("unhandledRejection", (error, _promise) => {
}
logger.error(`Error - unhandled rejection: ${error}`);
if (error instanceof Error && error.stack) {
if (error instanceof Error && error.stack != null) {
logger.error(error.stack);
}
process.exit(1);
@ -227,7 +225,7 @@ runTests()
})
.catch((error: unknown) => {
logger.error(`Error - tests failed with ${error}`);
if (error instanceof Error && error.stack) {
if (error instanceof Error && error.stack != null) {
logger.error(error.stack);
}
process.exit(1);

View file

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