Await all
This commit is contained in:
parent
e8d86c737b
commit
77e0bb4caf
3 changed files with 9 additions and 9 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { awaitAll } from "./utils/await-all";
|
||||||
import { logToConsole } from "./utils/debugging/log-to-console";
|
import { logToConsole } from "./utils/debugging/log-to-console";
|
||||||
import { slowFetchFactory } from "./utils/debugging/slow-fetch-factory";
|
import { slowFetchFactory } from "./utils/debugging/slow-fetch-factory";
|
||||||
import { slowWebSocketFactory } from "./utils/debugging/slow-web-socket-factory";
|
import { slowWebSocketFactory } from "./utils/debugging/slow-web-socket-factory";
|
||||||
|
|
@ -41,5 +42,6 @@ export const debugging = {
|
||||||
export const utils = {
|
export const utils = {
|
||||||
getRandomColor,
|
getRandomColor,
|
||||||
positionToLineAndColumn,
|
positionToLineAndColumn,
|
||||||
lineAndColumnToPosition
|
lineAndColumnToPosition,
|
||||||
|
awaitAll
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import { choose } from "../utils/choose";
|
||||||
import { v4 as uuidv4 } from "uuid";
|
import { v4 as uuidv4 } from "uuid";
|
||||||
import { assert } from "../utils/assert";
|
import { assert } from "../utils/assert";
|
||||||
import type { RelativePath, SyncSettings } from "sync-client";
|
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 { MockClient } from "./mock-client";
|
||||||
import { sleep } from "../utils/sleep";
|
import { sleep } from "../utils/sleep";
|
||||||
import type { LogLine } from "sync-client";
|
import type { LogLine } from "sync-client";
|
||||||
|
|
@ -140,8 +140,7 @@ export class MockAgent extends MockClient {
|
||||||
await withTimeout(
|
await withTimeout(
|
||||||
(async (): Promise<void> => {
|
(async (): Promise<void> => {
|
||||||
await this.client.setSetting("isSyncEnabled", true);
|
await this.client.setSetting("isSyncEnabled", true);
|
||||||
// eslint-disable-next-line no-restricted-properties
|
await utils.awaitAll(this.pendingActions);
|
||||||
await Promise.all(this.pendingActions);
|
|
||||||
await this.client.waitUntilFinished();
|
await this.client.waitUntilFinished();
|
||||||
})(),
|
})(),
|
||||||
TIMEOUT_MS,
|
TIMEOUT_MS,
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import type { SyncSettings } from "sync-client";
|
import type { SyncSettings } from "sync-client";
|
||||||
|
import { utils } from "sync-client";
|
||||||
import { MockAgent } from "./agent/mock-agent";
|
import { MockAgent } from "./agent/mock-agent";
|
||||||
import { sleep } from "./utils/sleep";
|
import { sleep } from "./utils/sleep";
|
||||||
import { v4 as uuidv4 } from "uuid";
|
import { v4 as uuidv4 } from "uuid";
|
||||||
|
|
@ -56,14 +57,12 @@ async function runTest({
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// eslint-disable-next-line no-restricted-properties
|
await utils.awaitAll(clients.map(async (client) => client.init()));
|
||||||
await Promise.all(clients.map(async (client) => client.init()));
|
|
||||||
|
|
||||||
for (let i = 0; i < iterations; i++) {
|
for (let i = 0; i < iterations; i++) {
|
||||||
console.info(`Iteration ${i + 1}/${iterations}`);
|
console.info(`Iteration ${i + 1}/${iterations}`);
|
||||||
// eslint-disable-next-line no-restricted-properties
|
await utils.awaitAll(clients.map(async (client) => client.act()));
|
||||||
await Promise.all(clients.map(async (client) => client.act()));
|
await sleep(Math.random() * 200);
|
||||||
await sleep(100);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
console.info("Stopping agents");
|
console.info("Stopping agents");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue