From 9363087cea43e81c9bc1ecc517fbc741d0cdddb9 Mon Sep 17 00:00:00 2001 From: tsuf239 <39455181+tsuf239@users.noreply.github.com> Date: Tue, 30 Apr 2024 14:57:00 +0300 Subject: [PATCH 01/15] batch test run --- apps/wing/src/cli.ts | 1 + apps/wing/src/commands/test/test.ts | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/apps/wing/src/cli.ts b/apps/wing/src/cli.ts index dfd15b2d6bc..f92a2c199de 100644 --- a/apps/wing/src/cli.ts +++ b/apps/wing/src/cli.ts @@ -227,6 +227,7 @@ async function main() { .preset(3) .argParser(parseInt) ) + .addOption(new Option("-b, --batch [batch]", "Number of tests to be executed on parallel")) .hook("preAction", progressHook) .hook("preAction", collectAnalyticsHook) .action(runSubCommand("test", "test/test")); diff --git a/apps/wing/src/commands/test/test.ts b/apps/wing/src/commands/test/test.ts index af3ed2508b1..56ffc691e09 100644 --- a/apps/wing/src/commands/test/test.ts +++ b/apps/wing/src/commands/test/test.ts @@ -53,6 +53,11 @@ export interface TestOptions extends CompileOptions { * Determine snapshot behavior. */ readonly snapshots?: SnapshotMode; + + /** + * Number of tests to be run in parallel, if zero or none- it will run all in parallel + */ + readonly batch?: number; } const TEST_FILE_PATTERNS = ["**/*.test.w", "**/{main,*.main}.{w,ts}"]; @@ -134,7 +139,14 @@ export async function test(entrypoints: string[], options: TestOptions): Promise }); } }; - await Promise.all(selectedEntrypoints.map(testFile)); + + // split the entrypoints to smaller batches according to the command options- + // if none- it will be preformed in one batch + const batchSize = Number(options.batch) || selectedEntrypoints.length; + for (let i = 0; i < selectedEntrypoints.length; i += batchSize) { + const entrypointBatch = selectedEntrypoints.slice(i, i + batchSize); + await Promise.all(entrypointBatch.map(testFile)); + } const testDuration = Date.now() - startTime; printResults(results, testDuration); if (options.outputFile) { From 7f71adb1ff802d1d7ba0702690998e8e7dc7fcbd Mon Sep 17 00:00:00 2001 From: tsuf239 <39455181+tsuf239@users.noreply.github.com> Date: Tue, 30 Apr 2024 15:10:32 +0300 Subject: [PATCH 02/15] add tests --- apps/wing/src/commands/test/test.test.ts | 35 +++++++++++++++++++++++- apps/wing/src/commands/test/test.ts | 1 + 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/apps/wing/src/commands/test/test.test.ts b/apps/wing/src/commands/test/test.test.ts index 5893a0239ed..f8dd1cd0b86 100644 --- a/apps/wing/src/commands/test/test.test.ts +++ b/apps/wing/src/commands/test/test.test.ts @@ -295,7 +295,7 @@ describe("test-filter option", () => { }); }); -describe("retry option", () => { +describe("retry and batch options", () => { let logSpy: SpyInstance; beforeEach(() => { @@ -358,6 +358,39 @@ describe("retry option", () => { const retryLogs = logSpy.mock.calls.filter((args) => args[0].includes("Retrying")); expect(retryLogs.length).toBe(3); }); + + test("wing test --batch [batch]", async () => { + const outDir = await fsPromises.mkdtemp(join(tmpdir(), "-wing-batch-test")); + + process.chdir(outDir); + + fs.writeFileSync( + "t1.test.w", + ` + bring cloud; + test "t1" { + assert(true); + } + ` + ); + fs.writeFileSync( + "r2.test.w", + ` + bring cloud; + test "t2" { + assert(true); + } + ` + ); + + await wingTest(["t1.test.w", "t2.test.w"], { + clean: true, + platform: [BuiltinPlatform.SIM], + batch: 1, + }); + const batchLogs = logSpy.mock.calls.filter((args) => args[0].includes("Processing batch")); + expect(batchLogs.length).toBe(0); + }); }); const EXAMPLE_TEST_RESULTS: Array = [ diff --git a/apps/wing/src/commands/test/test.ts b/apps/wing/src/commands/test/test.ts index 56ffc691e09..ee00f77c910 100644 --- a/apps/wing/src/commands/test/test.ts +++ b/apps/wing/src/commands/test/test.ts @@ -144,6 +144,7 @@ export async function test(entrypoints: string[], options: TestOptions): Promise // if none- it will be preformed in one batch const batchSize = Number(options.batch) || selectedEntrypoints.length; for (let i = 0; i < selectedEntrypoints.length; i += batchSize) { + log(`processing batch:`); const entrypointBatch = selectedEntrypoints.slice(i, i + batchSize); await Promise.all(entrypointBatch.map(testFile)); } From e85cf09ff08df6ab1678204a50e181b6a65757a8 Mon Sep 17 00:00:00 2001 From: tsuf239 <39455181+tsuf239@users.noreply.github.com> Date: Tue, 30 Apr 2024 15:20:12 +0300 Subject: [PATCH 03/15] add batches to the sdk test --- .github/workflows/build.yml | 2 +- .github/workflows/{tf-aws-test.yml => sdk-spec-test.yml} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename .github/workflows/{tf-aws-test.yml => sdk-spec-test.yml} (98%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6e53ed8ddab..2bc5e0661f8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -274,7 +274,7 @@ jobs: needs: - build if: github.event_name == 'push' && needs.build.outputs.e2e-changed == 'true' - uses: ./.github/workflows/tf-aws-test.yml + uses: ./.github/workflows/sdk-spec-test.yml secrets: inherit console-preview: diff --git a/.github/workflows/tf-aws-test.yml b/.github/workflows/sdk-spec-test.yml similarity index 98% rename from .github/workflows/tf-aws-test.yml rename to .github/workflows/sdk-spec-test.yml index 0c9a7d4d1dd..0c23b41a2ef 100644 --- a/.github/workflows/tf-aws-test.yml +++ b/.github/workflows/sdk-spec-test.yml @@ -187,7 +187,7 @@ jobs: echo $COMPATIBILITY fi cd ${{ matrix.test.directory }} - $WING_CLI test --snapshots=deploy -t ${{ matrix.target }} $COMPATIBILITY *.test.w -o ../../../../out/${{ matrix.test.name }}-${{ matrix.target }}.json + $WING_CLI test --snapshots=deploy -t ${{ matrix.target }} -b 10 $COMPATIBILITY *.test.w -o ../../../../out/${{ matrix.test.name }}-${{ matrix.target }}.json - name: Upload Artifacts if: ${{ env.LOCAL_BUILD == 'true' }} From 431e52461b70d2d211134cbcb283d507941749a7 Mon Sep 17 00:00:00 2001 From: tsuf239 <39455181+tsuf239@users.noreply.github.com> Date: Thu, 2 May 2024 11:27:58 +0300 Subject: [PATCH 04/15] better description --- apps/wing/src/cli.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/wing/src/cli.ts b/apps/wing/src/cli.ts index f92a2c199de..a45ffaad3bc 100644 --- a/apps/wing/src/cli.ts +++ b/apps/wing/src/cli.ts @@ -227,7 +227,12 @@ async function main() { .preset(3) .argParser(parseInt) ) - .addOption(new Option("-b, --batch [batch]", "Number of tests to be executed on parallel")) + .addOption( + new Option( + "-b, --batch [batch]", + "Number of tests to be executed on parallel- if not specified will execute all at the same time" + ) + ) .hook("preAction", progressHook) .hook("preAction", collectAnalyticsHook) .action(runSubCommand("test", "test/test")); From 636d2395a59f0dbe2d5068af74064efd38005169 Mon Sep 17 00:00:00 2001 From: tsuf239 <39455181+tsuf239@users.noreply.github.com> Date: Sun, 5 May 2024 13:58:26 +0300 Subject: [PATCH 05/15] fixes --- .github/workflows/sdk-spec-test.yml | 2 +- apps/wing/package.json | 2 ++ apps/wing/src/cli.ts | 6 +++--- apps/wing/src/commands/test/test.test.ts | 4 ++-- apps/wing/src/commands/test/test.ts | 22 ++++++++++++++-------- pnpm-lock.yaml | 19 ++++++++++++++----- 6 files changed, 36 insertions(+), 19 deletions(-) diff --git a/.github/workflows/sdk-spec-test.yml b/.github/workflows/sdk-spec-test.yml index 0c23b41a2ef..032d9ad18d7 100644 --- a/.github/workflows/sdk-spec-test.yml +++ b/.github/workflows/sdk-spec-test.yml @@ -187,7 +187,7 @@ jobs: echo $COMPATIBILITY fi cd ${{ matrix.test.directory }} - $WING_CLI test --snapshots=deploy -t ${{ matrix.target }} -b 10 $COMPATIBILITY *.test.w -o ../../../../out/${{ matrix.test.name }}-${{ matrix.target }}.json + $WING_CLI test --snapshots=deploy -t ${{ matrix.target }} -p 10 $COMPATIBILITY *.test.w -o ../../../../out/${{ matrix.test.name }}-${{ matrix.target }}.json - name: Upload Artifacts if: ${{ env.LOCAL_BUILD == 'true' }} diff --git a/apps/wing/package.json b/apps/wing/package.json index 8c0687af070..92c87b43cc9 100644 --- a/apps/wing/package.json +++ b/apps/wing/package.json @@ -34,6 +34,7 @@ "dependencies": { "@npmcli/arborist": "^7.2.0", "@segment/analytics-node": "^1.1.0", + "@supercharge/promise-pool": "^3.2.0", "@wingconsole/app": "workspace:^", "@wingconsole/server": "workspace:^", "@winglang/compiler": "workspace:^", @@ -52,6 +53,7 @@ "npm-packlist": "^8.0.0", "open": "^8.4.2", "ora": "^5.4.1", + "p-limit": "^5.0.0", "tar": "^6.2.0", "tiny-updater": "^3.5.1", "uuid": "^8.3.2", diff --git a/apps/wing/src/cli.ts b/apps/wing/src/cli.ts index a45ffaad3bc..4c413cd4b9e 100644 --- a/apps/wing/src/cli.ts +++ b/apps/wing/src/cli.ts @@ -229,9 +229,9 @@ async function main() { ) .addOption( new Option( - "-b, --batch [batch]", - "Number of tests to be executed on parallel- if not specified will execute all at the same time" - ) + "-p, --parallel [batch]", + "Number of tests to be executed on parallel- if not specified will start executing all at the same time" + ).argParser(parseInt) ) .hook("preAction", progressHook) .hook("preAction", collectAnalyticsHook) diff --git a/apps/wing/src/commands/test/test.test.ts b/apps/wing/src/commands/test/test.test.ts index f8dd1cd0b86..b1d9a3ee349 100644 --- a/apps/wing/src/commands/test/test.test.ts +++ b/apps/wing/src/commands/test/test.test.ts @@ -359,7 +359,7 @@ describe("retry and batch options", () => { expect(retryLogs.length).toBe(3); }); - test("wing test --batch [batch]", async () => { + test("wing test --parallel [batch]", async () => { const outDir = await fsPromises.mkdtemp(join(tmpdir(), "-wing-batch-test")); process.chdir(outDir); @@ -386,7 +386,7 @@ describe("retry and batch options", () => { await wingTest(["t1.test.w", "t2.test.w"], { clean: true, platform: [BuiltinPlatform.SIM], - batch: 1, + parallel: 1, }); const batchLogs = logSpy.mock.calls.filter((args) => args[0].includes("Processing batch")); expect(batchLogs.length).toBe(0); diff --git a/apps/wing/src/commands/test/test.ts b/apps/wing/src/commands/test/test.ts index ee00f77c910..703cf0f1dce 100644 --- a/apps/wing/src/commands/test/test.ts +++ b/apps/wing/src/commands/test/test.ts @@ -2,6 +2,7 @@ import * as cp from "child_process"; import { existsSync, readFile, readFileSync, realpathSync, rm, rmSync, statSync } from "fs"; import { basename, join, relative, resolve } from "path"; import { promisify } from "util"; +import { PromisePool } from "@supercharge/promise-pool"; import { BuiltinPlatform, determineTargetFromPlatforms } from "@winglang/compiler"; import { std, simulator } from "@winglang/sdk"; import { TraceType } from "@winglang/sdk/lib/std"; @@ -55,9 +56,9 @@ export interface TestOptions extends CompileOptions { readonly snapshots?: SnapshotMode; /** - * Number of tests to be run in parallel, if zero or none- it will run all in parallel + * Number of tests to be run in parallel, if zero or none- it will run all in once */ - readonly batch?: number; + readonly parallel?: number; } const TEST_FILE_PATTERNS = ["**/*.test.w", "**/{main,*.main}.{w,ts}"]; @@ -142,12 +143,17 @@ export async function test(entrypoints: string[], options: TestOptions): Promise // split the entrypoints to smaller batches according to the command options- // if none- it will be preformed in one batch - const batchSize = Number(options.batch) || selectedEntrypoints.length; - for (let i = 0; i < selectedEntrypoints.length; i += batchSize) { - log(`processing batch:`); - const entrypointBatch = selectedEntrypoints.slice(i, i + batchSize); - await Promise.all(entrypointBatch.map(testFile)); - } + const batchSize = Number(options.parallel) || selectedEntrypoints.length; + const totalBatches = Math.ceil(selectedEntrypoints.length / batchSize); + await PromisePool.withConcurrency(batchSize) + .for(selectedEntrypoints) + .onTaskFinished((_, pool) => { + const processed = pool.processedCount(); + if (processed % batchSize == 0 || processed === selectedEntrypoints.length) { + log(`Done processing batch ${Math.ceil(processed / batchSize)}/${totalBatches}`); + } + }) + .process(testFile); const testDuration = Date.now() - startTime; printResults(results, testDuration); if (options.outputFile) { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9cd7e731b9d..916e38f2821 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -248,6 +248,9 @@ importers: '@segment/analytics-node': specifier: ^1.1.0 version: 1.1.1 + '@supercharge/promise-pool': + specifier: ^3.2.0 + version: 3.2.0 '@wingconsole/app': specifier: workspace:^ version: link:../wing-console/console/app @@ -302,6 +305,9 @@ importers: ora: specifier: ^5.4.1 version: 5.4.1 + p-limit: + specifier: ^5.0.0 + version: 5.0.0 tar: specifier: ^6.2.0 version: 6.2.0 @@ -9970,6 +9976,11 @@ packages: file-system-cache: 2.3.0 dev: true + /@supercharge/promise-pool@3.2.0: + resolution: {integrity: sha512-pj0cAALblTZBPtMltWOlZTQSLT07jIaFNeM8TWoJD1cQMgDB9mcMlVMoetiB35OzNJpqQ2b+QEtwiR9f20mADg==} + engines: {node: '>=8'} + dev: false + /@swc/core-darwin-arm64@1.4.2: resolution: {integrity: sha512-1uSdAn1MRK5C1m/TvLZ2RDvr0zLvochgrZ2xL+lRzugLlCTlSA+Q4TWtrZaOz+vnnFVliCpw7c7qu0JouhgQIw==} engines: {node: '>=10'} @@ -14157,7 +14168,7 @@ packages: dependencies: semver: 7.5.4 shelljs: 0.8.5 - typescript: 5.5.0-dev.20240422 + typescript: 5.5.0-dev.20240505 dev: true /dset@3.1.2: @@ -19633,7 +19644,6 @@ packages: engines: {node: '>=18'} dependencies: yocto-queue: 1.0.0 - dev: true /p-locate@2.0.0: resolution: {integrity: sha512-nQja7m7gSKuewoVRen45CtVfODR3crN3goVQ0DDZ9N3yHxgpkuBhZqsaiotSQRrADUrne346peY7kT3TSACykg==} @@ -22782,8 +22792,8 @@ packages: engines: {node: '>=14.17'} hasBin: true - /typescript@5.5.0-dev.20240422: - resolution: {integrity: sha512-GKfP7cqp5Rq/z6xNYZ6u6XfS4I0K3h8tw3MRKkttEkLyEWBxYS141wOr1WBcUYfvB1F5Luo/cTd7iZnySH3bIg==} + /typescript@5.5.0-dev.20240505: + resolution: {integrity: sha512-pS7FxfKdWwZcCywfyjwwVAIV/Tb6YBAcVv63WJFhSf7RclqKUTwkGbvtii/VvHtfaW50/1LdYvHU0z+Xs3xTiQ==} engines: {node: '>=14.17'} hasBin: true dev: true @@ -23950,7 +23960,6 @@ packages: /yocto-queue@1.0.0: resolution: {integrity: sha512-9bnSc/HEW2uRy67wc+T8UwauLuPJVn28jb+GtJY16iiKWyvmYJRXVT4UamsAEGQfPohgr2q4Tq0sQbQlxTfi1g==} engines: {node: '>=12.20'} - dev: true /yoga-layout-prebuilt@1.10.0: resolution: {integrity: sha512-YnOmtSbv4MTf7RGJMK0FvZ+KD8OEe/J5BNnR0GHhD8J/XcG/Qvxgszm0Un6FTHWW4uHlTgP0IztiXQnGyIR45g==} From da27e11b66d1e3a25c00c1387631954bd4abed9f Mon Sep 17 00:00:00 2001 From: Tsuf Cohen <39455181+tsuf239@users.noreply.github.com> Date: Wed, 8 May 2024 16:14:15 +0300 Subject: [PATCH 06/15] Update apps/wing/package.json Co-authored-by: Mark McCulloh --- apps/wing/package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/wing/package.json b/apps/wing/package.json index 92c87b43cc9..894cbc69809 100644 --- a/apps/wing/package.json +++ b/apps/wing/package.json @@ -53,7 +53,6 @@ "npm-packlist": "^8.0.0", "open": "^8.4.2", "ora": "^5.4.1", - "p-limit": "^5.0.0", "tar": "^6.2.0", "tiny-updater": "^3.5.1", "uuid": "^8.3.2", From f0a5a1f7fb28ebb6bd992a8c599c62229b0537ee Mon Sep 17 00:00:00 2001 From: Tsuf Cohen <39455181+tsuf239@users.noreply.github.com> Date: Wed, 8 May 2024 16:14:27 +0300 Subject: [PATCH 07/15] Update apps/wing/src/commands/test/test.ts Co-authored-by: Mark McCulloh --- apps/wing/src/commands/test/test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/wing/src/commands/test/test.ts b/apps/wing/src/commands/test/test.ts index 703cf0f1dce..11fb1d2056a 100644 --- a/apps/wing/src/commands/test/test.ts +++ b/apps/wing/src/commands/test/test.ts @@ -56,7 +56,7 @@ export interface TestOptions extends CompileOptions { readonly snapshots?: SnapshotMode; /** - * Number of tests to be run in parallel, if zero or none- it will run all in once + * Number of tests to be run in parallel. 0 or undefined will run all at once. */ readonly parallel?: number; } From 6dcf8a21157f78aab18bb7f4ff1eb9fd1923df90 Mon Sep 17 00:00:00 2001 From: Tsuf Cohen <39455181+tsuf239@users.noreply.github.com> Date: Wed, 8 May 2024 17:34:41 +0300 Subject: [PATCH 08/15] Update apps/wing/src/commands/test/test.ts Co-authored-by: Mark McCulloh --- apps/wing/src/commands/test/test.ts | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/apps/wing/src/commands/test/test.ts b/apps/wing/src/commands/test/test.ts index 3aab0738bda..56b3305d3ee 100644 --- a/apps/wing/src/commands/test/test.ts +++ b/apps/wing/src/commands/test/test.ts @@ -141,18 +141,9 @@ export async function test(entrypoints: string[], options: TestOptions): Promise } }; - // split the entrypoints to smaller batches according to the command options- - // if none- it will be preformed in one batch - const batchSize = Number(options.parallel) || selectedEntrypoints.length; - const totalBatches = Math.ceil(selectedEntrypoints.length / batchSize); - await PromisePool.withConcurrency(batchSize) + await PromisePool + .withConcurrency(options.parallel ?? selectedEntrypoints.length) .for(selectedEntrypoints) - .onTaskFinished((_, pool) => { - const processed = pool.processedCount(); - if (processed % batchSize == 0 || processed === selectedEntrypoints.length) { - log(`Done processing batch ${Math.ceil(processed / batchSize)}/${totalBatches}`); - } - }) .process(testFile); const testDuration = Date.now() - startTime; printResults(results, testDuration); From f56a0ae13c0bc97e8de9c2fc1c14c501981d845e Mon Sep 17 00:00:00 2001 From: "monada-bot[bot]" Date: Wed, 8 May 2024 14:49:26 +0000 Subject: [PATCH 09/15] chore: self mutation (build.diff) Signed-off-by: monada-bot[bot] --- apps/wing/src/commands/test/test.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/wing/src/commands/test/test.ts b/apps/wing/src/commands/test/test.ts index 56b3305d3ee..0f94e8fbd81 100644 --- a/apps/wing/src/commands/test/test.ts +++ b/apps/wing/src/commands/test/test.ts @@ -141,8 +141,7 @@ export async function test(entrypoints: string[], options: TestOptions): Promise } }; - await PromisePool - .withConcurrency(options.parallel ?? selectedEntrypoints.length) + await PromisePool.withConcurrency(options.parallel ?? selectedEntrypoints.length) .for(selectedEntrypoints) .process(testFile); const testDuration = Date.now() - startTime; From 3bb870b4ed4405f09028d1bbcb06c9ffc3f59fb5 Mon Sep 17 00:00:00 2001 From: tsuf239 <39455181+tsuf239@users.noreply.github.com> Date: Thu, 9 May 2024 10:01:38 +0300 Subject: [PATCH 10/15] fix test and ass default --- apps/wing/src/commands/test/test.test.ts | 28 ++++++++++++++---------- apps/wing/src/commands/test/test.ts | 5 +++-- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/apps/wing/src/commands/test/test.test.ts b/apps/wing/src/commands/test/test.test.ts index e0278155784..079f1e799a1 100644 --- a/apps/wing/src/commands/test/test.test.ts +++ b/apps/wing/src/commands/test/test.test.ts @@ -295,7 +295,7 @@ describe("test-filter option", () => { }); }); -describe("retry and batch options", () => { +describe("retry and parallel options", () => { let logSpy: SpyInstance; beforeEach(() => { @@ -367,29 +367,33 @@ describe("retry and batch options", () => { fs.writeFileSync( "t1.test.w", ` - bring cloud; - test "t1" { - assert(true); - } +bring util; + +test "t1" { + util.sleep(2s); + assert(true); +} ` ); fs.writeFileSync( - "r2.test.w", + "t2.test.w", ` - bring cloud; - test "t2" { - assert(true); - } +bring util; + +test "t2" { + util.sleep(1s); + assert(true); +} ` ); + const startingTime = Date.now(); await wingTest(["t1.test.w", "t2.test.w"], { clean: true, platform: [BuiltinPlatform.SIM], parallel: 1, }); - const batchLogs = logSpy.mock.calls.filter((args) => args[0].includes("Processing batch")); - expect(batchLogs.length).toBe(0); + expect(Date.now() - startingTime).toBeGreaterThanOrEqual(3 * 1000); }); }); diff --git a/apps/wing/src/commands/test/test.ts b/apps/wing/src/commands/test/test.ts index 56b3305d3ee..ca13477a946 100644 --- a/apps/wing/src/commands/test/test.ts +++ b/apps/wing/src/commands/test/test.ts @@ -24,6 +24,7 @@ const log = debug("wing:test"); const ENV_WING_TEST_RUNNER_FUNCTION_IDENTIFIERS = "WING_TEST_RUNNER_FUNCTION_IDENTIFIERS"; const ENV_WING_TEST_RUNNER_FUNCTION_IDENTIFIERS_AWSCDK = "WingTestRunnerFunctionArns"; +const DEFAULT_PARALLEL_SIZE = 10; /** * Options for the `test` command. @@ -141,10 +142,10 @@ export async function test(entrypoints: string[], options: TestOptions): Promise } }; - await PromisePool - .withConcurrency(options.parallel ?? selectedEntrypoints.length) + await PromisePool.withConcurrency(options.parallel ?? DEFAULT_PARALLEL_SIZE) .for(selectedEntrypoints) .process(testFile); + const testDuration = Date.now() - startTime; printResults(results, testDuration); if (options.outputFile) { From 655cf71cbebae4c003e615ff5dfcd395f8aafd36 Mon Sep 17 00:00:00 2001 From: tsuf239 <39455181+tsuf239@users.noreply.github.com> Date: Thu, 9 May 2024 10:09:35 +0300 Subject: [PATCH 11/15] fix 0 and description and add test --- apps/wing/src/cli.ts | 3 +- apps/wing/src/commands/test/test.test.ts | 37 ++++++++++++++++++++++++ apps/wing/src/commands/test/test.ts | 4 +-- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/apps/wing/src/cli.ts b/apps/wing/src/cli.ts index 940e00606b7..1e23e810fd7 100644 --- a/apps/wing/src/cli.ts +++ b/apps/wing/src/cli.ts @@ -3,6 +3,7 @@ import { satisfies } from "compare-versions"; import { optionallyDisplayDisclaimer } from "./analytics/disclaimer"; import { exportAnalytics } from "./analytics/export"; +import { DEFAULT_PARALLEL_SIZE } from "./commands"; import { SNAPSHOTS_HELP } from "./commands/test/snapshots-help"; import { currentPackage, projectTemplateNames } from "./util"; @@ -238,7 +239,7 @@ async function main() { .addOption( new Option( "-p, --parallel [batch]", - "Number of tests to be executed on parallel- if not specified will start executing all at the same time" + `Number of tests to be executed on parallel- if zero not specified- ${DEFAULT_PARALLEL_SIZE} will run on parallel` ).argParser(parseInt) ) .hook("preAction", progressHook) diff --git a/apps/wing/src/commands/test/test.test.ts b/apps/wing/src/commands/test/test.test.ts index 079f1e799a1..23b30c39f7b 100644 --- a/apps/wing/src/commands/test/test.test.ts +++ b/apps/wing/src/commands/test/test.test.ts @@ -395,6 +395,43 @@ test "t2" { }); expect(Date.now() - startingTime).toBeGreaterThanOrEqual(3 * 1000); }); + + test("wing test --parallel 2", async () => { + const outDir = await fsPromises.mkdtemp(join(tmpdir(), "-wing-batch-test")); + + process.chdir(outDir); + + fs.writeFileSync( + "t1.test.w", + ` +bring util; + +test "t1" { +util.sleep(1s); +assert(true); +} + ` + ); + fs.writeFileSync( + "t2.test.w", + ` +bring util; + +test "t2" { +util.sleep(1s); +assert(true); +} + ` + ); + + const startingTime = Date.now(); + await wingTest(["t1.test.w", "t2.test.w"], { + clean: true, + platform: [BuiltinPlatform.SIM], + parallel: 2, + }); + expect(Date.now() - startingTime).toBeLessThan(2 * 1000); + }); }); const EXAMPLE_TEST_RESULTS: Array = [ diff --git a/apps/wing/src/commands/test/test.ts b/apps/wing/src/commands/test/test.ts index ca13477a946..c58e2bfb24a 100644 --- a/apps/wing/src/commands/test/test.ts +++ b/apps/wing/src/commands/test/test.ts @@ -24,7 +24,7 @@ const log = debug("wing:test"); const ENV_WING_TEST_RUNNER_FUNCTION_IDENTIFIERS = "WING_TEST_RUNNER_FUNCTION_IDENTIFIERS"; const ENV_WING_TEST_RUNNER_FUNCTION_IDENTIFIERS_AWSCDK = "WingTestRunnerFunctionArns"; -const DEFAULT_PARALLEL_SIZE = 10; +export const DEFAULT_PARALLEL_SIZE = 10; /** * Options for the `test` command. @@ -142,7 +142,7 @@ export async function test(entrypoints: string[], options: TestOptions): Promise } }; - await PromisePool.withConcurrency(options.parallel ?? DEFAULT_PARALLEL_SIZE) + await PromisePool.withConcurrency(options.parallel || DEFAULT_PARALLEL_SIZE) .for(selectedEntrypoints) .process(testFile); From c391e108f4cf2c89082d545ee96db1c6ee63f7d3 Mon Sep 17 00:00:00 2001 From: tsuf239 <39455181+tsuf239@users.noreply.github.com> Date: Sun, 12 May 2024 16:36:53 +0300 Subject: [PATCH 12/15] fixes --- apps/wing/src/cli.ts | 9 +++++---- apps/wing/src/commands/test/test.ts | 3 +-- apps/wing/src/util.ts | 2 ++ 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/apps/wing/src/cli.ts b/apps/wing/src/cli.ts index 1e23e810fd7..8299300d180 100644 --- a/apps/wing/src/cli.ts +++ b/apps/wing/src/cli.ts @@ -3,9 +3,8 @@ import { satisfies } from "compare-versions"; import { optionallyDisplayDisclaimer } from "./analytics/disclaimer"; import { exportAnalytics } from "./analytics/export"; -import { DEFAULT_PARALLEL_SIZE } from "./commands"; import { SNAPSHOTS_HELP } from "./commands/test/snapshots-help"; -import { currentPackage, projectTemplateNames } from "./util"; +import { currentPackage, projectTemplateNames, DEFAULT_PARALLEL_SIZE } from "./util"; export const PACKAGE_VERSION = currentPackage.version; if (PACKAGE_VERSION == "0.0.0" && !process.env.DEBUG) { @@ -239,8 +238,10 @@ async function main() { .addOption( new Option( "-p, --parallel [batch]", - `Number of tests to be executed on parallel- if zero not specified- ${DEFAULT_PARALLEL_SIZE} will run on parallel` - ).argParser(parseInt) + `Number of tests to be executed on parallel- if not specified- ${DEFAULT_PARALLEL_SIZE} will run on parallel, 0 to run all at once` + ) + .preset(DEFAULT_PARALLEL_SIZE) + .argParser(parseInt) ) .hook("preAction", progressHook) .hook("preAction", collectAnalyticsHook) diff --git a/apps/wing/src/commands/test/test.ts b/apps/wing/src/commands/test/test.ts index c58e2bfb24a..c662cee76a5 100644 --- a/apps/wing/src/commands/test/test.ts +++ b/apps/wing/src/commands/test/test.ts @@ -24,7 +24,6 @@ const log = debug("wing:test"); const ENV_WING_TEST_RUNNER_FUNCTION_IDENTIFIERS = "WING_TEST_RUNNER_FUNCTION_IDENTIFIERS"; const ENV_WING_TEST_RUNNER_FUNCTION_IDENTIFIERS_AWSCDK = "WingTestRunnerFunctionArns"; -export const DEFAULT_PARALLEL_SIZE = 10; /** * Options for the `test` command. @@ -142,7 +141,7 @@ export async function test(entrypoints: string[], options: TestOptions): Promise } }; - await PromisePool.withConcurrency(options.parallel || DEFAULT_PARALLEL_SIZE) + await PromisePool.withConcurrency(options.parallel || selectedEntrypoints.length) .for(selectedEntrypoints) .process(testFile); diff --git a/apps/wing/src/util.ts b/apps/wing/src/util.ts index 227008c630e..d94ac820f9a 100644 --- a/apps/wing/src/util.ts +++ b/apps/wing/src/util.ts @@ -5,6 +5,8 @@ import { tmpdir } from "os"; import { join } from "path"; import { promisify } from "util"; +export const DEFAULT_PARALLEL_SIZE = 10; + /** * Normalize windows paths to be posix-like. */ From 68e1738ea7cbf953854739417685649de87d30f7 Mon Sep 17 00:00:00 2001 From: tsuf239 <39455181+tsuf239@users.noreply.github.com> Date: Sun, 12 May 2024 16:56:13 +0300 Subject: [PATCH 13/15] increase time --- apps/wing/src/commands/test/test.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/wing/src/commands/test/test.test.ts b/apps/wing/src/commands/test/test.test.ts index 23b30c39f7b..283955f2cd3 100644 --- a/apps/wing/src/commands/test/test.test.ts +++ b/apps/wing/src/commands/test/test.test.ts @@ -407,7 +407,7 @@ test "t2" { bring util; test "t1" { -util.sleep(1s); +util.sleep(2s); assert(true); } ` @@ -418,7 +418,7 @@ assert(true); bring util; test "t2" { -util.sleep(1s); +util.sleep(2s); assert(true); } ` @@ -430,7 +430,7 @@ assert(true); platform: [BuiltinPlatform.SIM], parallel: 2, }); - expect(Date.now() - startingTime).toBeLessThan(2 * 1000); + expect(Date.now() - startingTime).toBeLessThan(4 * 1000); }); }); From 57015e489e9a3497efccb225cbc787241f3e8b10 Mon Sep 17 00:00:00 2001 From: Tsuf Cohen <39455181+tsuf239@users.noreply.github.com> Date: Wed, 15 May 2024 10:24:13 +0300 Subject: [PATCH 14/15] Update apps/wing/src/commands/test/test.ts Co-authored-by: Mark McCulloh --- apps/wing/src/commands/test/test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/wing/src/commands/test/test.ts b/apps/wing/src/commands/test/test.ts index c662cee76a5..c88b2c6c8e7 100644 --- a/apps/wing/src/commands/test/test.ts +++ b/apps/wing/src/commands/test/test.ts @@ -141,7 +141,7 @@ export async function test(entrypoints: string[], options: TestOptions): Promise } }; - await PromisePool.withConcurrency(options.parallel || selectedEntrypoints.length) + await PromisePool.withConcurrency(options.parallel ?? selectedEntrypoints.length) .for(selectedEntrypoints) .process(testFile); From d187fa3a06857d340645636b73f2998c265e9612 Mon Sep 17 00:00:00 2001 From: tsuf239 <39455181+tsuf239@users.noreply.github.com> Date: Wed, 15 May 2024 10:25:27 +0300 Subject: [PATCH 15/15] Revert "Update apps/wing/src/commands/test/test.ts" This reverts commit 57015e489e9a3497efccb225cbc787241f3e8b10. --- apps/wing/src/commands/test/test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/wing/src/commands/test/test.ts b/apps/wing/src/commands/test/test.ts index c88b2c6c8e7..c662cee76a5 100644 --- a/apps/wing/src/commands/test/test.ts +++ b/apps/wing/src/commands/test/test.ts @@ -141,7 +141,7 @@ export async function test(entrypoints: string[], options: TestOptions): Promise } }; - await PromisePool.withConcurrency(options.parallel ?? selectedEntrypoints.length) + await PromisePool.withConcurrency(options.parallel || selectedEntrypoints.length) .for(selectedEntrypoints) .process(testFile);