Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/1.11 #1146

Merged
merged 4 commits into from Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .evergreen/config.yml
Expand Up @@ -1045,6 +1045,7 @@ tasks:
- name: sa-fmt
tags: ["static-analysis"]
commands:
- func: install-linters
- func: run-make
vars:
targets: check-fmt
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Expand Up @@ -47,7 +47,7 @@ build-tests:

.PHONY: check-fmt
check-fmt:
etc/check_fmt.sh $(PKGS)
etc/check_fmt.sh

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

.PHONY: fmt
fmt:
gofmt -l -s -w $(PKGS)
go fmt ./...

.PHONY: lint
lint:
Expand Down
10 changes: 5 additions & 5 deletions etc/check_fmt.sh
@@ -1,11 +1,11 @@
#!/usr/bin/env bash
# check_fmt gopackages...
# Runs gofmt on given packages and checks that *_example_test.go files have wrapped lines.
# check_fmt
# Runs go fmt on all packages in the repo and checks that *_example_test.go files have wrapped lines.

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

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

if [[ $lll_out ]]; then
echo "lll check failed for:";
Expand Down
5 changes: 3 additions & 2 deletions mongo/crud_examples_test.go
Expand Up @@ -749,8 +749,9 @@ func ExampleClient_StartSession_withTransaction() {
result, err := sess.WithTransaction(
context.TODO(),
func(sessCtx mongo.SessionContext) (interface{}, error) {
// Use sessCtx as the Context parameter for InsertOne and FindOne so
// both operations are run in a transaction.
// Use the mongo.SessionContext as the Context parameter for
// InsertOne and FindOne so both operations are run in the same
// transaction.

coll := client.Database("db").Collection("coll")
res, err := coll.InsertOne(sessCtx, bson.D{{"x", 1}})
Expand Down
40 changes: 40 additions & 0 deletions mongo/integration/initial_dns_seedlist_discovery_test.go
Expand Up @@ -15,12 +15,15 @@ import (
"runtime"
"strings"
"testing"
"time"

"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/internal/testutil/assert"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/description"
"go.mongodb.org/mongo-driver/mongo/integration/mtest"
"go.mongodb.org/mongo-driver/mongo/options"
"go.mongodb.org/mongo-driver/mongo/readpref"
"go.mongodb.org/mongo-driver/x/mongo/driver/connstring"
"go.mongodb.org/mongo-driver/x/mongo/driver/topology"
)
Expand All @@ -37,19 +40,26 @@ type seedlistTest struct {
NumHosts *int `bson:"numHosts"`
Error bool `bson:"error"`
Options bson.Raw `bson:"options"`
Ping *bool `bson:"ping"`
}

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

mt.RunOpts("replica set", mtest.NewOptions().Topologies(mtest.ReplicaSet).CreateClient(false), func(mt *mtest.T) {
mt.Parallel()

runSeedlistDiscoveryDirectory(mt, "replica-set")
})
mt.RunOpts("sharded", mtest.NewOptions().Topologies(mtest.Sharded).CreateClient(false), func(mt *mtest.T) {
mt.Parallel()

runSeedlistDiscoveryDirectory(mt, "sharded")
})
mt.RunOpts("load balanced", mtest.NewOptions().Topologies(mtest.LoadBalanced).CreateClient(false), func(mt *mtest.T) {
mt.Parallel()

runSeedlistDiscoveryDirectory(mt, "load-balanced")
})
}
Expand All @@ -63,6 +73,24 @@ func runSeedlistDiscoveryDirectory(mt *mtest.T, subdirectory string) {
}
}

// runSeedlistDiscoveryPingTest will create a new connection using the test URI and attempt to "ping" the server.
func runSeedlistDiscoveryPingTest(mt *mtest.T, clientOpts *options.ClientOptions) {
ctx := context.Background()

client, err := mongo.Connect(ctx, clientOpts)
assert.Nil(mt, err, "Connect error: %v", err)

defer func() { _ = client.Disconnect(ctx) }()

// Create a context with a timeout to prevent the ping operation from blocking indefinitely.
pingCtx, cancel := context.WithTimeout(ctx, 1*time.Second)
defer cancel()

// Ping the server.
err = client.Ping(pingCtx, readpref.Nearest())
assert.Nil(mt, err, "Ping error: %v", err)
}

func runSeedlistDiscoveryTest(mt *mtest.T, file string) {
content, err := ioutil.ReadFile(file)
assert.Nil(mt, err, "ReadFile error for %v: %v", file, err)
Expand Down Expand Up @@ -131,6 +159,10 @@ func runSeedlistDiscoveryTest(mt *mtest.T, file string) {
_, err := getServerByAddress(host, topo)
assert.Nil(mt, err, "error finding host %q: %v", host, err)
}

if ping := test.Ping; ping == nil || *ping {
runSeedlistDiscoveryPingTest(mt, opts)
}
}

func buildSet(list []string) map[string]struct{} {
Expand Down Expand Up @@ -230,6 +262,14 @@ func getServerByAddress(address string, topo *topology.Topology) (description.Se
if err != nil {
return description.Server{}, err
}

// If the selected server is a topology.SelectedServer, then we can get the description without creating a
// connect pool.
topologySelectedServer, ok := selectedServer.(*topology.SelectedServer)
if ok {
return topologySelectedServer.Description().Server, nil
}

selectedServerConnection, err := selectedServer.Connection(context.Background())
if err != nil {
return description.Server{}, err
Expand Down
2 changes: 1 addition & 1 deletion mongo/integration/retryable_writes_prose_test.go
Expand Up @@ -282,7 +282,7 @@ func TestRetryableWritesProse(t *testing.T) {

require.True(mt, secondFailPointConfigured)

// Assert that the "NotWritablePrimary" error is returned.
// Assert that the "ShutdownInProgress" error is returned.
require.True(mt, err.(mongo.WriteException).HasErrorCode(int(shutdownInProgressErrorCode)))
})
}
Expand Up @@ -10,5 +10,6 @@
"loadBalanced": true,
"ssl": true,
"directConnection": false
}
},
"ping": true
}
Expand Up @@ -11,3 +11,4 @@ options:
loadBalanced: true
ssl: true
directConnection: false
ping: true
Expand Up @@ -9,5 +9,6 @@
"options": {
"loadBalanced": true,
"ssl": true
}
},
"ping": true
}
Expand Up @@ -8,3 +8,4 @@ hosts:
options:
loadBalanced: true
ssl: true
ping: true
Expand Up @@ -10,5 +10,6 @@
"loadBalanced": true,
"srvMaxHosts": 0,
"ssl": true
}
},
"ping": true
}
Expand Up @@ -8,3 +8,4 @@ options:
loadBalanced: true
srvMaxHosts: 0
ssl: true
ping: true
Expand Up @@ -10,5 +10,6 @@
"loadBalanced": true,
"srvMaxHosts": 0,
"ssl": true
}
},
"ping": true
}
Expand Up @@ -8,3 +8,4 @@ options:
loadBalanced: true
srvMaxHosts: 0
ssl: true
ping: true
Expand Up @@ -11,5 +11,6 @@
"options": {
"ssl": true,
"directConnection": false
}
},
"ping": true
}
Expand Up @@ -8,3 +8,4 @@ hosts:
options:
ssl: true
directConnection: false
ping: true
@@ -0,0 +1,22 @@
{
"uri": "mongodb+srv://b*b%40f3tt%3D:%244to%40L8%3DMC@test3.test.build.10gen.cc/mydb%3F?replicaSet=repl0",
"seeds": [
"localhost.test.build.10gen.cc:27017"
],
"hosts": [
"localhost:27017",
"localhost:27018",
"localhost:27019"
],
"options": {
"replicaSet": "repl0",
"ssl": true
},
"parsed_options": {
"user": "b*b@f3tt=",
"password": "$4to@L8=MC",
"db": "mydb?"
},
"ping": false,
"comment": "Encoded user, pass, and DB parse correctly"
}
@@ -0,0 +1,19 @@
uri: "mongodb+srv://b*b%40f3tt%3D:%244to%40L8%3DMC@test3.test.build.10gen.cc/mydb%3F?replicaSet=repl0"
seeds:
- localhost.test.build.10gen.cc:27017
hosts:
- localhost:27017
- localhost:27018
- localhost:27019
options:
replicaSet: repl0
ssl: true
parsed_options:
user: "b*b@f3tt="
password: "$4to@L8=MC"
db: "mydb?"
# Don't run a ping for URIs that include userinfo. Ping doesn't require authentication, so missing
# userinfo isn't a problem, but some drivers will fail handshake on a connection if userinfo is
# provided but incorrect.
ping: false
comment: Encoded user, pass, and DB parse correctly
Expand Up @@ -11,5 +11,6 @@
"options": {
"loadBalanced": false,
"ssl": true
}
},
"ping": true
}
Expand Up @@ -8,3 +8,4 @@ hosts:
options:
loadBalanced: false
ssl: true
ping: true
Expand Up @@ -12,5 +12,6 @@
"replicaSet": "repl0",
"ssl": true
},
"ping": true,
"comment": "Is correct, as returned host name shared the URI root \"test.build.10gen.cc\"."
}
Expand Up @@ -8,4 +8,5 @@ hosts:
options:
replicaSet: repl0
ssl: true
ping: true
comment: Is correct, as returned host name shared the URI root "test.build.10gen.cc".
Expand Up @@ -11,5 +11,6 @@
"options": {
"replicaSet": "repl0",
"ssl": true
}
},
"ping": true
}
Expand Up @@ -8,3 +8,4 @@ hosts:
options:
replicaSet: repl0
ssl: true
ping: true
Expand Up @@ -11,5 +11,6 @@
"options": {
"replicaSet": "repl0",
"ssl": true
}
},
"ping": true
}
Expand Up @@ -8,3 +8,4 @@ hosts:
options:
replicaSet: repl0
ssl: true
ping: true
Expand Up @@ -12,5 +12,6 @@
"replicaSet": "repl0",
"authSource": "thisDB",
"ssl": true
}
},
"ping": true
}
Expand Up @@ -9,3 +9,4 @@ options:
replicaSet: repl0
authSource: thisDB
ssl: true
ping: true
Expand Up @@ -12,5 +12,6 @@
"options": {
"ssl": true,
"srvServiceName": "customname"
}
},
"ping": true
}
Expand Up @@ -9,3 +9,4 @@ hosts:
options:
ssl: true
srvServiceName: "customname"
ping: true
Expand Up @@ -13,5 +13,6 @@
"options": {
"srvMaxHosts": 2,
"ssl": true
}
},
"ping": true
}
Expand Up @@ -14,3 +14,4 @@ hosts:
options:
srvMaxHosts: 2
ssl: true
ping: true
Expand Up @@ -12,5 +12,6 @@
"options": {
"srvMaxHosts": 3,
"ssl": true
}
},
"ping": true
}
Expand Up @@ -13,3 +13,4 @@ hosts:
options:
srvMaxHosts: 3
ssl: true
ping: true
Expand Up @@ -9,5 +9,6 @@
"options": {
"srvMaxHosts": 1,
"ssl": true
}
},
"ping": true
}
Expand Up @@ -13,3 +13,4 @@ hosts:
options:
srvMaxHosts: 1
ssl: true
ping: true
Expand Up @@ -13,5 +13,6 @@
"replicaSet": "repl0",
"srvMaxHosts": 0,
"ssl": true
}
},
"ping": true
}