Investigate dead-lock
This commit is contained in:
parent
564d4a6c37
commit
8adb8841ef
5 changed files with 69 additions and 11 deletions
|
|
@ -5,7 +5,10 @@ import type { RelativePath, SyncSettings } from "sync-client";
|
|||
import { debugging, Logger, LogLevel } from "sync-client";
|
||||
import { MockClient } from "./mock-client";
|
||||
import { sleep } from "../utils/sleep";
|
||||
import type { LogLine } from "sync-client/dist/types/tracing/logger";
|
||||
import type { LogLine } from "sync-client";
|
||||
import { withTimeout } from "../utils/with-timeout";
|
||||
|
||||
const TIMEOUT_MS = 10 * 60 * 1000;
|
||||
|
||||
export class MockAgent extends MockClient {
|
||||
private readonly writtenContents: string[] = [];
|
||||
|
|
@ -134,15 +137,27 @@ export class MockAgent extends MockClient {
|
|||
}
|
||||
|
||||
public async finish(): Promise<void> {
|
||||
await this.client.setSetting("isSyncEnabled", true);
|
||||
// eslint-disable-next-line no-restricted-properties
|
||||
await Promise.all(this.pendingActions);
|
||||
await this.client.waitUntilFinished();
|
||||
await withTimeout(
|
||||
(async (): Promise<void> => {
|
||||
await this.client.setSetting("isSyncEnabled", true);
|
||||
// eslint-disable-next-line no-restricted-properties
|
||||
await Promise.all(this.pendingActions);
|
||||
await this.client.waitUntilFinished();
|
||||
})(),
|
||||
TIMEOUT_MS,
|
||||
"finish()"
|
||||
);
|
||||
}
|
||||
|
||||
public async destroy(): Promise<void> {
|
||||
await this.client.waitUntilFinished();
|
||||
await this.client.destroy();
|
||||
await withTimeout(
|
||||
(async (): Promise<void> => {
|
||||
await this.client.waitUntilFinished();
|
||||
await this.client.destroy();
|
||||
})(),
|
||||
TIMEOUT_MS,
|
||||
"destroy()"
|
||||
);
|
||||
}
|
||||
|
||||
public assertFileSystemsAreConsistent(otherAgent: MockAgent): void {
|
||||
|
|
@ -184,14 +199,14 @@ export class MockAgent extends MockClient {
|
|||
);
|
||||
this.client.logger.info(
|
||||
"Local files: " +
|
||||
Array.from(otherAgent.localFiles.keys()).join(", ")
|
||||
Array.from(otherAgent.localFiles.keys()).join(", ")
|
||||
);
|
||||
otherAgent.client.logger.info(
|
||||
"Local data: " + JSON.stringify(otherAgent.data, null, 2)
|
||||
);
|
||||
otherAgent.client.logger.info(
|
||||
"Local files: " +
|
||||
Array.from(otherAgent.localFiles.keys()).join(", ")
|
||||
Array.from(otherAgent.localFiles.keys()).join(", ")
|
||||
);
|
||||
|
||||
throw e;
|
||||
|
|
|
|||
|
|
@ -71,6 +71,7 @@ async function runTest({
|
|||
// Each agent can have unpushed changes which might conflict with eachother so each has to resolve the conflicts & push, and
|
||||
for (const client of clients) {
|
||||
try {
|
||||
console.info(`Finishing up ${client.name}`);
|
||||
await client.finish();
|
||||
} catch (err) {
|
||||
if (!slowFileEvents) {
|
||||
|
|
@ -82,6 +83,7 @@ async function runTest({
|
|||
// then we need a second pass to ensure that all agents pull the same state.
|
||||
for (const client of clients) {
|
||||
try {
|
||||
console.info(`Destroying ${client.name}`);
|
||||
await client.destroy();
|
||||
} catch (err) {
|
||||
if (!slowFileEvents) {
|
||||
|
|
|
|||
23
frontend/test-client/src/utils/with-timeout.ts
Normal file
23
frontend/test-client/src/utils/with-timeout.ts
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
|
||||
export async function withTimeout<T>(
|
||||
promise: Promise<T>,
|
||||
timeoutMs: number,
|
||||
operationName: string
|
||||
): Promise<T> {
|
||||
return Promise.race([
|
||||
promise,
|
||||
new Promise<T>((_, reject) =>
|
||||
setTimeout(
|
||||
() =>
|
||||
{ reject(
|
||||
new Error(
|
||||
`${operationName} timed out after ${timeoutMs}ms`
|
||||
)
|
||||
); },
|
||||
timeoutMs
|
||||
)
|
||||
)
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue