From 10568efebecbec703541378c0035ca31e045401a Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Sun, 16 Mar 2025 19:49:09 +0000 Subject: [PATCH] Clean up diff --- backend/sync_server/src/database.rs | 2 -- .../src/file-operations/file-operations.ts | 2 +- frontend/sync-client/src/services/types.ts | 9 +++-- .../sync-client/src/sync-operations/syncer.ts | 26 +------------- frontend/test-client/src/agent/mock-agent.ts | 7 ++-- frontend/test-client/src/cli.ts | 36 +++++++++---------- 6 files changed, 25 insertions(+), 57 deletions(-) diff --git a/backend/sync_server/src/database.rs b/backend/sync_server/src/database.rs index 123f1c8a..882bd0a2 100644 --- a/backend/sync_server/src/database.rs +++ b/backend/sync_server/src/database.rs @@ -23,7 +23,6 @@ pub type Transaction<'a> = sqlx::Transaction<'a, Sqlite>; impl Database { pub async fn try_new(config: &DatabaseConfig) -> Result { - // Create the databases directory if it doesn't exist tokio::fs::create_dir_all(&config.databases_directory_path) .await .with_context(|| { @@ -67,7 +66,6 @@ impl Database { .databases_directory_path .join(format!("{vault}.sqlite")); - // Continue with database connection setup let connection_options = SqliteConnectOptions::new() .filename(file_name.clone()) .create_if_missing(true) diff --git a/frontend/sync-client/src/file-operations/file-operations.ts b/frontend/sync-client/src/file-operations/file-operations.ts index 01084647..b198caa4 100644 --- a/frontend/sync-client/src/file-operations/file-operations.ts +++ b/frontend/sync-client/src/file-operations/file-operations.ts @@ -107,7 +107,7 @@ export class FileOperations { currentText = currentText.replace(/\r\n/g, "\n"); if (currentText !== expectedText) { this.logger.debug( - `Performing a 3-way merge for ${path} with the expected content:\n${expectedText}` + `Performing a 3-way merge for ${path} with the expected content` ); return mergeText(expectedText, currentText, newText); diff --git a/frontend/sync-client/src/services/types.ts b/frontend/sync-client/src/services/types.ts index 5c464075..e8a954f3 100644 --- a/frontend/sync-client/src/services/types.ts +++ b/frontend/sync-client/src/services/types.ts @@ -452,7 +452,10 @@ export interface components { Array_of_uint8: number[]; CreateDocumentVersion: { contentBase64: string; - /** Format: uuid */ + /** + * Format: uuid + * @description The client can decide the document id (if it wishes to) in order to help with syncing. If the client does not provide a document id, the server will generate one. If the client provides a document id it must not already exist in the database. + */ documentId?: string | null; relativePath: string; }; @@ -476,7 +479,6 @@ export interface components { type: "FastForwardUpdate"; /** Format: date-time */ updatedDate: string; - vaultId: string; /** Format: int64 */ vaultUpdateId: number; } @@ -490,7 +492,6 @@ export interface components { type: "MergingUpdate"; /** Format: date-time */ updatedDate: string; - vaultId: string; /** Format: int64 */ vaultUpdateId: number; }; @@ -502,7 +503,6 @@ export interface components { relativePath: string; /** Format: date-time */ updatedDate: string; - vaultId: string; /** Format: int64 */ vaultUpdateId: number; }; @@ -513,7 +513,6 @@ export interface components { relativePath: string; /** Format: date-time */ updatedDate: string; - vaultId: string; /** Format: int64 */ vaultUpdateId: number; }; diff --git a/frontend/sync-client/src/sync-operations/syncer.ts b/frontend/sync-client/src/sync-operations/syncer.ts index e882004f..70ba88d5 100644 --- a/frontend/sync-client/src/sync-operations/syncer.ts +++ b/frontend/sync-client/src/sync-operations/syncer.ts @@ -60,24 +60,6 @@ export class Syncer { ); } - private static async forgivingFileNotFoundWrapper( - fn: () => Promise, - logger: Logger - ): Promise { - try { - return await fn(); - } catch (e) { - if (e instanceof FileNotFoundError) { - logger.debug( - `File has been deleted or moved before we had a chance to inspect it, skipping` - ); - return undefined; - } - - throw e; - } - } - public addRemainingOperationsListener( listener: (remainingOperations: number) => void ): void { @@ -355,13 +337,7 @@ export class Syncer { // Perhaps the file has been moved; let's check by looking at the deleted files const contentHash = await this.syncQueue.add(async () => { const contentBytes = - await Syncer.forgivingFileNotFoundWrapper( - async () => this.operations.read(relativePath), - this.logger - ); - if (contentBytes === undefined) { - return; - } + await this.operations.read(relativePath); // this can throw FileNotFoundError return hash(contentBytes); }); diff --git a/frontend/test-client/src/agent/mock-agent.ts b/frontend/test-client/src/agent/mock-agent.ts index 2dc4ec99..7713b524 100644 --- a/frontend/test-client/src/agent/mock-agent.ts +++ b/frontend/test-client/src/agent/mock-agent.ts @@ -251,10 +251,7 @@ export class MockAgent extends MockClient { `Decided to create file ${file} with content ${content}` ); - return this.create( - file, - new TextEncoder().encode(` |${content}| `) - ); + return this.create(file, new TextEncoder().encode(` ${content} `)); } private async changeFetchChangesUpdateIntervalMsAction(): Promise { @@ -328,7 +325,7 @@ export class MockAgent extends MockClient { `Decided to update file ${file} with ${content}` ); this.doNotTouchWhileOffline.push(file); - await this.atomicUpdateText(file, (old) => old + ` |${content}| `); + await this.atomicUpdateText(file, (old) => old + ` ${content} `); } private async deleteFileAction(files: RelativePath[]): Promise { diff --git a/frontend/test-client/src/cli.ts b/frontend/test-client/src/cli.ts index 85fb3c43..326ebb99 100644 --- a/frontend/test-client/src/cli.ts +++ b/frontend/test-client/src/cli.ts @@ -46,10 +46,6 @@ async function runTest({ ); } - // for debugging - // eslint-disable-next-line - (globalThis as any).clients = clients; - try { await Promise.all(clients.map(async (client) => client.init())); @@ -109,20 +105,22 @@ async function runTest({ } async function runTests(): Promise { - for (const concurrency of [ - 16, - 1 // test with concurrency 1 to check for deadlocks - ]) { - for (const doDeletes of [true, false]) { - for (const useSlowFileEvents of [true, false]) { - await runTest({ - agentCount: 4, - concurrency, - iterations: 200, - doDeletes, - useSlowFileEvents, - jitterScaleInSeconds: 0.75 - }); + for (const useSlowFileEvents of [false, true]) { + for (const concurrency of [ + 16, + 1 // test with concurrency 1 to check for deadlocks + ]) { + for (const doDeletes of [true, false]) { + for (let i = 0; i < 4; i++) { + await runTest({ + agentCount: 2, + concurrency, + iterations: 200, + doDeletes, + useSlowFileEvents, + jitterScaleInSeconds: 0.75 + }); + } } } } @@ -148,7 +146,7 @@ runTests() .then(() => { process.exit(0); }) - .catch(async (err: unknown) => { + .catch((err: unknown) => { console.error(err); process.exit(1); });