Skip to content

Commit ec7894e

Browse files
authored
GODRIVER-2445 Clean up Makefile and run all package tests in targets. (#997)
1 parent 4f4770c commit ec7894e

File tree

9 files changed

+87
-126
lines changed

9 files changed

+87
-126
lines changed

Makefile

Lines changed: 76 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,43 @@
1-
BSON_PKGS = $(shell etc/list_pkgs.sh ./bson)
2-
BSON_TEST_PKGS = $(shell etc/list_test_pkgs.sh ./bson)
3-
EVENT_PKGS = $(shell etc/list_pkgs.sh ./event)
4-
EVENT_TEST_PKGS = $(shell etc/list_test_pkgs.sh ./event)
5-
MONGO_PKGS = $(shell etc/list_pkgs.sh ./mongo)
6-
MONGO_TEST_PKGS = $(shell etc/list_test_pkgs.sh ./mongo)
7-
UNSTABLE_PKGS = $(shell etc/list_pkgs.sh ./x)
8-
UNSTABLE_TEST_PKGS = $(shell etc/list_test_pkgs.sh ./x)
9-
TAG_PKG = $(shell etc/list_pkgs.sh ./tag)
10-
TAG_TEST_PKG = $(shell etc/list_test_pkgs.sh ./tag)
11-
EXAMPLES_PKGS = $(shell etc/list_pkgs.sh ./examples)
12-
EXAMPLES_TEST_PKGS = $(shell etc/list_test_pkgs.sh ./examples)
13-
PKGS = $(BSON_PKGS) $(EVENT_PKGS) $(MONGO_PKGS) $(UNSTABLE_PKGS) $(TAG_PKG) $(EXAMPLES_PKGS)
14-
TEST_PKGS = $(BSON_TEST_PKGS) $(EVENT_TEST_PKGS) $(MONGO_TEST_PKGS) $(UNSTABLE_TEST_PKGS) $(TAG_PKG) $(EXAMPLES_TEST_PKGS)
1+
# We list packages with shell scripts and loop through them to avoid testing with ./...
2+
# Running go test ./... will run tests in all packages concurrently which can lead to
3+
# unexpected errors.
4+
#
5+
# TODO(GODRIVER-2093): Use ./... to run tests in all packages with parallelism and remove
6+
# these PKG variables and loops from all make targets.
7+
PKGS = $(shell etc/list_pkgs.sh)
8+
TEST_PKGS = $(shell etc/list_test_pkgs.sh)
9+
1510
ATLAS_URIS = "$(ATLAS_FREE)" "$(ATLAS_REPLSET)" "$(ATLAS_SHARD)" "$(ATLAS_TLS11)" "$(ATLAS_TLS12)" "$(ATLAS_FREE_SRV)" "$(ATLAS_REPLSET_SRV)" "$(ATLAS_SHARD_SRV)" "$(ATLAS_TLS11_SRV)" "$(ATLAS_TLS12_SRV)" "$(ATLAS_SERVERLESS)" "$(ATLAS_SERVERLESS_SRV)"
1611
GODISTS=linux/amd64 linux/386 linux/arm64 linux/arm linux/s390x
17-
1812
TEST_TIMEOUT = 1800
1913

14+
### Utility targets. ###
2015
.PHONY: default
21-
default: check-env check-fmt build-examples lint test-cover test-race
16+
default: add-license build build-examples check-env check-fmt lint test-short
2217

23-
.PHONY: check-env
24-
check-env:
25-
etc/check_env.sh
18+
.PHONY: add-license
19+
add-license:
20+
# Find all .go files not in the vendor directory and try to write a license notice.
21+
find . -path ./vendor -prune -o -type f -name "*.go" -print | xargs ./etc/add_license.sh
22+
# Check for any changes made with -G. to ignore permissions changes. Exit with a non-zero
23+
# exit code if there is a diff.
24+
git diff -G. --quiet
2625

27-
.PHONY: doc
28-
doc:
29-
godoc -http=:6060 -index
26+
.PHONY: build
27+
build:
28+
go build $(BUILD_TAGS) $(PKGS)
3029

3130
.PHONY: build-examples
3231
build-examples:
3332
go build $(BUILD_TAGS) ./examples/... ./x/mongo/driver/examples/...
3433

35-
.PHONY: build
36-
build:
37-
go build $(BUILD_TAGS) $(filter-out ./core/auth/internal/gssapi,$(PKGS))
38-
3934
.PHONY: build-no-tags
4035
build-no-tags:
41-
go build $(filter-out ./core/auth/internal/gssapi,$(PKGS))
36+
go build $(PKGS)
4237

4338
.PHONY: build-tests
4439
build-tests:
45-
for TEST in $(PKGS); do \
40+
for TEST in $(TEST_PKGS); do \
4641
go test $(BUILD_TAGS) -c $$TEST ; \
4742
if [ $$? -ne 0 ]; \
4843
then \
@@ -54,6 +49,10 @@ build-tests:
5449
check-fmt:
5550
etc/check_fmt.sh $(PKGS)
5651

52+
.PHONY: doc
53+
doc:
54+
godoc -http=:6060 -index
55+
5756
.PHONY: fmt
5857
fmt:
5958
gofmt -l -s -w $(PKGS)
@@ -68,14 +67,11 @@ lint:
6867
eval $$command ; \
6968
done
7069

71-
.PHONY: add-license
72-
add-license:
73-
# Find all .go files not in the vendor directory and try to write a license notice.
74-
find . -path ./vendor -prune -o -type f -name "*.go" -print | xargs ./etc/add-license.sh
75-
# Check for any changes made with -G. to ignore permissions changes. Exit with a non-zero
76-
# exit code if there is a diff.
77-
git diff -G. --quiet
70+
.PHONY: update-notices
71+
update-notices:
72+
etc/generate_notices.pl > THIRD-PARTY-NOTICES
7873

74+
### Local testing targets. ###
7975
.PHONY: test
8076
test:
8177
for TEST in $(TEST_PKGS) ; do \
@@ -85,105 +81,69 @@ test:
8581
.PHONY: test-cover
8682
test-cover:
8783
for TEST in $(TEST_PKGS) ; do \
88-
go test $(BUILD_TAGS) -timeout $(TEST_TIMEOUT)s -cover $(COVER_ARGS) $$TEST ; \
89-
done
84+
go test $(BUILD_TAGS) -timeout $(TEST_TIMEOUT)s -cover $(COVER_ARGS) $$TEST ; \
85+
done
9086

9187
.PHONY: test-race
9288
test-race:
9389
for TEST in $(TEST_PKGS) ; do \
94-
go test $(BUILD_TAGS) -timeout $(TEST_TIMEOUT)s -race $(COVER_ARGS) $$TEST ; \
95-
done
90+
go test $(BUILD_TAGS) -timeout $(TEST_TIMEOUT)s -race $$TEST ; \
91+
done
9692

9793
.PHONY: test-short
9894
test-short:
99-
go test $(BUILD_TAGS) -timeout 60s -short $(COVER_ARGS) ./...
100-
101-
.PHONY: update-bson-corpus-tests
102-
update-bson-corpus-tests:
103-
etc/update-spec-tests.sh bson-corpus
104-
105-
.PHONY: update-connection-string-tests
106-
update-connection-string-tests:
107-
etc/update-spec-tests.sh connection-string
108-
109-
.PHONY: update-crud-tests
110-
update-crud-tests:
111-
etc/update-spec-tests.sh crud
95+
go test $(BUILD_TAGS) -timeout 60s -short $(TEST_PKGS)
11296

113-
.PHONY: update-initial-dns-seedlist-discovery-tests
114-
update-initial-dns-seedlist-discovery-tests:
115-
etc/update-spec-tests.sh initial-dns-seedlist-discovery
116-
117-
.PHONY: update-max-staleness-tests
118-
update-max-staleness-tests:
119-
etc/update-spec-tests.sh max-staleness
120-
121-
.PHONY: update-server-discovery-and-monitoring-tests
122-
update-server-discovery-and-monitoring-tests:
123-
etc/update-spec-tests.sh server-discovery-and-monitoring
124-
125-
.PHONY: update-server-selection-tests
126-
update-server-selection-tests:
127-
etc/update-spec-tests.sh server-selection
128-
129-
.PHONY: update-notices
130-
update-notices:
131-
etc/generate-notices.pl > THIRD-PARTY-NOTICES
97+
### Evergreen specific targets. ###
98+
.PHONY: build-aws-ecs-test
99+
build-aws-ecs-test:
100+
go build $(BUILD_TAGS) ./mongo/testaws/main.go
132101

133-
# Evergreen specific targets
134102
.PHONY: evg-test
135103
evg-test:
136104
for TEST in $(TEST_PKGS); do \
137105
go test -exec "env PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) LD_LIBRARY_PATH=$(LD_LIBRARY_PATH)" $(BUILD_TAGS) -v -timeout $(TEST_TIMEOUT)s $$TEST >> test.suite ; \
138106
done
139107

140-
.PHONY: evg-test-auth
141-
evg-test-auth:
142-
go run -tags gssapi ./x/mongo/driver/examples/count/main.go -uri $(MONGODB_URI)
143-
144108
.PHONY: evg-test-atlas
145109
evg-test-atlas:
146110
go run ./mongo/testatlas/main.go $(ATLAS_URIS)
147111

148-
.PHONY: evg-test-ocsp
149-
evg-test-ocsp:
150-
go test -v ./mongo -run TestOCSP $(OCSP_TLS_SHOULD_SUCCEED) >> test.suite
151-
152-
.PHONY: build-aws-ecs-test
153-
build-aws-ecs-test:
154-
go build $(BUILD_TAGS) ./mongo/testaws/main.go
155-
156112
.PHONY: evg-test-atlas-data-lake
157113
evg-test-atlas-data-lake:
158114
ATLAS_DATA_LAKE_INTEGRATION_TEST=true go test -v ./mongo/integration -run TestUnifiedSpecs/atlas-data-lake-testing >> spec_test.suite
159115
ATLAS_DATA_LAKE_INTEGRATION_TEST=true go test -v ./mongo/integration -run TestAtlasDataLake >> spec_test.suite
160116

161-
.PHONY: evg-test-versioned-api
162-
evg-test-versioned-api:
163-
for TEST_PKG in ./mongo ./mongo/integration ./mongo/integration/unified; do \
164-
go test -exec "env PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) LD_LIBRARY_PATH=$(LD_LIBRARY_PATH)" $(BUILD_TAGS) -v -timeout $(TEST_TIMEOUT)s $$TEST_PKG >> test.suite ; \
165-
done
117+
.PHONY: evg-test-auth
118+
evg-test-auth:
119+
go run -tags gssapi ./x/mongo/driver/examples/count/main.go -uri $(MONGODB_URI)
120+
121+
.PHONY: evg-test-kmip
122+
evg-test-kmip:
123+
go test -exec "env PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) LD_LIBRARY_PATH=$(LD_LIBRARY_PATH)" $(BUILD_TAGS) -v -timeout $(TEST_TIMEOUT)s ./mongo/integration -run TestClientSideEncryptionSpec/kmipKMS >> test.suite
124+
go test -exec "env PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) LD_LIBRARY_PATH=$(LD_LIBRARY_PATH)" $(BUILD_TAGS) -v -timeout $(TEST_TIMEOUT)s ./mongo/integration -run TestClientSideEncryptionProse/data_key_and_double_encryption >> test.suite
125+
go test -exec "env PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) LD_LIBRARY_PATH=$(LD_LIBRARY_PATH)" $(BUILD_TAGS) -v -timeout $(TEST_TIMEOUT)s ./mongo/integration -run TestClientSideEncryptionProse/corpus >> test.suite
126+
go test -exec "env PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) LD_LIBRARY_PATH=$(LD_LIBRARY_PATH)" $(BUILD_TAGS) -v -timeout $(TEST_TIMEOUT)s ./mongo/integration -run TestClientSideEncryptionProse/custom_endpoint >> test.suite
127+
go test -exec "env PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) LD_LIBRARY_PATH=$(LD_LIBRARY_PATH)" $(BUILD_TAGS) -v -timeout $(TEST_TIMEOUT)s ./mongo/integration -run TestClientSideEncryptionProse/kms_tls_options_test >> test.suite
128+
129+
.PHONY: evg-test-kms
130+
evg-test-kms:
131+
go test -exec "env PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) LD_LIBRARY_PATH=$(LD_LIBRARY_PATH)" $(BUILD_TAGS) -v -timeout $(TEST_TIMEOUT)s ./mongo/integration -run TestClientSideEncryptionProse/kms_tls_tests >> test.suite
166132

167133
.PHONY: evg-test-load-balancers
168134
evg-test-load-balancers:
135+
# Load balancer should be tested with all unified tests as well as tests in the following
136+
# components: retryable reads, retryable writes, change streams, initial DNS seedlist discovery.
169137
go test $(BUILD_TAGS) ./mongo/integration -run TestUnifiedSpecs/retryable-reads -v -timeout $(TEST_TIMEOUT)s >> test.suite
170138
go test $(BUILD_TAGS) ./mongo/integration -run TestRetryableWritesSpec -v -timeout $(TEST_TIMEOUT)s >> test.suite
171139
go test $(BUILD_TAGS) ./mongo/integration -run TestChangeStreamSpec -v -timeout $(TEST_TIMEOUT)s >> test.suite
172140
go test $(BUILD_TAGS) ./mongo/integration -run TestInitialDNSSeedlistDiscoverySpec/load_balanced -v -timeout $(TEST_TIMEOUT)s >> test.suite
173141
go test $(BUILD_TAGS) ./mongo/integration -run TestLoadBalancerSupport -v -timeout $(TEST_TIMEOUT)s >> test.suite
174142
go test $(BUILD_TAGS) ./mongo/integration/unified -run TestUnifiedSpec -v -timeout $(TEST_TIMEOUT)s >> test.suite
175143

176-
.PHONY: evg-test-kms
177-
evg-test-kms:
178-
go test -exec "env PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) LD_LIBRARY_PATH=$(LD_LIBRARY_PATH)" $(BUILD_TAGS) -v -timeout $(TEST_TIMEOUT)s ./mongo/integration -run TestClientSideEncryptionProse/kms_tls_tests >> test.suite
179-
180-
.PHONY: evg-test-kmip
181-
evg-test-kmip:
182-
go test -exec "env PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) LD_LIBRARY_PATH=$(LD_LIBRARY_PATH)" $(BUILD_TAGS) -v -timeout $(TEST_TIMEOUT)s ./mongo/integration -run TestClientSideEncryptionSpec/kmipKMS >> test.suite
183-
go test -exec "env PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) LD_LIBRARY_PATH=$(LD_LIBRARY_PATH)" $(BUILD_TAGS) -v -timeout $(TEST_TIMEOUT)s ./mongo/integration -run TestClientSideEncryptionProse/data_key_and_double_encryption >> test.suite
184-
go test -exec "env PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) LD_LIBRARY_PATH=$(LD_LIBRARY_PATH)" $(BUILD_TAGS) -v -timeout $(TEST_TIMEOUT)s ./mongo/integration -run TestClientSideEncryptionProse/corpus >> test.suite
185-
go test -exec "env PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) LD_LIBRARY_PATH=$(LD_LIBRARY_PATH)" $(BUILD_TAGS) -v -timeout $(TEST_TIMEOUT)s ./mongo/integration -run TestClientSideEncryptionProse/custom_endpoint >> test.suite
186-
go test -exec "env PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) LD_LIBRARY_PATH=$(LD_LIBRARY_PATH)" $(BUILD_TAGS) -v -timeout $(TEST_TIMEOUT)s ./mongo/integration -run TestClientSideEncryptionProse/kms_tls_options_test >> test.suite
144+
.PHONY: evg-test-ocsp
145+
evg-test-ocsp:
146+
go test -v ./mongo -run TestOCSP $(OCSP_TLS_SHOULD_SUCCEED) >> test.suite
187147

188148
.PHONY: evg-test-serverless
189149
evg-test-serverless:
@@ -207,14 +167,24 @@ evg-test-serverless:
207167
go test $(BUILD_TAGS) ./mongo/integration -run TestCursor -v -timeout $(TEST_TIMEOUT)s >> test.suite
208168
go test $(BUILD_TAGS) ./mongo/integration/unified -run TestUnifiedSpec -v -timeout $(TEST_TIMEOUT)s >> test.suite
209169

210-
# benchmark specific targets and support
170+
.PHONY: evg-test-versioned-api
171+
evg-test-versioned-api:
172+
# Versioned API related tests are in the mongo, integration and unified packages.
173+
for TEST_PKG in ./mongo ./mongo/integration ./mongo/integration/unified; do \
174+
go test -exec "env PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) LD_LIBRARY_PATH=$(LD_LIBRARY_PATH)" $(BUILD_TAGS) -v -timeout $(TEST_TIMEOUT)s $$TEST_PKG >> test.suite ; \
175+
done
176+
177+
### Benchmark specific targets and support. ###
178+
.PHONY: benchmark
179+
benchmark:perf
180+
go test $(BUILD_TAGS) -benchmem -bench=. ./benchmark
181+
182+
.PHONY: driver-benchmark
183+
driver-benchmark:perf
184+
@go run cmd/godriver-benchmark/main.go | tee perf.suite
185+
211186
perf:driver-test-data.tar.gz
212187
tar -zxf $< $(if $(eq $(UNAME_S),Darwin),-s , --transform=s)/data/perf/
213188
@touch $@
214189
driver-test-data.tar.gz:
215190
curl --retry 5 "https://s3.amazonaws.com/boxes.10gen.com/build/driver-test-data.tar.gz" -o driver-test-data.tar.gz --silent --max-time 120
216-
benchmark:perf
217-
go test $(BUILD_TAGS) -benchmem -bench=. ./benchmark
218-
driver-benchmark:perf
219-
@go run cmd/godriver-benchmark/main.go | tee perf.suite
220-
.PHONY:benchmark driver-benchmark
File renamed without changes.

etc/check_env.sh

Lines changed: 0 additions & 16 deletions
This file was deleted.

etc/check_fmt.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#!/usr/bin/env bash
2+
# check_fmt gopackages...
3+
# Runs gofmt on given packages and checks that *_example_test.go files have wrapped lines.
24

35
gofmt_out="$(gofmt -l -s "$@")"
46

File renamed without changes.

etc/list_pkgs.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/sh
22
# list_pkgs <directory>
3+
# Lists all Go packages in the given directory.
4+
35
directory="$1"
46
if [ -z "$directory" ]; then
57
directory="."

etc/list_test_pkgs.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/sh
2-
# list_pkgs <directory>
2+
# list_test_pkgs <directory>
3+
# Lists all Go packages with _test.go files in the given directory.
4+
35
directory="$1"
46
if [ -z "$directory" ]; then
57
directory="."

etc/update-spec-tests.sh renamed to etc/update_spec_tests.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
2-
3-
# This script is used to fetch the latest JSON tests for the CRUD spec. It puts the tests in the
4-
# direcory $reporoot/data/crud. It should be run from the root of the repository.
2+
# update_spec_tests spec
3+
# This script is used to fetch the latest tests for the given spec. It puts the tests in the
4+
# directory data/[specname]. It should be run from the root of the repository.
55

66
set -o errexit
77
set -o nounset

internal/testutil/israce/race.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// not use this file except in compliance with the License. You may obtain
55
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
66

7+
//go:build race
78
// +build race
89

910
// Package israce reports if the Go race detector is enabled.

0 commit comments

Comments
 (0)