Await all

This commit is contained in:
Andras Schmelczer 2025-12-05 22:33:33 +00:00
parent e8d86c737b
commit 77e0bb4caf
3 changed files with 9 additions and 9 deletions

View file

@ -1,3 +1,4 @@
import { awaitAll } from "./utils/await-all";
import { logToConsole } from "./utils/debugging/log-to-console";
import { slowFetchFactory } from "./utils/debugging/slow-fetch-factory";
import { slowWebSocketFactory } from "./utils/debugging/slow-web-socket-factory";
@ -41,5 +42,6 @@ export const debugging = {
export const utils = {
getRandomColor,
positionToLineAndColumn,
lineAndColumnToPosition
lineAndColumnToPosition,
awaitAll
};

View file

@ -2,7 +2,7 @@ import { choose } from "../utils/choose";
import { v4 as uuidv4 } from "uuid";
import { assert } from "../utils/assert";
import type { RelativePath, SyncSettings } from "sync-client";
import { debugging, Logger, LogLevel } from "sync-client";
import { debugging, Logger, LogLevel, utils } from "sync-client";
import { MockClient } from "./mock-client";
import { sleep } from "../utils/sleep";
import type { LogLine } from "sync-client";
@ -140,8 +140,7 @@ export class MockAgent extends MockClient {
await withTimeout(
(async (): Promise<void> => {
await this.client.setSetting("isSyncEnabled", true);
// eslint-disable-next-line no-restricted-properties
await Promise.all(this.pendingActions);
await utils.awaitAll(this.pendingActions);
await this.client.waitUntilFinished();
})(),
TIMEOUT_MS,

View file

@ -1,4 +1,5 @@
import type { SyncSettings } from "sync-client";
import { utils } from "sync-client";
import { MockAgent } from "./agent/mock-agent";
import { sleep } from "./utils/sleep";
import { v4 as uuidv4 } from "uuid";
@ -56,14 +57,12 @@ async function runTest({
}
try {
// eslint-disable-next-line no-restricted-properties
await Promise.all(clients.map(async (client) => client.init()));
await utils.awaitAll(clients.map(async (client) => client.init()));
for (let i = 0; i < iterations; i++) {
console.info(`Iteration ${i + 1}/${iterations}`);
// eslint-disable-next-line no-restricted-properties
await Promise.all(clients.map(async (client) => client.act()));
await sleep(100);
await utils.awaitAll(clients.map(async (client) => client.act()));
await sleep(Math.random() * 200);
}
console.info("Stopping agents");