Skip to content

Commit bf833d5

Browse files
prestonvasquezqingyang-hubenjirewiskevinAlbs
authored
Release/1.11 (#1146)
* GODRIVER-2651 Break NoWritesPerformed-Only Error Sequence (#1135) Co-authored-by: Qingyang Hu <[email protected]> Co-authored-by: Benjamin Rewis <[email protected]> Co-authored-by: Kevin Albertson <[email protected]> Co-authored-by: Qingyang Hu <[email protected]> Co-authored-by: Benjamin Rewis <[email protected]> * GODRIVER-2333 Assert that Ping op succeeds initial DNS spec tests (#1124) * GODRIVER-2577 Retry heartbeat on timeout to prevent pool cleanup in FAAS pause. (#1133) * resolve merge conflicts Co-authored-by: Qingyang Hu <[email protected]> Co-authored-by: Benjamin Rewis <[email protected]> Co-authored-by: Kevin Albertson <[email protected]>
1 parent 4803b59 commit bf833d5

File tree

65 files changed

+583
-61
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+583
-61
lines changed

.evergreen/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,7 @@ tasks:
10451045
- name: sa-fmt
10461046
tags: ["static-analysis"]
10471047
commands:
1048+
- func: install-linters
10481049
- func: run-make
10491050
vars:
10501051
targets: check-fmt

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ build-tests:
4747

4848
.PHONY: check-fmt
4949
check-fmt:
50-
etc/check_fmt.sh $(PKGS)
50+
etc/check_fmt.sh
5151

5252
# check-modules runs "go mod tidy" then "go mod vendor" and exits with a non-zero exit code if there
5353
# are any module or vendored modules changes. The intent is to confirm two properties:
@@ -69,7 +69,7 @@ doc:
6969

7070
.PHONY: fmt
7171
fmt:
72-
gofmt -l -s -w $(PKGS)
72+
go fmt ./...
7373

7474
.PHONY: lint
7575
lint:

etc/check_fmt.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
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.
2+
# check_fmt
3+
# Runs go fmt on all packages in the repo and checks that *_example_test.go files have wrapped lines.
44

5-
gofmt_out="$(gofmt -l -s "$@")"
5+
gofmt_out="$(go fmt ./...)"
66

77
if [[ $gofmt_out ]]; then
8-
echo "gofmt check failed for:";
8+
echo "go fmt check failed for:";
99
sed -e 's/^/ - /' <<< "$gofmt_out";
1010
exit 1;
1111
fi
@@ -16,7 +16,7 @@ fi
1616
# E.g ignored lines:
1717
# // "mongodb://ldap-user:ldap-pwd@localhost:27017/?authMechanism=PLAIN"
1818
# // (https://www.mongodb.com/docs/manual/core/authentication-mechanisms-enterprise/#security-auth-ldap).
19-
lll_out="$(find "$@" -type f -name "*_examples_test.go" | lll -w 4 -l 80 -e '^\s*\/\/.+:\/\/' --files)"
19+
lll_out="$(find . -type f -name "*_examples_test.go" | lll -w 4 -l 80 -e '^\s*\/\/.+:\/\/' --files)"
2020

2121
if [[ $lll_out ]]; then
2222
echo "lll check failed for:";

mongo/crud_examples_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -749,8 +749,9 @@ func ExampleClient_StartSession_withTransaction() {
749749
result, err := sess.WithTransaction(
750750
context.TODO(),
751751
func(sessCtx mongo.SessionContext) (interface{}, error) {
752-
// Use sessCtx as the Context parameter for InsertOne and FindOne so
753-
// both operations are run in a transaction.
752+
// Use the mongo.SessionContext as the Context parameter for
753+
// InsertOne and FindOne so both operations are run in the same
754+
// transaction.
754755

755756
coll := client.Database("db").Collection("coll")
756757
res, err := coll.InsertOne(sessCtx, bson.D{{"x", 1}})

mongo/integration/initial_dns_seedlist_discovery_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@ import (
1515
"runtime"
1616
"strings"
1717
"testing"
18+
"time"
1819

1920
"go.mongodb.org/mongo-driver/bson"
2021
"go.mongodb.org/mongo-driver/internal/testutil/assert"
22+
"go.mongodb.org/mongo-driver/mongo"
2123
"go.mongodb.org/mongo-driver/mongo/description"
2224
"go.mongodb.org/mongo-driver/mongo/integration/mtest"
2325
"go.mongodb.org/mongo-driver/mongo/options"
26+
"go.mongodb.org/mongo-driver/mongo/readpref"
2427
"go.mongodb.org/mongo-driver/x/mongo/driver/connstring"
2528
"go.mongodb.org/mongo-driver/x/mongo/driver/topology"
2629
)
@@ -37,19 +40,26 @@ type seedlistTest struct {
3740
NumHosts *int `bson:"numHosts"`
3841
Error bool `bson:"error"`
3942
Options bson.Raw `bson:"options"`
43+
Ping *bool `bson:"ping"`
4044
}
4145

4246
func TestInitialDNSSeedlistDiscoverySpec(t *testing.T) {
4347
mt := mtest.New(t, noClientOpts)
4448
defer mt.Close()
4549

4650
mt.RunOpts("replica set", mtest.NewOptions().Topologies(mtest.ReplicaSet).CreateClient(false), func(mt *mtest.T) {
51+
mt.Parallel()
52+
4753
runSeedlistDiscoveryDirectory(mt, "replica-set")
4854
})
4955
mt.RunOpts("sharded", mtest.NewOptions().Topologies(mtest.Sharded).CreateClient(false), func(mt *mtest.T) {
56+
mt.Parallel()
57+
5058
runSeedlistDiscoveryDirectory(mt, "sharded")
5159
})
5260
mt.RunOpts("load balanced", mtest.NewOptions().Topologies(mtest.LoadBalanced).CreateClient(false), func(mt *mtest.T) {
61+
mt.Parallel()
62+
5363
runSeedlistDiscoveryDirectory(mt, "load-balanced")
5464
})
5565
}
@@ -63,6 +73,24 @@ func runSeedlistDiscoveryDirectory(mt *mtest.T, subdirectory string) {
6373
}
6474
}
6575

76+
// runSeedlistDiscoveryPingTest will create a new connection using the test URI and attempt to "ping" the server.
77+
func runSeedlistDiscoveryPingTest(mt *mtest.T, clientOpts *options.ClientOptions) {
78+
ctx := context.Background()
79+
80+
client, err := mongo.Connect(ctx, clientOpts)
81+
assert.Nil(mt, err, "Connect error: %v", err)
82+
83+
defer func() { _ = client.Disconnect(ctx) }()
84+
85+
// Create a context with a timeout to prevent the ping operation from blocking indefinitely.
86+
pingCtx, cancel := context.WithTimeout(ctx, 1*time.Second)
87+
defer cancel()
88+
89+
// Ping the server.
90+
err = client.Ping(pingCtx, readpref.Nearest())
91+
assert.Nil(mt, err, "Ping error: %v", err)
92+
}
93+
6694
func runSeedlistDiscoveryTest(mt *mtest.T, file string) {
6795
content, err := ioutil.ReadFile(file)
6896
assert.Nil(mt, err, "ReadFile error for %v: %v", file, err)
@@ -131,6 +159,10 @@ func runSeedlistDiscoveryTest(mt *mtest.T, file string) {
131159
_, err := getServerByAddress(host, topo)
132160
assert.Nil(mt, err, "error finding host %q: %v", host, err)
133161
}
162+
163+
if ping := test.Ping; ping == nil || *ping {
164+
runSeedlistDiscoveryPingTest(mt, opts)
165+
}
134166
}
135167

136168
func buildSet(list []string) map[string]struct{} {
@@ -230,6 +262,14 @@ func getServerByAddress(address string, topo *topology.Topology) (description.Se
230262
if err != nil {
231263
return description.Server{}, err
232264
}
265+
266+
// If the selected server is a topology.SelectedServer, then we can get the description without creating a
267+
// connect pool.
268+
topologySelectedServer, ok := selectedServer.(*topology.SelectedServer)
269+
if ok {
270+
return topologySelectedServer.Description().Server, nil
271+
}
272+
233273
selectedServerConnection, err := selectedServer.Connection(context.Background())
234274
if err != nil {
235275
return description.Server{}, err

mongo/integration/retryable_writes_prose_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ func TestRetryableWritesProse(t *testing.T) {
282282

283283
require.True(mt, secondFailPointConfigured)
284284

285-
// Assert that the "NotWritablePrimary" error is returned.
285+
// Assert that the "ShutdownInProgress" error is returned.
286286
require.True(mt, err.(mongo.WriteException).HasErrorCode(int(shutdownInProgressErrorCode)))
287287
})
288288
}

testdata/initial-dns-seedlist-discovery/load-balanced/loadBalanced-directConnection.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
"loadBalanced": true,
1111
"ssl": true,
1212
"directConnection": false
13-
}
13+
},
14+
"ping": true
1415
}

testdata/initial-dns-seedlist-discovery/load-balanced/loadBalanced-directConnection.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ options:
1111
loadBalanced: true
1212
ssl: true
1313
directConnection: false
14+
ping: true

testdata/initial-dns-seedlist-discovery/load-balanced/loadBalanced-true-txt.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
"options": {
1010
"loadBalanced": true,
1111
"ssl": true
12-
}
12+
},
13+
"ping": true
1314
}

testdata/initial-dns-seedlist-discovery/load-balanced/loadBalanced-true-txt.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ hosts:
88
options:
99
loadBalanced: true
1010
ssl: true
11+
ping: true

testdata/initial-dns-seedlist-discovery/load-balanced/srvMaxHosts-zero-txt.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
"loadBalanced": true,
1111
"srvMaxHosts": 0,
1212
"ssl": true
13-
}
13+
},
14+
"ping": true
1415
}

testdata/initial-dns-seedlist-discovery/load-balanced/srvMaxHosts-zero-txt.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ options:
88
loadBalanced: true
99
srvMaxHosts: 0
1010
ssl: true
11+
ping: true

testdata/initial-dns-seedlist-discovery/load-balanced/srvMaxHosts-zero.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
"loadBalanced": true,
1111
"srvMaxHosts": 0,
1212
"ssl": true
13-
}
13+
},
14+
"ping": true
1415
}

testdata/initial-dns-seedlist-discovery/load-balanced/srvMaxHosts-zero.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ options:
88
loadBalanced: true
99
srvMaxHosts: 0
1010
ssl: true
11+
ping: true

testdata/initial-dns-seedlist-discovery/replica-set/direct-connection-false.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@
1111
"options": {
1212
"ssl": true,
1313
"directConnection": false
14-
}
14+
},
15+
"ping": true
1516
}

testdata/initial-dns-seedlist-discovery/replica-set/direct-connection-false.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ hosts:
88
options:
99
ssl: true
1010
directConnection: false
11+
ping: true
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"uri": "mongodb+srv://b*b%40f3tt%3D:%244to%40L8%[email protected]/mydb%3F?replicaSet=repl0",
3+
"seeds": [
4+
"localhost.test.build.10gen.cc:27017"
5+
],
6+
"hosts": [
7+
"localhost:27017",
8+
"localhost:27018",
9+
"localhost:27019"
10+
],
11+
"options": {
12+
"replicaSet": "repl0",
13+
"ssl": true
14+
},
15+
"parsed_options": {
16+
"user": "b*b@f3tt=",
17+
"password": "$4to@L8=MC",
18+
"db": "mydb?"
19+
},
20+
"ping": false,
21+
"comment": "Encoded user, pass, and DB parse correctly"
22+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
uri: "mongodb+srv://b*b%40f3tt%3D:%244to%40L8%[email protected]/mydb%3F?replicaSet=repl0"
2+
seeds:
3+
- localhost.test.build.10gen.cc:27017
4+
hosts:
5+
- localhost:27017
6+
- localhost:27018
7+
- localhost:27019
8+
options:
9+
replicaSet: repl0
10+
ssl: true
11+
parsed_options:
12+
user: "b*b@f3tt="
13+
password: "$4to@L8=MC"
14+
db: "mydb?"
15+
# Don't run a ping for URIs that include userinfo. Ping doesn't require authentication, so missing
16+
# userinfo isn't a problem, but some drivers will fail handshake on a connection if userinfo is
17+
# provided but incorrect.
18+
ping: false
19+
comment: Encoded user, pass, and DB parse correctly

testdata/initial-dns-seedlist-discovery/replica-set/loadBalanced-false-txt.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@
1111
"options": {
1212
"loadBalanced": false,
1313
"ssl": true
14-
}
14+
},
15+
"ping": true
1516
}

testdata/initial-dns-seedlist-discovery/replica-set/loadBalanced-false-txt.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ hosts:
88
options:
99
loadBalanced: false
1010
ssl: true
11+
ping: true

testdata/initial-dns-seedlist-discovery/replica-set/longer-parent-in-return.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
"replicaSet": "repl0",
1313
"ssl": true
1414
},
15+
"ping": true,
1516
"comment": "Is correct, as returned host name shared the URI root \"test.build.10gen.cc\"."
1617
}

testdata/initial-dns-seedlist-discovery/replica-set/longer-parent-in-return.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ hosts:
88
options:
99
replicaSet: repl0
1010
ssl: true
11+
ping: true
1112
comment: Is correct, as returned host name shared the URI root "test.build.10gen.cc".

testdata/initial-dns-seedlist-discovery/replica-set/one-result-default-port.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@
1111
"options": {
1212
"replicaSet": "repl0",
1313
"ssl": true
14-
}
14+
},
15+
"ping": true
1516
}

testdata/initial-dns-seedlist-discovery/replica-set/one-result-default-port.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ hosts:
88
options:
99
replicaSet: repl0
1010
ssl: true
11+
ping: true

testdata/initial-dns-seedlist-discovery/replica-set/one-txt-record-multiple-strings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@
1111
"options": {
1212
"replicaSet": "repl0",
1313
"ssl": true
14-
}
14+
},
15+
"ping": true
1516
}

testdata/initial-dns-seedlist-discovery/replica-set/one-txt-record-multiple-strings.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ hosts:
88
options:
99
replicaSet: repl0
1010
ssl: true
11+
ping: true

testdata/initial-dns-seedlist-discovery/replica-set/one-txt-record.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
"replicaSet": "repl0",
1313
"authSource": "thisDB",
1414
"ssl": true
15-
}
15+
},
16+
"ping": true
1617
}

testdata/initial-dns-seedlist-discovery/replica-set/one-txt-record.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ options:
99
replicaSet: repl0
1010
authSource: thisDB
1111
ssl: true
12+
ping: true

testdata/initial-dns-seedlist-discovery/replica-set/srv-service-name.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
"options": {
1313
"ssl": true,
1414
"srvServiceName": "customname"
15-
}
15+
},
16+
"ping": true
1617
}

testdata/initial-dns-seedlist-discovery/replica-set/srv-service-name.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ hosts:
99
options:
1010
ssl: true
1111
srvServiceName: "customname"
12+
ping: true

testdata/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-equal_to_srv_records.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@
1313
"options": {
1414
"srvMaxHosts": 2,
1515
"ssl": true
16-
}
16+
},
17+
"ping": true
1718
}

testdata/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-equal_to_srv_records.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ hosts:
1414
options:
1515
srvMaxHosts: 2
1616
ssl: true
17+
ping: true

testdata/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-greater_than_srv_records.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
"options": {
1313
"srvMaxHosts": 3,
1414
"ssl": true
15-
}
15+
},
16+
"ping": true
1617
}

testdata/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-greater_than_srv_records.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ hosts:
1313
options:
1414
srvMaxHosts: 3
1515
ssl: true
16+
ping: true

testdata/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-less_than_srv_records.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
"options": {
1010
"srvMaxHosts": 1,
1111
"ssl": true
12-
}
12+
},
13+
"ping": true
1314
}

testdata/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-less_than_srv_records.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ hosts:
1313
options:
1414
srvMaxHosts: 1
1515
ssl: true
16+
ping: true

testdata/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-zero-txt.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@
1313
"replicaSet": "repl0",
1414
"srvMaxHosts": 0,
1515
"ssl": true
16-
}
16+
},
17+
"ping": true
1718
}

0 commit comments

Comments
 (0)