Skip to content

Commit e6fb647

Browse files
Run CI tests in parallel (#25271)
#21774 Improves run time by about 30%. Things have been arranged in such a way that splitting modules out further will be trivial in the future, such as breaking the different integration test suited into their own units. ![image](https://github.com/user-attachments/assets/ead46e4c-6f14-406d-a29b-b25abc79c384) ![image](https://github.com/user-attachments/assets/3f7fd7f3-d7a8-4ff8-a184-646a72f1d015)
1 parent 33c3ca6 commit e6fb647

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

.github/workflows/test-go.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
test-go:
4343
strategy:
4444
matrix:
45-
suite: ["integration", "core"]
45+
suite: ["integration", "core", "mysql", "fleetctl", "vuln"]
4646
os: [ubuntu-latest]
4747
mysql: ["mysql:8.0.36", "mysql:8.4.3", "mysql:9.1.0"] # make sure to update supported versions docs when this changes
4848
isCron:
@@ -118,10 +118,13 @@ jobs:
118118
- name: Run Go Tests
119119
run: |
120120
if [[ "${{ matrix.suite }}" == "core" ]]; then
121+
CI_TEST_PKG=main
121122
RUN_TESTS_ARG='-skip=^TestIntegrations'
122123
elif [[ "${{ matrix.suite }}" == "integration" ]]; then
124+
CI_TEST_PKG=main
123125
RUN_TESTS_ARG='-run=^TestIntegrations'
124126
else
127+
CI_TEST_PKG="${{ matrix.suite }}"
125128
RUN_TESTS_ARG=''
126129
fi
127130
GO_TEST_EXTRA_FLAGS="-v -race=$RACE_ENABLED -timeout=$GO_TEST_TIMEOUT $RUN_TESTS_ARG" \
@@ -135,6 +138,7 @@ jobs:
135138
SAML_IDP_TEST=1 \
136139
MAIL_TEST=1 \
137140
NETWORK_TEST_GITHUB_TOKEN=${{ secrets.FLEET_RELEASE_GITHUB_PAT }} \
141+
CI_TEST_PKG="${CI_TEST_PKG}" \
138142
make test-go 2>&1 | tee /tmp/gotest.log
139143
140144
- name: Create mysql identifier without colon

Makefile

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,30 @@ dump-test-schema:
150150
# TESTS_TO_RUN: Name specific tests to run in the specified packages. Leave blank to run all tests in the specified packages.
151151
# GO_TEST_EXTRA_FLAGS: Used to specify other arguments to `go test`.
152152
# GO_TEST_MAKE_FLAGS: Internal var used by other targets to add arguments to `go test`.
153-
#
153+
#
154154
PKG_TO_TEST := "" # default to empty string; can be overridden on command line.
155155
go_test_pkg_to_test := $(addprefix ./,$(PKG_TO_TEST)) # set paths for packages to test
156156
dlv_test_pkg_to_test := $(addprefix github.com/fleetdm/fleet/v4/,$(PKG_TO_TEST)) # set URIs for packages to debug
157157

158+
DEFAULT_PKG_TO_TEST := ./cmd/... ./ee/... ./orbit/pkg/... ./orbit/cmd/orbit ./pkg/... ./server/... ./tools/...
159+
ifeq ($(CI_TEST_PKG), main)
160+
CI_PKG_TO_TEST=$(shell go list ${DEFAULT_PKG_TO_TEST} | grep -v "server/datastore/mysql" | grep -v "cmd/fleetctl" | grep -v "server/vulnerabilities" | sed -e 's|github.com/fleetdm/fleet/v4/||g')
161+
else ifeq ($(CI_TEST_PKG), mysql)
162+
CI_PKG_TO_TEST="server/datastore/mysql/..."
163+
else ifeq ($(CI_TEST_PKG), fleetctl)
164+
CI_PKG_TO_TEST="cmd/fleetctl/..."
165+
else ifeq ($(CI_TEST_PKG), vuln)
166+
CI_PKG_TO_TEST="server/vulnerabilities/..."
167+
else
168+
CI_PKG_TO_TEST=$(DEFAULT_PKG_TO_TEST)
169+
endif
170+
171+
ci-pkg-list:
172+
@echo $(CI_PKG_TO_TEST)
173+
158174
.run-go-tests:
159175
ifeq ($(PKG_TO_TEST), "")
160-
@echo "Please specify one or more packages to test with argument PKG_TO_TEST=\"/path/to/pkg/1 /path/to/pkg/2\"...";
176+
@echo "Please specify one or more packages to test with argument PKG_TO_TEST=\"/path/to/pkg/1 /path/to/pkg/2\"...";
161177
else
162178
@echo Running Go tests with command:
163179
go test -tags full,fts5,netgo -run=${TESTS_TO_RUN} ${GO_TEST_MAKE_FLAGS} ${GO_TEST_EXTRA_FLAGS} -parallel 8 -coverprofile=coverage.txt -covermode=atomic -coverpkg=github.com/fleetdm/fleet/v4/... $(go_test_pkg_to_test)
@@ -171,22 +187,22 @@ endif
171187
# GO_TEST_EXTRA_FLAGS: Used to specify other arguments to `go test`.
172188
.debug-go-tests:
173189
ifeq ($(PKG_TO_TEST), "")
174-
@echo "Please specify one or more packages to debug with argument PKG_TO_TEST=\"/path/to/pkg/1 /path/to/pkg/2\"...";
190+
@echo "Please specify one or more packages to debug with argument PKG_TO_TEST=\"/path/to/pkg/1 /path/to/pkg/2\"...";
175191
else
176192
@echo Debugging tests with command:
177-
dlv test ${dlv_test_pkg_to_test} --api-version=2 --listen=127.0.0.1:61179 ${DEBUG_TEST_EXTRA_FLAGS} -- -test.v -test.run=${TESTS_TO_RUN} ${GO_TEST_EXTRA_FLAGS}
193+
dlv test ${dlv_test_pkg_to_test} --api-version=2 --listen=127.0.0.1:61179 ${DEBUG_TEST_EXTRA_FLAGS} -- -test.v -test.run=${TESTS_TO_RUN} ${GO_TEST_EXTRA_FLAGS}
178194
endif
179195

180196
# Command to run specific tests in development. Can run all tests for one or more packages, or specific tests within packages.
181197
run-go-tests:
182198
@MYSQL_TEST=1 REDIS_TEST=1 MINIO_STORAGE_TEST=1 SAML_IDP_TEST=1 NETWORK_TEST=1 make .run-go-tests GO_TEST_MAKE_FLAGS="-v"
183199

184200
debug-go-tests:
185-
@MYSQL_TEST=1 REDIS_TEST=1 MINIO_STORAGE_TEST=1 SAML_IDP_TEST=1 NETWORK_TEST=1 make .debug-go-tests
201+
@MYSQL_TEST=1 REDIS_TEST=1 MINIO_STORAGE_TEST=1 SAML_IDP_TEST=1 NETWORK_TEST=1 make .debug-go-tests
186202

187203
# Command used in CI to run all tests.
188-
test-go: dump-test-schema generate-mock
189-
make .run-go-tests PKG_TO_TEST="./cmd/... ./ee/... ./orbit/pkg/... ./orbit/cmd/orbit ./pkg/... ./server/... ./tools/..."
204+
test-go: dump-test-schema generate-mock
205+
make .run-go-tests PKG_TO_TEST="$(CI_PKG_TO_TEST)"
190206

191207
analyze-go:
192208
go test -tags full,fts5,netgo -race -cover ./...

0 commit comments

Comments
 (0)