Fix test
This commit is contained in:
parent
62427183fd
commit
a8cadd1e53
4 changed files with 27 additions and 24 deletions
|
|
@ -7,7 +7,7 @@ export {
|
||||||
export { Logger, LogLevel, LogLine } from "./tracing/logger";
|
export { Logger, LogLevel, LogLine } from "./tracing/logger";
|
||||||
export type { CheckConnectionResult } from "./services/sync-service";
|
export type { CheckConnectionResult } from "./services/sync-service";
|
||||||
export { type SyncSettings } from "./persistence/settings";
|
export { type SyncSettings } from "./persistence/settings";
|
||||||
export type { RelativePath } from "./persistence/database";
|
export type { RelativePath, StoredDatabase } from "./persistence/database";
|
||||||
export type { FileSystemOperations } from "./file-operations/filesystem-operations";
|
export type { FileSystemOperations } from "./file-operations/filesystem-operations";
|
||||||
export type { PersistenceProvider } from "./persistence/persistence";
|
export type { PersistenceProvider } from "./persistence/persistence";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -173,8 +173,7 @@ export class SyncClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async waitAndStop(): Promise<void> {
|
public async waitAndStop(): Promise<void> {
|
||||||
await this.syncer.applyRemoteChangesLocally();
|
await this.syncer.waitUntilFinished();
|
||||||
await this.syncer.waitForSyncQueue();
|
|
||||||
this.stop();
|
this.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import type { Database, RelativePath } from "../persistence/database";
|
import type { Database, RelativePath } from "../persistence/database";
|
||||||
import type { SyncService } from "../services/sync-service";
|
import type { SyncService } from "../services/sync-service";
|
||||||
import type { Logger } from "../tracing/logger";
|
import type { Logger } from "../tracing/logger";
|
||||||
import type { SyncHistory } from "../tracing/sync-history";
|
|
||||||
import PQueue from "p-queue";
|
import PQueue from "p-queue";
|
||||||
import { hash } from "../utils/hash";
|
import { hash } from "../utils/hash";
|
||||||
import { v4 as uuidv4 } from "uuid";
|
import { v4 as uuidv4 } from "uuid";
|
||||||
|
|
@ -9,7 +8,7 @@ import type { components } from "../services/types";
|
||||||
import type { Settings } from "../persistence/settings";
|
import type { Settings } from "../persistence/settings";
|
||||||
import type { FileOperations } from "../file-operations/file-operations";
|
import type { FileOperations } from "../file-operations/file-operations";
|
||||||
import { findMatchingFile } from "../utils/find-matching-file";
|
import { findMatchingFile } from "../utils/find-matching-file";
|
||||||
import { UnrestrictedSyncer } from "./unrestricted-syncer";
|
import type { UnrestrictedSyncer } from "./unrestricted-syncer";
|
||||||
import { createPromise } from "../utils/create-promise";
|
import { createPromise } from "../utils/create-promise";
|
||||||
import { SyncResetError } from "../services/sync-reset-error";
|
import { SyncResetError } from "../services/sync-reset-error";
|
||||||
|
|
||||||
|
|
@ -17,21 +16,18 @@ export class Syncer {
|
||||||
private readonly remainingOperationsListeners: ((
|
private readonly remainingOperationsListeners: ((
|
||||||
remainingOperations: number
|
remainingOperations: number
|
||||||
) => void)[] = [];
|
) => void)[] = [];
|
||||||
|
|
||||||
private readonly syncQueue: PQueue;
|
private readonly syncQueue: PQueue;
|
||||||
|
|
||||||
private runningScheduleSyncForOfflineChanges: Promise<void> | undefined;
|
private runningScheduleSyncForOfflineChanges: Promise<void> | undefined;
|
||||||
private runningApplyRemoteChangesLocally: Promise<void> | undefined;
|
private runningApplyRemoteChangesLocally: Promise<void> | undefined;
|
||||||
|
|
||||||
private readonly internalSyncer: UnrestrictedSyncer;
|
|
||||||
|
|
||||||
public constructor(
|
public constructor(
|
||||||
private readonly logger: Logger,
|
private readonly logger: Logger,
|
||||||
private readonly database: Database,
|
private readonly database: Database,
|
||||||
settings: Settings,
|
settings: Settings,
|
||||||
private readonly syncService: SyncService,
|
private readonly syncService: SyncService,
|
||||||
private readonly operations: FileOperations,
|
private readonly operations: FileOperations,
|
||||||
history: SyncHistory
|
private readonly internalSyncer: UnrestrictedSyncer
|
||||||
) {
|
) {
|
||||||
this.syncQueue = new PQueue({
|
this.syncQueue = new PQueue({
|
||||||
concurrency: settings.getSettings().syncConcurrency
|
concurrency: settings.getSettings().syncConcurrency
|
||||||
|
|
@ -49,15 +45,6 @@ export class Syncer {
|
||||||
listener(this.syncQueue.size);
|
listener(this.syncQueue.size);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
this.internalSyncer = new UnrestrictedSyncer(
|
|
||||||
logger,
|
|
||||||
database,
|
|
||||||
settings,
|
|
||||||
syncService,
|
|
||||||
operations,
|
|
||||||
history
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public addRemainingOperationsListener(
|
public addRemainingOperationsListener(
|
||||||
|
|
@ -246,13 +233,17 @@ export class Syncer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async waitForSyncQueue(): Promise<void> {
|
public async reset(): Promise<void> {
|
||||||
return this.syncQueue.onEmpty();
|
await this.waitUntilFinished();
|
||||||
|
this.internalSyncer.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async reset(): Promise<void> {
|
public async waitUntilFinished(): Promise<void> {
|
||||||
await this.syncQueue.onEmpty();
|
await Promise.allSettled([
|
||||||
this.internalSyncer.reset();
|
this.runningScheduleSyncForOfflineChanges,
|
||||||
|
this.runningApplyRemoteChangesLocally
|
||||||
|
]);
|
||||||
|
return this.syncQueue.onEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async internalApplyRemoteChangesLocally(): Promise<void> {
|
private async internalApplyRemoteChangesLocally(): Promise<void> {
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import type { StoredDatabase } from "sync-client/dist/types/persistence/database";
|
||||||
import { assert } from "../utils/assert";
|
import { assert } from "../utils/assert";
|
||||||
import {
|
import {
|
||||||
type RelativePath,
|
type RelativePath,
|
||||||
|
|
@ -9,7 +10,17 @@ import {
|
||||||
export class MockClient implements FileSystemOperations {
|
export class MockClient implements FileSystemOperations {
|
||||||
protected readonly localFiles = new Map<string, Uint8Array>();
|
protected readonly localFiles = new Map<string, Uint8Array>();
|
||||||
protected client!: SyncClient;
|
protected client!: SyncClient;
|
||||||
protected data: object | undefined = undefined;
|
|
||||||
|
protected data: Partial<{
|
||||||
|
settings: Partial<SyncSettings>;
|
||||||
|
database: Partial<StoredDatabase>;
|
||||||
|
}> = {
|
||||||
|
database: {
|
||||||
|
// Assume all clients start at the same time so there's no need to fetch
|
||||||
|
// any shared state.
|
||||||
|
hasInitialSyncCompleted: true
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
public constructor(
|
public constructor(
|
||||||
private readonly initialSettings: Partial<SyncSettings>,
|
private readonly initialSettings: Partial<SyncSettings>,
|
||||||
|
|
@ -37,6 +48,8 @@ export class MockClient implements FileSystemOperations {
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
await this.client.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async listAllFiles(): Promise<RelativePath[]> {
|
public async listAllFiles(): Promise<RelativePath[]> {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue