Skip to content

Commit 0f5eb30

Browse files
committed
Try and batch tests
1 parent 5e477ff commit 0f5eb30

3 files changed

Lines changed: 95 additions & 55 deletions

File tree

.github/workflows/pull_request.yml

Lines changed: 31 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -26,52 +26,28 @@ jobs:
2626
runs-on: ubuntu-latest
2727
strategy:
2828
fail-fast: false
29-
# Unit on all Node versions; v5 integration in batches on all Node versions; v4 full suite on 22.
3029
matrix:
31-
include:
32-
- node-version: 20
33-
test: unit
34-
- node-version: 22
35-
test: unit
36-
- node-version: 24
37-
test: unit
38-
- node-version: 20
39-
test: integration:v5:batch1
40-
- node-version: 22
41-
test: integration:v5:batch1
42-
- node-version: 24
43-
test: integration:v5:batch1
44-
- node-version: 20
45-
test: integration:v5:batch2
46-
- node-version: 22
47-
test: integration:v5:batch2
48-
- node-version: 24
49-
test: integration:v5:batch2
50-
- node-version: 20
51-
test: integration:v5:batch3
52-
- node-version: 22
53-
test: integration:v5:batch3
54-
- node-version: 24
55-
test: integration:v5:batch3
56-
- node-version: 20
57-
test: integration:v5:batch4
58-
- node-version: 22
59-
test: integration:v5:batch4
60-
- node-version: 24
61-
test: integration:v5:batch4
62-
- node-version: 20
63-
test: integration:v5:batch5
64-
- node-version: 22
65-
test: integration:v5:batch5
66-
- node-version: 24
67-
test: integration:v5:batch5
68-
- node-version: 20
69-
test: integration:v4
70-
- node-version: 22
71-
test: integration:v4
72-
- node-version: 24
73-
test: integration:v4
74-
name: Node.js v${{ matrix.node-version }} - ${{ matrix.test }} tests
30+
node-version: [20, 22, 24]
31+
test: [unit, integration:v4, integration:v5:batch]
32+
batch-index: [0, 1, 2, 3, 4]
33+
exclude:
34+
- test: unit
35+
batch-index: 1
36+
- test: unit
37+
batch-index: 2
38+
- test: unit
39+
batch-index: 3
40+
- test: unit
41+
batch-index: 4
42+
- test: integration:v4
43+
batch-index: 1
44+
- test: integration:v4
45+
batch-index: 2
46+
- test: integration:v4
47+
batch-index: 3
48+
- test: integration:v4
49+
batch-index: 4
50+
name: Node.js v${{ matrix.node-version }} - ${{ matrix.test == 'integration:v5:batch' && format('{0}{1}', matrix.test, matrix.batch-index) || matrix.test }} tests
7551
steps:
7652
- name: Checkout
7753
uses: actions/checkout@v4
@@ -83,20 +59,25 @@ jobs:
8359
run: npm ci
8460
- name: Run ${{ matrix.test }} Tests and Add Annotations
8561
id: tests
86-
run: npm run test:${{ matrix.test }} -- --ci --coverage --reporters=default --reporters=github-actions --reporters=jest-junit
62+
run: |
63+
if [ "${{ matrix.test }}" = "integration:v5:batch" ]; then
64+
npm run test:integration:v5:batch -- ${{ matrix.batch-index }} -- --ci --coverage --reporters=default --reporters=github-actions --reporters=jest-junit
65+
else
66+
npm run test:${{ matrix.test }} -- --ci --coverage --reporters=default --reporters=github-actions --reporters=jest-junit
67+
fi
8768
env:
8869
ORKES_BACKEND_VERSION: ${{ matrix.test == 'integration:v4' && '4' || (contains(matrix.test, 'integration:v5') && '5' || '') }}
8970
CONDUCTOR_SERVER_URL: ${{ matrix.test == 'integration:v4' && vars.SERVER_URL_V4 || (contains(matrix.test, 'integration') && vars.SERVER_URL || '') }}
9071
CONDUCTOR_AUTH_KEY: ${{ matrix.test == 'integration:v4' && secrets.AUTH_KEY_V4 || (contains(matrix.test, 'integration') && secrets.AUTH_KEY || '') }}
9172
CONDUCTOR_AUTH_SECRET: ${{ matrix.test == 'integration:v4' && secrets.AUTH_SECRET_V4 || (contains(matrix.test, 'integration') && secrets.AUTH_SECRET || '') }}
9273
CONDUCTOR_SDK_INITIAL_TOKEN_STAGGER_MS: ${{ (matrix.test == 'integration:v4' || contains(matrix.test, 'integration')) && '2000' || '' }}
93-
JEST_JUNIT_OUTPUT_NAME: ${{ matrix.test }}-node-${{ matrix.node-version }}-test-results.xml
94-
- name: Publish ${{ matrix.test }} Test Results
74+
JEST_JUNIT_OUTPUT_NAME: ${{ matrix.test == 'integration:v5:batch' && format('{0}{1}-node-{2}-test-results.xml', matrix.test, matrix.batch-index, matrix.node-version) || format('{0}-node-{1}-test-results.xml', matrix.test, matrix.node-version) }}
75+
- name: Publish Test Results
9576
uses: dorny/test-reporter@v2
9677
if: ${{ !cancelled() }}
9778
with:
98-
name: ${{ matrix.test }} (Node ${{ matrix.node-version }})
99-
path: reports/${{ matrix.test }}-node-${{ matrix.node-version }}-test-results.xml
79+
name: ${{ matrix.test == 'integration:v5:batch' && format('{0}{1} (Node {2})', matrix.test, matrix.batch-index, matrix.node-version) || format('{0} (Node {1})', matrix.test, matrix.node-version) }}
80+
path: reports/${{ matrix.test == 'integration:v5:batch' && format('{0}{1}-node-{2}-test-results.xml', matrix.test, matrix.batch-index, matrix.node-version) || format('{0}-node-{1}-test-results.xml', matrix.test, matrix.node-version) }}
10081
reporter: jest-junit
10182
- name: Upload coverage to Codecov
10283
if: always()

package.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,7 @@
5151
"test:integration:base": "jest --force-exit --detectOpenHandles --testMatch='**/src/integration-tests/*.test.[jt]s?(x)'",
5252
"test:integration:v5": "cross-env ORKES_BACKEND_VERSION=5 npm run test:integration:base --",
5353
"test:integration:v4": "cross-env ORKES_BACKEND_VERSION=4 npm run test:integration:base --",
54-
"test:integration:v5:batch1": "cross-env ORKES_BACKEND_VERSION=5 npm run test:integration:base -- --testPathPatterns=\"EventClient|ApplicationClient|AuthorizationClient\"",
55-
"test:integration:v5:batch2": "cross-env ORKES_BACKEND_VERSION=5 npm run test:integration:base -- --testPathPatterns=\"WorkflowExecutor|ConductorWorkflow\"",
56-
"test:integration:v5:batch3": "cross-env ORKES_BACKEND_VERSION=5 npm run test:integration:base -- --testPathPatterns=\"TaskManager|TaskRunner|TaskClient|WorkerRegistration|WorkerAdvanced\"",
57-
"test:integration:v5:batch4": "cross-env ORKES_BACKEND_VERSION=5 npm run test:integration:base -- --testPathPatterns=\"MetadataClient|IntegrationClient|SecretClient|SchemaClient|PromptClient\"",
58-
"test:integration:v5:batch5": "cross-env ORKES_BACKEND_VERSION=5 npm run test:integration:base -- --testPathPatterns=\"ServiceRegistryClient|SchedulerClient|readme|WorkflowResourceService|E2EFiveTaskWorkflow\"",
54+
"test:integration:v5:batch": "cross-env ORKES_BACKEND_VERSION=5 node scripts/run-integration-batch.js",
5955
"ci": "npm run lint && npm run test",
6056
"build": "tsup index.ts",
6157
"generate-openapi-layer": "openapi-ts",

scripts/run-integration-batch.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env node
2+
"use strict";
3+
/**
4+
* Runs one batch of integration tests (by file count). Splits src/integration-tests/*.test.* into 5 batches.
5+
* Usage: node scripts/run-integration-batch.js <batchIndex 0-4> [-- jest args...]
6+
* Example: npm run test:integration:v5:batch -- 0
7+
* Example: npm run test:integration:v5:batch -- 2 -- --ci --coverage
8+
*/
9+
10+
const fs = require("fs");
11+
const path = require("path");
12+
const { spawnSync } = require("child_process");
13+
14+
const INTEGRATION_DIR = path.join(__dirname, "..", "src", "integration-tests");
15+
const TOTAL_BATCHES = 5;
16+
17+
function getIntegrationTestFiles() {
18+
const files = fs.readdirSync(INTEGRATION_DIR);
19+
return files
20+
.filter((f) => /\.test\.(ts|tsx|js|jsx)$/i.test(f))
21+
.sort();
22+
}
23+
24+
function getPatternForBatch(batchIndex) {
25+
const files = getIntegrationTestFiles();
26+
const chunkSize = Math.ceil(files.length / TOTAL_BATCHES);
27+
const start = batchIndex * chunkSize;
28+
const end = Math.min(start + chunkSize, files.length);
29+
const batchFiles = files.slice(start, end);
30+
// Match full filename so e.g. MetadataClient.test.ts and MetadataClient.complete.test.ts stay distinct
31+
return batchFiles.map((f) => f.replace(/\./g, "\\.")).join("|");
32+
}
33+
34+
const raw = process.argv[2];
35+
const batchIndex = raw === undefined ? 0 : parseInt(raw, 10);
36+
if (Number.isNaN(batchIndex) || batchIndex < 0 || batchIndex >= TOTAL_BATCHES) {
37+
console.error(`Usage: run-integration-batch.js <batchIndex 0-${TOTAL_BATCHES - 1}> [-- jest args...]`);
38+
console.error(`Example: npm run test:integration:v5:batch -- 0`);
39+
console.error(`Example: npm run test:integration:v5:batch -- 2 -- --ci --coverage`);
40+
process.exit(1);
41+
}
42+
43+
if (raw === undefined) {
44+
console.log(`Running integration batch 0 (default). Use "npm run test:integration:v5:batch -- <0-4>" for a specific batch.\n`);
45+
}
46+
47+
const rest = process.argv.slice(raw === undefined ? 2 : 3).filter((a) => a !== "--");
48+
const pattern = getPatternForBatch(batchIndex);
49+
50+
const jestArgs = [
51+
"--force-exit",
52+
"--detectOpenHandles",
53+
"--testMatch=**/src/integration-tests/*.test.[jt]s?(x)",
54+
`--testPathPatterns=${pattern}`,
55+
...rest,
56+
];
57+
58+
const result = spawnSync("npx", ["jest", ...jestArgs], {
59+
stdio: "inherit",
60+
env: process.env,
61+
});
62+
63+
process.exit(result.status ?? 1);

0 commit comments

Comments
 (0)