Skip to content

Commit f3e6c77

Browse files
Run integration tests concurrently
This enhancement reduces the amount of time needed to execute integration tests, since each test package no longer has to wait for the previous ones to be completed. In order to do this, a regex is used to match each test file. It is also specified the path to the directory that contains the file.
1 parent 4dcf0da commit f3e6c77

File tree

3 files changed

+38
-7
lines changed

3 files changed

+38
-7
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from pathlib import Path
2+
import json
3+
4+
5+
if __name__ == "__main__":
6+
import sys
7+
8+
tests_path = sys.argv[1]
9+
10+
test_files = [str(f).split("/")[-2] for f in Path(tests_path).glob("*/*_test.go")]
11+
test_files = list(dict.fromkeys(test_files))
12+
print(json.dumps(test_files))

.github/workflows/test-go-task.yml

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,30 @@ jobs:
5858
5959
echo "result=$RESULT" >> $GITHUB_OUTPUT
6060
61-
test:
61+
tests-collector:
62+
runs-on: ubuntu-latest
6263
needs: run-determination
6364
if: needs.run-determination.outputs.result == 'true'
65+
outputs:
66+
tests-data: ${{ steps.collection.outputs.tests-data }}
67+
steps:
68+
- name: Checkout repository
69+
uses: actions/checkout@v3
6470

65-
strategy:
66-
fail-fast: false
71+
- name: Collect tests
72+
id: collection
73+
run: |
74+
echo "tests-data=$(python .github/tools/get_go_integration_tests.py ./internal/integrationtest)" >> $GITHUB_OUTPUT
6775
76+
test:
77+
needs: tests-collector
78+
strategy:
6879
matrix:
6980
operating-system:
7081
- ubuntu-latest
7182
- windows-latest
7283
- macos-latest
84+
tests: ${{ fromJSON(needs.tests-collector.outputs.tests-data) }}
7385

7486
runs-on: ${{ matrix.operating-system }}
7587

@@ -93,7 +105,10 @@ jobs:
93105
version: 3.x
94106

95107
- name: Run tests
96-
run: task go:test
108+
shell: bash
109+
run: |
110+
export GO_TEST_PACKAGE="github.com/arduino/arduino-cli/internal/integrationtest/${{ matrix.tests }}"
111+
task go:test
97112
98113
- name: Run unit tests on the legacy package
99114
# Run legacy tests on one platform only

Taskfile.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,11 @@ tasks:
9999
go test \
100100
-v \
101101
-short \
102+
{{ .GO_TEST_PACKAGE }} \
102103
-run '{{default ".*" .GO_TEST_REGEX}}' \
103104
{{default "-timeout 20m -coverpkg=./... -covermode=atomic" .GO_TEST_FLAGS}} \
104105
-coverprofile=coverage_unit.txt \
105-
{{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}} \
106+
{{default .DEFAULT_INTEGRATIONTEST_GO_PACKAGES .GO_PACKAGES}} \
106107
{{.TEST_LDFLAGS}}
107108
108109
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/test-go-integration-task/Taskfile.yml
@@ -342,10 +343,13 @@ tasks:
342343
vars:
343344
PROJECT_NAME: "arduino-cli"
344345
DIST_DIR: "dist"
345-
# all modules of this project except for "legacy/..." module
346+
# all modules of this project except for "legacy/..." module and integration test
346347
DEFAULT_GO_PACKAGES:
347348
sh: |
348-
echo $(cd {{default "./" .GO_MODULE_PATH}} && go list ./... | grep -v legacy | tr '\n' ' ' || echo '"ERROR: Unable to discover Go packages"')
349+
echo $(cd {{default "./" .GO_MODULE_PATH}} && go list ./... | grep -v internal/integrationtest | grep -v legacy | tr '\n' ' ' || echo '"ERROR: Unable to discover Go packages"')
350+
DEFAULT_INTEGRATIONTEST_GO_PACKAGES:
351+
sh: |
352+
echo $(cd {{default "./" .GO_MODULE_PATH}} && go list ./... | grep internal/integrationtest | tr '\n' ' ' || echo '"ERROR: Unable to discover Go packages"')
349353
# build vars
350354
COMMIT:
351355
sh: echo "$(git log --no-show-signature -n 1 --format=%h)"

0 commit comments

Comments
 (0)