From ec610c77fbbec9c826a677c609f170812a42d82f Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Tue, 20 May 2025 20:08:02 +0100 Subject: [PATCH] Randomise slow file event length --- frontend/test-client/src/agent/mock-client.ts | 14 +++++++------- frontend/test-client/src/cli.ts | 1 + 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/frontend/test-client/src/agent/mock-client.ts b/frontend/test-client/src/agent/mock-client.ts index 766e7981..ae465473 100644 --- a/frontend/test-client/src/agent/mock-client.ts +++ b/frontend/test-client/src/agent/mock-client.ts @@ -78,7 +78,7 @@ export class MockClient implements FileSystemOperations { ); this.localFiles.set(path, newContent); - this.runCallback(() => { + this.executeFileOperation(() => { void this.client.syncLocallyCreatedFile(path); }); } @@ -120,7 +120,7 @@ export class MockClient implements FileSystemOperations { `Updated file ${path} with:\n current content: ${currentContent}\n new content: ${newContent}` ); - this.runCallback(() => { + this.executeFileOperation(() => { void this.client.syncLocallyUpdatedFile({ relativePath: path }); @@ -137,7 +137,7 @@ export class MockClient implements FileSystemOperations { `Updated file ${path} with:\n new content: ${new TextDecoder().decode(content)}` ); - this.runCallback(() => { + this.executeFileOperation(() => { if (hasExisted) { void this.client.syncLocallyUpdatedFile({ relativePath: path @@ -154,7 +154,7 @@ export class MockClient implements FileSystemOperations { ); this.localFiles.delete(path); - this.runCallback(() => { + this.executeFileOperation(() => { void this.client.syncLocallyDeletedFile(path); }); } @@ -176,7 +176,7 @@ export class MockClient implements FileSystemOperations { `Renamed file: ${oldPath} -> ${newPath} with:\n content ${new TextDecoder().decode(file)}` ); - this.runCallback(() => { + this.executeFileOperation(() => { void this.client.syncLocallyUpdatedFile({ oldPath, relativePath: newPath @@ -184,10 +184,10 @@ export class MockClient implements FileSystemOperations { }); } - private runCallback(callback: () => void): void { + private executeFileOperation(callback: () => void): void { if (this.useSlowFileEvents) { // we aren't the best client and it takes some time to notice changes - setTimeout(callback, 100); + setTimeout(callback, Math.random() * 100); } else { callback(); } diff --git a/frontend/test-client/src/cli.ts b/frontend/test-client/src/cli.ts index ce941b00..6e5ede93 100644 --- a/frontend/test-client/src/cli.ts +++ b/frontend/test-client/src/cli.ts @@ -4,6 +4,7 @@ import { sleep } from "./utils/sleep"; import { v4 as uuidv4 } from "uuid"; import { randomCasing } from "./utils/random-casing"; +// Simulate async file access by injecting waiting time before returning from file operations. let slowFileEvents = false; async function runTest({