Add initial documents before starting
This commit is contained in:
parent
0e1849061b
commit
bd8650e80b
3 changed files with 35 additions and 1 deletions
|
|
@ -90,6 +90,29 @@ export class MockAgent extends MockClient {
|
||||||
this.client.logger.info("Agent initialized");
|
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> {
|
public async act(): Promise<void> {
|
||||||
const options: (() => Promise<unknown>)[] = [
|
const options: (() => Promise<unknown>)[] = [
|
||||||
this.createFileAction.bind(this)
|
this.createFileAction.bind(this)
|
||||||
|
|
|
||||||
|
|
@ -183,7 +183,7 @@ export class MockClient implements FileSystemOperations {
|
||||||
), ignoreSlowFileEvents);
|
), ignoreSlowFileEvents);
|
||||||
}
|
}
|
||||||
|
|
||||||
private executeFileOperation(callback: () => unknown, ignoreSlowFileEvents: boolean = false): void {
|
private executeFileOperation(callback: () => unknown, ignoreSlowFileEvents = false): void {
|
||||||
if (this.useSlowFileEvents && !ignoreSlowFileEvents) {
|
if (this.useSlowFileEvents && !ignoreSlowFileEvents) {
|
||||||
// we aren't the best client and it takes some time to notice changes
|
// we aren't the best client and it takes some time to notice changes
|
||||||
setTimeout(callback, Math.random() * 100);
|
setTimeout(callback, Math.random() * 100);
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import { v4 as uuidv4 } from "uuid";
|
||||||
import { randomCasing } from "./utils/random-casing";
|
import { randomCasing } from "./utils/random-casing";
|
||||||
|
|
||||||
const TEST_ITERATIONS = 5;
|
const TEST_ITERATIONS = 5;
|
||||||
|
const MAX_INITIAL_DOCS = 5;
|
||||||
|
|
||||||
// Simulate async file access by injecting waiting time before returning from file operations.
|
// Simulate async file access by injecting waiting time before returning from file operations.
|
||||||
let slowFileEvents = false;
|
let slowFileEvents = false;
|
||||||
|
|
@ -68,6 +69,16 @@ async function runTest({
|
||||||
try {
|
try {
|
||||||
await utils.awaitAll(clients.map(async (client) => client.init()));
|
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++) {
|
for (let i = 0; i < iterations; i++) {
|
||||||
logger.info(`Iteration ${i + 1}/${iterations}`);
|
logger.info(`Iteration ${i + 1}/${iterations}`);
|
||||||
await utils.awaitAll(clients.map(async (client) => client.act()));
|
await utils.awaitAll(clients.map(async (client) => client.act()));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue