Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): -p/ --parallel option defines tests amount to be run on parallel #6381

Merged
merged 20 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }} -p 10 $COMPATIBILITY *.test.w -o ../../../../out/${{ matrix.test.name }}-${{ matrix.target }}.json

- name: Upload Artifacts
if: ${{ env.LOCAL_BUILD == 'true' }}
Expand Down
1 change: 1 addition & 0 deletions apps/wing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:^",
Expand Down
6 changes: 6 additions & 0 deletions apps/wing/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,12 @@ async function main() {
.preset(3)
.argParser(parseInt)
)
.addOption(
new Option(
tsuf239 marked this conversation as resolved.
Show resolved Hide resolved
"-p, --parallel [batch]",
"Number of tests to be executed on parallel- if not specified will start executing all at the same time"
tsuf239 marked this conversation as resolved.
Show resolved Hide resolved
).argParser(parseInt)
)
.hook("preAction", progressHook)
.hook("preAction", collectAnalyticsHook)
.action(runSubCommand("test", "test/test"));
Expand Down
35 changes: 34 additions & 1 deletion apps/wing/src/commands/test/test.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ describe("test-filter option", () => {
});
});

describe("retry option", () => {
describe("retry and batch options", () => {
let logSpy: SpyInstance;

beforeEach(() => {
Expand Down Expand Up @@ -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 --parallel [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],
parallel: 1,
});
const batchLogs = logSpy.mock.calls.filter((args) => args[0].includes("Processing batch"));
expect(batchLogs.length).toBe(0);
tsuf239 marked this conversation as resolved.
Show resolved Hide resolved
});
});

const EXAMPLE_TEST_RESULTS: Array<TestResult> = [
Expand Down
11 changes: 10 additions & 1 deletion apps/wing/src/commands/test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 { LogLevel } from "@winglang/sdk/lib/std";
Expand Down Expand Up @@ -53,6 +54,11 @@ export interface TestOptions extends CompileOptions {
* Determine snapshot behavior.
*/
readonly snapshots?: SnapshotMode;

/**
* Number of tests to be run in parallel. 0 or undefined will run all at once.
*/
readonly parallel?: number;
}

const TEST_FILE_PATTERNS = ["**/*.test.w", "**/{main,*.main}.{w,ts}"];
Expand Down Expand Up @@ -134,7 +140,10 @@ export async function test(entrypoints: string[], options: TestOptions): Promise
});
}
};
await Promise.all(selectedEntrypoints.map(testFile));

await PromisePool.withConcurrency(options.parallel ?? selectedEntrypoints.length)
.for(selectedEntrypoints)
.process(testFile);
const testDuration = Date.now() - startTime;
printResults(results, testDuration);
if (options.outputFile) {
Expand Down
14 changes: 11 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.