Use locks
This commit is contained in:
parent
4fb4b498a1
commit
727b6b7ed5
10 changed files with 245 additions and 317 deletions
|
|
@ -9,7 +9,7 @@ import { sleep } from "../utils/sleep";
|
|||
import type { LogLine } from "sync-client";
|
||||
import { withTimeout } from "../utils/with-timeout";
|
||||
|
||||
const TIMEOUT_MS = 10 * 60 * 1000;
|
||||
const TIMEOUT_MS = 2 * 60 * 1000;
|
||||
|
||||
export class MockAgent extends MockClient {
|
||||
private readonly writtenContents: string[] = [];
|
||||
|
|
@ -105,7 +105,16 @@ export class MockAgent extends MockClient {
|
|||
}
|
||||
|
||||
public async waitUntilSynced(): Promise<void> {
|
||||
await this.client.waitUntilFinished();
|
||||
await withTimeout(
|
||||
(async (): Promise<void> => {
|
||||
this.client.setSetting("isSyncEnabled", true);
|
||||
await this.client.waitUntilFinished();
|
||||
})(),
|
||||
TIMEOUT_MS,
|
||||
"waitUntilSynced()"
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public async act(): Promise<void> {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import { randomCasing } from "./utils/random-casing";
|
|||
import { TimeoutError } from "./utils/with-timeout";
|
||||
|
||||
const TEST_ITERATIONS = 5;
|
||||
const MAX_INITIAL_DOCS = 0;
|
||||
const MAX_INITIAL_DOCS = 10;
|
||||
|
||||
// Simulate async file access by injecting waiting time before returning from file operations.
|
||||
let slowFileEvents = false;
|
||||
|
|
@ -90,10 +90,11 @@ async function runTest({
|
|||
|
||||
logger.info("Stopping agents");
|
||||
|
||||
// Each agent can have unpushed changes which might conflict with eachother so each has to resolve the conflicts & push, and
|
||||
// Each agent can have unpushed changes which might conflict with eachother so each has to resolve the conflicts & push, and pull
|
||||
for (const client of clients) {
|
||||
try {
|
||||
logger.info(`Finishing up ${client.name}`);
|
||||
await client.waitUntilSynced();
|
||||
await client.finish();
|
||||
} catch (err) {
|
||||
if (err instanceof TimeoutError || !slowFileEvents) {
|
||||
|
|
@ -102,7 +103,7 @@ async function runTest({
|
|||
}
|
||||
}
|
||||
|
||||
// then we need a second pass to ensure that all agents pull the same state.
|
||||
// then we need a second pass to ensure that all agents pull the same state
|
||||
for (const client of clients) {
|
||||
try {
|
||||
logger.info(`Destroying ${client.name}`);
|
||||
|
|
@ -183,6 +184,9 @@ process.on("uncaughtException", (error) => {
|
|||
}
|
||||
|
||||
logger.error(`Error - uncaught exception: ${error}`);
|
||||
if (error instanceof Error && error.stack) {
|
||||
logger.error(error.stack);
|
||||
}
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
|
|
@ -211,6 +215,9 @@ process.on("unhandledRejection", (error, _promise) => {
|
|||
}
|
||||
|
||||
logger.error(`Error - unhandled rejection: ${error}`);
|
||||
if (error instanceof Error && error.stack) {
|
||||
logger.error(error.stack);
|
||||
}
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue