Skip to content

Commit 48b0701

Browse files
authored
GODRIVER-2093 Add more parallelization to test suite. (#1131)
1 parent 5edaf2b commit 48b0701

File tree

9 files changed

+54
-83
lines changed

9 files changed

+54
-83
lines changed

Makefile

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
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-
101
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)"
112
GODISTS=linux/amd64 linux/386 linux/arm64 linux/arm linux/s390x
123
TEST_TIMEOUT = 1800
@@ -25,25 +16,22 @@ add-license:
2516

2617
.PHONY: build
2718
build:
28-
go build $(BUILD_TAGS) $(PKGS)
19+
go build $(BUILD_TAGS) ./...
2920

3021
.PHONY: build-examples
3122
build-examples:
3223
go build $(BUILD_TAGS) ./examples/...
3324

3425
.PHONY: build-no-tags
3526
build-no-tags:
36-
go build $(PKGS)
27+
go build ./...
3728

3829
.PHONY: build-tests
3930
build-tests:
40-
for TEST in $(TEST_PKGS); do \
41-
go test $(BUILD_TAGS) -c $$TEST ; \
42-
if [ $$? -ne 0 ]; \
43-
then \
44-
exit 1; \
45-
fi \
46-
done
31+
# Use ^$ to match no tests so that no tests are actually run but all tests are
32+
# compiled. Run with -short to ensure none of the TestMain functions try to
33+
# connect to a server.
34+
go test -short $(BUILD_TAGS) -run ^$$ ./...
4735

4836
.PHONY: check-fmt
4937
check-fmt:
@@ -88,25 +76,19 @@ update-notices:
8876
### Local testing targets. ###
8977
.PHONY: test
9078
test:
91-
for TEST in $(TEST_PKGS) ; do \
92-
go test $(BUILD_TAGS) -timeout $(TEST_TIMEOUT)s $$TEST ; \
93-
done
79+
go test $(BUILD_TAGS) -timeout $(TEST_TIMEOUT)s -p 1 ./...
9480

9581
.PHONY: test-cover
9682
test-cover:
97-
for TEST in $(TEST_PKGS) ; do \
98-
go test $(BUILD_TAGS) -timeout $(TEST_TIMEOUT)s -cover $(COVER_ARGS) $$TEST ; \
99-
done
83+
go test $(BUILD_TAGS) -timeout $(TEST_TIMEOUT)s -cover $(COVER_ARGS) -p 1 ./...
10084

10185
.PHONY: test-race
10286
test-race:
103-
for TEST in $(TEST_PKGS) ; do \
104-
go test $(BUILD_TAGS) -timeout $(TEST_TIMEOUT)s -race $$TEST ; \
105-
done
87+
go test $(BUILD_TAGS) -timeout $(TEST_TIMEOUT)s -race -p 1 ./...
10688

10789
.PHONY: test-short
10890
test-short:
109-
go test $(BUILD_TAGS) -timeout 60s -short $(TEST_PKGS)
91+
go test $(BUILD_TAGS) -timeout 60s -short -p 1 ./...
11092

11193
### Evergreen specific targets. ###
11294
.PHONY: build-aws-ecs-test
@@ -115,9 +97,7 @@ build-aws-ecs-test:
11597

11698
.PHONY: evg-test
11799
evg-test:
118-
for TEST in $(TEST_PKGS); do \
119-
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 ; \
120-
done
100+
go test -exec "env PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) LD_LIBRARY_PATH=$(LD_LIBRARY_PATH)" $(BUILD_TAGS) -v -timeout $(TEST_TIMEOUT)s -p 1 ./... >> test.suite
121101

122102
.PHONY: evg-test-atlas
123103
evg-test-atlas:

etc/list_pkgs.sh

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

etc/list_test_pkgs.sh

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

internal/uuid/uuid_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ import (
1818
// Test that initializing many package-global UUID sources concurrently never leads to any duplicate
1919
// UUIDs being generated.
2020
func TestGlobalSource(t *testing.T) {
21+
t.Parallel()
22+
2123
t.Run("exp rand 1 UUID x 1,000,000 goroutines using a global source", func(t *testing.T) {
24+
t.Parallel()
25+
2226
if israce.Enabled {
2327
t.Skip("skipping as race detector is enabled and test exceeds 8128 goroutine limit")
2428
}
@@ -41,6 +45,8 @@ func TestGlobalSource(t *testing.T) {
4145
wg.Wait()
4246
})
4347
t.Run("exp rand 1 UUID x 1,000,000 goroutines each initializing a new source", func(t *testing.T) {
48+
t.Parallel()
49+
4450
if israce.Enabled {
4551
t.Skip("skipping as race detector is enabled and test exceeds 8128 goroutine limit")
4652
}
@@ -66,6 +72,8 @@ func TestGlobalSource(t *testing.T) {
6672
wg.Wait()
6773
})
6874
t.Run("exp rand 1,000 UUIDs x 1,000 goroutines each initializing a new source", func(t *testing.T) {
75+
t.Parallel()
76+
6977
// Read 1,000 UUIDs from each goroutine and assert that there is never a duplicate value, either
7078
// from the same goroutine or from separate goroutines.
7179
const iterations = 1000

mongo/integration/client_side_encryption_prose_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ const (
5353
)
5454

5555
func TestClientSideEncryptionProse(t *testing.T) {
56+
t.Parallel()
57+
5658
verifyClientSideEncryptionVarsSet(t)
5759
mt := mtest.New(t, mtest.NewOptions().MinServerVersion("4.2").Enterprise(true).CreateClient(false))
5860
defer mt.Close()
@@ -476,6 +478,8 @@ func TestClientSideEncryptionProse(t *testing.T) {
476478
assert.NotNil(mt, err, "expected InsertOne error for document over 16MiB, got nil")
477479
})
478480
mt.Run("5. views are prohibited", func(mt *mtest.T) {
481+
mt.Parallel()
482+
479483
kmsProviders := map[string]map[string]interface{}{
480484
"local": {
481485
"key": localMasterKey,
@@ -933,6 +937,8 @@ func TestClientSideEncryptionProse(t *testing.T) {
933937
}
934938
})
935939
mt.RunOpts("8. bypass mongocryptd spawning", noClientOpts, func(mt *mtest.T) {
940+
mt.Parallel()
941+
936942
kmsProviders := map[string]map[string]interface{}{
937943
"local": {
938944
"key": localMasterKey,
@@ -1081,6 +1087,8 @@ func TestClientSideEncryptionProse(t *testing.T) {
10811087
{"collection", mongo.CollectionStream},
10821088
}
10831089
mt.RunOpts("auto encryption errors", noClientOpts, func(mt *mtest.T) {
1090+
mt.Parallel()
1091+
10841092
for _, tc := range testCases {
10851093
mt.Run(tc.name, func(mt *mtest.T) {
10861094
autoEncryptionOpts := options.AutoEncryption().
@@ -1993,7 +2001,6 @@ func TestClientSideEncryptionProse(t *testing.T) {
19932001

19942002
mt.RunOpts("20. Bypass creating mongocryptd client when shared library is loaded",
19952003
noClientOpts, func(mt *mtest.T) {
1996-
19972004
cryptSharedLibPath := os.Getenv("CRYPT_SHARED_LIB_PATH")
19982005
if cryptSharedLibPath == "" {
19992006
mt.Skip("CRYPT_SHARED_LIB_PATH not set, skipping")

mongo/integration/client_test.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,8 @@ func TestClient(t *testing.T) {
515515
})
516516

517517
mt.Run("minimum RTT is monitored", func(mt *mtest.T) {
518+
mt.Parallel()
519+
518520
// Reset the client with a dialer that delays all network round trips by 300ms and set the
519521
// heartbeat interval to 100ms to reduce the time it takes to collect RTT samples.
520522
mt.ResetClient(options.Client().
@@ -553,6 +555,8 @@ func TestClient(t *testing.T) {
553555
// Test that if the minimum RTT is greater than the remaining timeout for an operation, the
554556
// operation is not sent to the server and no connections are closed.
555557
mt.Run("minimum RTT used to prevent sending requests", func(mt *mtest.T) {
558+
mt.Parallel()
559+
556560
// Assert that we can call Ping with a 250ms timeout.
557561
ctx, cancel := context.WithTimeout(context.Background(), 250*time.Millisecond)
558562
defer cancel()
@@ -610,9 +614,7 @@ func TestClient(t *testing.T) {
610614
})
611615

612616
mt.Run("RTT90 is monitored", func(mt *mtest.T) {
613-
if testing.Short() {
614-
t.Skip("skipping integration test in short mode")
615-
}
617+
mt.Parallel()
616618

617619
// Reset the client with a dialer that delays all network round trips by 300ms and set the
618620
// heartbeat interval to 100ms to reduce the time it takes to collect RTT samples.
@@ -652,9 +654,7 @@ func TestClient(t *testing.T) {
652654
// Test that if Timeout is set and the RTT90 is greater than the remaining timeout for an operation, the
653655
// operation is not sent to the server, fails with a timeout error, and no connections are closed.
654656
mt.Run("RTT90 used to prevent sending requests", func(mt *mtest.T) {
655-
if testing.Short() {
656-
t.Skip("skipping integration test in short mode")
657-
}
657+
mt.Parallel()
658658

659659
// Assert that we can call Ping with a 250ms timeout.
660660
ctx, cancel := context.WithTimeout(context.Background(), 250*time.Millisecond)
@@ -792,12 +792,16 @@ func TestClient(t *testing.T) {
792792
}
793793

794794
func TestClientStress(t *testing.T) {
795+
t.Parallel()
796+
795797
mtOpts := mtest.NewOptions().CreateClient(false)
796798
mt := mtest.New(t, mtOpts)
797799
defer mt.Close()
798800

799801
// Test that a Client can recover from a massive traffic spike after the traffic spike is over.
800802
mt.Run("Client recovers from traffic spike", func(mt *mtest.T) {
803+
mt.Parallel()
804+
801805
oid := primitive.NewObjectID()
802806
doc := bson.D{{Key: "_id", Value: oid}, {Key: "key", Value: "value"}}
803807
_, err := mt.Coll.InsertOne(context.Background(), doc)
@@ -852,6 +856,8 @@ func TestClientStress(t *testing.T) {
852856
SetPoolMonitor(tpm.PoolMonitor).
853857
SetMaxPoolSize(maxPoolSize))
854858
mt.RunOpts(fmt.Sprintf("maxPoolSize %d", maxPoolSize), maxPoolSizeOpt, func(mt *mtest.T) {
859+
mt.Parallel()
860+
855861
// Print the count of connection created, connection closed, and pool clear events
856862
// collected during the test to help with debugging.
857863
defer func() {

mongo/integration/collection_test.go

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ package integration
88

99
import (
1010
"context"
11-
"os"
1211
"strings"
1312
"testing"
1413
"time"
@@ -120,7 +119,11 @@ func TestCollection(t *testing.T) {
120119
})
121120
})
122121
mt.RunOpts("insert many", noClientOpts, func(mt *mtest.T) {
122+
mt.Parallel()
123+
123124
mt.Run("success", func(mt *mtest.T) {
125+
mt.Parallel()
126+
124127
want1 := int32(11)
125128
want2 := int32(12)
126129
docs := []interface{}{
@@ -137,11 +140,7 @@ func TestCollection(t *testing.T) {
137140
assert.Equal(mt, want2, res.InsertedIDs[2], "expected inserted ID %v, got %v", want2, res.InsertedIDs[2])
138141
})
139142
mt.Run("batches", func(mt *mtest.T) {
140-
// TODO(GODRIVER-425): remove this as part a larger project to refactor integration and other longrunning
141-
// TODO tasks.
142-
if os.Getenv("EVR_TASK_ID") == "" {
143-
mt.Skip("skipping long running integration test outside of evergreen")
144-
}
143+
mt.Parallel()
145144

146145
const (
147146
megabyte = 10 * 10 * 10 * 10 * 10 * 10
@@ -167,11 +166,7 @@ func TestCollection(t *testing.T) {
167166
assert.Equal(mt, numDocs, len(res.InsertedIDs), "expected %v inserted IDs, got %v", numDocs, len(res.InsertedIDs))
168167
})
169168
mt.Run("large document batches", func(mt *mtest.T) {
170-
// TODO(GODRIVER-425): remove this as part a larger project to refactor integration and other longrunning
171-
// TODO tasks.
172-
if os.Getenv("EVR_TASK_ID") == "" {
173-
mt.Skip("skipping long running integration test outside of evergreen")
174-
}
169+
mt.Parallel()
175170

176171
docs := []interface{}{create16MBDocument(mt), create16MBDocument(mt)}
177172
_, err := mt.Coll.InsertMany(context.Background(), docs)
@@ -182,6 +177,8 @@ func TestCollection(t *testing.T) {
182177
assert.Equal(mt, "insert", evt.CommandName, "expected 'insert' event, got '%v'", evt.CommandName)
183178
})
184179
mt.RunOpts("write error", noClientOpts, func(mt *mtest.T) {
180+
mt.Parallel()
181+
185182
docs := []interface{}{
186183
bson.D{{"_id", primitive.NewObjectID()}},
187184
bson.D{{"_id", primitive.NewObjectID()}},
@@ -212,7 +209,9 @@ func TestCollection(t *testing.T) {
212209
}
213210
})
214211
mt.Run("return only inserted ids", func(mt *mtest.T) {
215-
id := int32(11)
212+
mt.Parallel()
213+
214+
id := int32(15)
216215
docs := []interface{}{
217216
bson.D{{"_id", id}},
218217
bson.D{{"_id", id}},
@@ -249,11 +248,7 @@ func TestCollection(t *testing.T) {
249248
}
250249
})
251250
mt.Run("writeError index", func(mt *mtest.T) {
252-
// TODO(GODRIVER-425): remove this as part a larger project to refactor integration and other longrunning
253-
// TODO tasks.
254-
if os.Getenv("EVR_TASK_ID") == "" {
255-
mt.Skip("skipping long running integration test outside of evergreen")
256-
}
251+
mt.Parallel()
257252

258253
// force multiple batches
259254
numDocs := 700000

mongo/integration/csot_cse_prose_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ func TestCSOTClientSideEncryptionProse(t *testing.T) {
3030

3131
mt.RunOpts("2. maxTimeMS is not set for commands sent to mongocryptd",
3232
noClientOpts, func(mt *mtest.T) {
33-
if testing.Short() {
34-
mt.Skip("skipping integration test in short mode")
35-
}
36-
3733
kmsProviders := map[string]map[string]interface{}{
3834
"local": {
3935
"key": localMasterKey,

x/mongo/driver/topology/pool_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,9 @@ func TestPool(t *testing.T) {
513513
time.Sleep(50 * time.Millisecond)
514514
c2, err := p.checkOut(context.Background())
515515
noerr(t, err)
516-
assert.NotEqualf(t, c1, c2, "expected a new connection on 2nd check out after idle timeout expires")
516+
// Assert that the connection pointers are not equal. Don't use "assert.NotEqual" because it asserts
517+
// non-equality of fields, possibly accessing some fields non-atomically and causing a race condition.
518+
assert.True(t, c1 != c2, "expected a new connection on 2nd check out after idle timeout expires")
517519
assert.Equalf(t, 2, d.lenopened(), "should have opened 2 connections")
518520
assert.Equalf(t, 1, p.totalConnectionCount(), "pool should have 1 total connection")
519521

0 commit comments

Comments
 (0)