Skip to content

Commit 9eb4de7

Browse files
ci(test): add ability to parallelise aws tests (#2544)
* ci(test): add ability to parallelise aws tests * ci(test): name npm script better
1 parent 1ae2d76 commit 9eb4de7

File tree

4 files changed

+91
-7
lines changed

4 files changed

+91
-7
lines changed

.github/workflows/run-aws-tests.yml

+24-6
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,32 @@ jobs:
3838
with:
3939
ref: ${{ github.event.pull_request.head.sha || null }} # this should only be run with this ref if is-collaborator has been run and passed
4040

41+
generate-test-matrix:
42+
runs-on: ubuntu-latest
43+
needs: publish-branch-image
44+
outputs:
45+
matrix: ${{ steps.generate-matrix.outputs.matrix }}
46+
steps:
47+
- uses: actions/checkout@v3
48+
with:
49+
ref: ${{ github.event.pull_request.head.sha || null }}
50+
- name: Use Node.js 18.x
51+
uses: actions/setup-node@v3
52+
with:
53+
node-version: 18.x
54+
- id: generate-matrix
55+
run: |
56+
RESULT=$(node .github/workflows/scripts/get-tests-in-package-location.js)
57+
echo "matrix=$RESULT" >> $GITHUB_OUTPUT
58+
4159
run-tests:
4260
if: contains( github.event.pull_request.labels.*.name, 'run-aws-tests' )
43-
needs: publish-branch-image
61+
needs: generate-test-matrix
4462
timeout-minutes: 60
4563
runs-on: ubuntu-latest
64+
strategy:
65+
matrix:
66+
testName: ${{fromJson(needs.generate-test-matrix.outputs.matrix).names}}
4667
permissions:
4768
contents: read
4869
id-token: write
@@ -73,10 +94,7 @@ jobs:
7394
node-version: 18.x
7495
- run: npm install
7596
- run: npm run build
76-
- run: npm run test:aws --workspace artillery
77-
env:
78-
FORCE_COLOR: 1
79-
80-
- run: npm run test:aws --workspace artillery-engine-playwright
97+
# runs the single test file from `package` workspace in the `file`, as defined in the matrix output
98+
- run: npm run test:aws:ci --workspace ${{fromJson(needs.generate-test-matrix.outputs.matrix).namesToFiles[matrix.testName].package }} -- --files ${{ fromJson(needs.generate-test-matrix.outputs.matrix).namesToFiles[matrix.testName].file }}
8199
env:
82100
FORCE_COLOR: 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
/**
5+
* This script is used to discover all the tests in different test directories that match a specific suffix
6+
* and generate a JSON file that can be used to run the tests in parallel leveraging Github Actions
7+
*/
8+
9+
const testLocations = [
10+
{
11+
location: 'test/cloud-e2e/fargate',
12+
package: 'artillery',
13+
suffix: '.test.js'
14+
},
15+
{
16+
location: 'test/cloud-e2e/lambda',
17+
package: 'artillery',
18+
suffix: '.test.js'
19+
},
20+
{
21+
location: 'test',
22+
package: 'artillery-engine-playwright',
23+
suffix: '.aws.js'
24+
}
25+
];
26+
27+
const tests = {
28+
names: [],
29+
namesToFiles: {}
30+
};
31+
32+
const addTest = (fileName, baseLocation, packageName, suffix) => {
33+
if (!fileName.endsWith(suffix)) {
34+
return;
35+
}
36+
const testName = fileName.replace(suffix, '');
37+
const jobName = `${packageName}/${testName}`;
38+
tests.names.push(jobName);
39+
tests.namesToFiles[jobName] = {
40+
file: `${baseLocation}/${fileName}`,
41+
package: packageName
42+
};
43+
};
44+
45+
// Recursively scan a directory to find files, and add tests to the tests object
46+
function scanDirectory(location, baseLocation, packageName, suffix) {
47+
fs.readdirSync(location).forEach((file) => {
48+
const absolute = path.join(location, file);
49+
if (fs.statSync(absolute).isDirectory()) {
50+
scanDirectory(absolute, baseLocation, packageName, suffix);
51+
} else {
52+
addTest(file, baseLocation, packageName, suffix);
53+
}
54+
});
55+
}
56+
57+
// Scan all the test locations
58+
for (const { package, location, suffix } of testLocations) {
59+
const fullLocation = `packages/${package}/${location}`;
60+
scanDirectory(fullLocation, location, package, suffix);
61+
}
62+
63+
// Output the tests object as a JSON string to be used by Github Actions
64+
console.log(JSON.stringify(tests));

packages/artillery-engine-playwright/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"main": "index.js",
66
"scripts": {
77
"test": "export ARTILLERY_TELEMETRY_DEFAULTS='{\"source\":\"test-suite\"}' && tap test/*.test.js --color --no-coverage --timeout 300",
8-
"test:aws": "export ARTILLERY_TELEMETRY_DEFAULTS='{\"source\":\"test-suite\"}' && tap test/*.aws.js --color --no-coverage --timeout 420"
8+
"test:aws": "export ARTILLERY_TELEMETRY_DEFAULTS='{\"source\":\"test-suite\"}' && tap test/*.aws.js --color --no-coverage --timeout 420",
9+
"test:aws:ci": "export ARTILLERY_TELEMETRY_DEFAULTS='{\"source\":\"test-suite\"}' && tap --no-coverage --color --timeout=420"
910
},
1011
"keywords": [],
1112
"author": "",

packages/artillery/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"test": "export ARTILLERY_TELEMETRY_DEFAULTS='{\"source\":\"test-suite\"}' && npm run test:unit && npm run test:acceptance",
4949
"test:windows": "set ARTILLERY_TELEMETRY_DEFAULTS='{\"source\":\"test-suite\"}' & npm run test:unit && tap --no-coverage --timeout=420 --color test/cli/*.test.js",
5050
"test:aws": "export ARTILLERY_TELEMETRY_DEFAULTS='{\"source\":\"test-suite\"}' && tap --no-coverage --color --timeout=4200 test/cloud-e2e/**/*.test.js",
51+
"test:aws:ci": "export ARTILLERY_TELEMETRY_DEFAULTS='{\"source\":\"test-suite\"}' && tap --no-coverage --color --timeout=4200",
5152
"test:aws:windows": "set ARTILLERY_TELEMETRY_DEFAULTS='{\"source\":\"test-suite\"}' & tap --no-coverage --timeout=420 --color test/cloud-e2e/fargate/*.test.js --grep \"Run simple-bom\"",
5253
"lint": "eslint --ext \".js,.ts,.tsx\" .",
5354
"lint-fix": "npm run lint -- --fix"

0 commit comments

Comments
 (0)