Add initial documents before starting

This commit is contained in:
Andras Schmelczer 2026-01-13 20:28:06 +00:00
parent 0e1849061b
commit bd8650e80b
3 changed files with 35 additions and 1 deletions

View file

@ -90,6 +90,29 @@ export class MockAgent extends MockClient {
this.client.logger.info("Agent initialized");
}
public async createInitialDocuments(count: number): Promise<void> {
this.client.logger.info(`Creating ${count} initial documents`);
for (let i = 0; i < count; i++) {
const file = `initial-${i}.md`;
const content = this.getContent();
this.client.logger.info(
`Creating initial file ${file} with content ${content}`
);
await this.create(file, new TextEncoder().encode(` ${content} `), {
ignoreSlowFileEvents: true
});
}
// Wait for all initial documents to sync
await this.client.waitUntilFinished();
this.client.logger.info(`Initial documents created and synced`);
}
public async waitUntilSynced(): Promise<void> {
await this.client.waitUntilFinished();
}
public async act(): Promise<void> {
const options: (() => Promise<unknown>)[] = [
this.createFileAction.bind(this)

View file

@ -183,7 +183,7 @@ export class MockClient implements FileSystemOperations {
), ignoreSlowFileEvents);
}
private executeFileOperation(callback: () => unknown, ignoreSlowFileEvents: boolean = false): void {
private executeFileOperation(callback: () => unknown, ignoreSlowFileEvents = false): void {
if (this.useSlowFileEvents && !ignoreSlowFileEvents) {
// we aren't the best client and it takes some time to notice changes
setTimeout(callback, Math.random() * 100);

View file

@ -6,6 +6,7 @@ import { v4 as uuidv4 } from "uuid";
import { randomCasing } from "./utils/random-casing";
const TEST_ITERATIONS = 5;
const MAX_INITIAL_DOCS = 5;
// Simulate async file access by injecting waiting time before returning from file operations.
let slowFileEvents = false;
@ -68,6 +69,16 @@ async function runTest({
try {
await utils.awaitAll(clients.map(async (client) => client.init()));
for (const client of clients) {
const initialDocCount = Math.floor(Math.random() * MAX_INITIAL_DOCS);
if (initialDocCount > 0) {
logger.info(
`Creating ${initialDocCount} initial documents for ${client.name}`
);
await client.createInitialDocuments(initialDocCount);
}
}
for (let i = 0; i < iterations; i++) {
logger.info(`Iteration ${i + 1}/${iterations}`);
await utils.awaitAll(clients.map(async (client) => client.act()));