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 all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
10 changes: 9 additions & 1 deletion apps/wing/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { satisfies } from "compare-versions";
import { optionallyDisplayDisclaimer } from "./analytics/disclaimer";
import { exportAnalytics } from "./analytics/export";
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) {
Expand Down Expand Up @@ -235,6 +235,14 @@ 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- ${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)
.action(runSubCommand("test", "test/test"));
Expand Down
76 changes: 75 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 parallel options", () => {
let logSpy: SpyInstance;

beforeEach(() => {
Expand Down Expand Up @@ -358,6 +358,80 @@ 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 util;

test "t1" {
util.sleep(2s);
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: 1,
});
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(2s);
assert(true);
}
`
);
fs.writeFileSync(
"t2.test.w",
`
bring util;

test "t2" {
util.sleep(2s);
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(4 * 1000);
tsuf239 marked this conversation as resolved.
Show resolved Hide resolved
});
});

const EXAMPLE_TEST_RESULTS: Array<TestResult> = [
Expand Down
12 changes: 11 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,11 @@ export async function test(entrypoints: string[], options: TestOptions): Promise
});
}
};
await Promise.all(selectedEntrypoints.map(testFile));

await PromisePool.withConcurrency(options.parallel || selectedEntrypoints.length)
tsuf239 marked this conversation as resolved.
Show resolved Hide resolved
.for(selectedEntrypoints)
.process(testFile);

const testDuration = Date.now() - startTime;
printResults(results, testDuration);
if (options.outputFile) {
Expand Down
2 changes: 2 additions & 0 deletions apps/wing/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
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.

Loading