Skip to content

Commit 70d5060

Browse files
author
Divjot Arora
committed
Pin to a single host in GridFS tests (#500)
1 parent 3cc2bf3 commit 70d5060

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

mongo/gridfs/gridfs_test.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,16 @@ func TestGridFS(t *testing.T) {
3535
}
3636
},
3737
}
38-
clientOpts := options.Client().ApplyURI(cs.Original).SetReadPreference(readpref.Primary()).
39-
SetWriteConcern(writeconcern.New(writeconcern.WMajority())).SetPoolMonitor(poolMonitor)
38+
clientOpts := options.Client().
39+
ApplyURI(cs.Original).
40+
SetReadPreference(readpref.Primary()).
41+
SetWriteConcern(writeconcern.New(writeconcern.WMajority())).
42+
SetPoolMonitor(poolMonitor).
43+
// Connect to a single host. For sharded clusters, this will pin to a single mongos, which avoids
44+
// non-deterministic versioning errors in the server. This has no effect for replica sets because the driver
45+
// will discover the other hosts during SDAM checks.
46+
SetHosts(cs.Hosts[:1])
47+
4048
client, err := mongo.Connect(context.Background(), clientOpts)
4149
assert.Nil(t, err, "Connect error: %v", err)
4250
db := client.Database("gridfs")

0 commit comments

Comments
 (0)