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 5 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 }} -b 10 $COMPATIBILITY *.test.w -o ../../../../out/${{ matrix.test.name }}-${{ matrix.target }}.json

- name: Upload Artifacts
if: ${{ env.LOCAL_BUILD == 'true' }}
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 @@ -227,6 +227,12 @@ async function main() {
.preset(3)
.argParser(parseInt)
)
.addOption(
new Option(
tsuf239 marked this conversation as resolved.
Show resolved Hide resolved
"-b, --batch [batch]",
"Number of tests to be executed on parallel- if not specified will execute all at the same time"
tsuf239 marked this conversation as resolved.
Show resolved Hide resolved
)
)
.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 --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);
tsuf239 marked this conversation as resolved.
Show resolved Hide resolved
});
});

const EXAMPLE_TEST_RESULTS: Array<TestResult> = [
Expand Down
15 changes: 14 additions & 1 deletion apps/wing/src/commands/test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}"];
Expand Down Expand Up @@ -134,7 +139,15 @@ 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) {
log(`processing batch:`);
const entrypointBatch = selectedEntrypoints.slice(i, i + batchSize);
await Promise.all(entrypointBatch.map(testFile));
}
const testDuration = Date.now() - startTime;
printResults(results, testDuration);
if (options.outputFile) {
Expand Down
Loading