Skip to content

Commit e25bb90

Browse files
committed
Properly set default local threshold in Client
GODRIVER-1226 Change-Id: I7fcc5b09a49b80908d04f3c4fde75b6958748b5f
1 parent cd0e792 commit e25bb90

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

mongo/client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ func (c *Client) configure(opts *options.ClientOptions) error {
348348
func(...string) []string { return hosts },
349349
))
350350
// LocalThreshold
351+
c.localThreshold = defaultLocalThreshold
351352
if opts.LocalThreshold != nil {
352353
c.localThreshold = *opts.LocalThreshold
353354
}

mongo/client_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ func ExampleClient_Connect() {
3636

3737
func TestClient(t *testing.T) {
3838
t.Run("Can configure LocalThreshold", func(t *testing.T) {
39+
t.Run("Should have default LocalThreshold set", func(t *testing.T) {
40+
client := new(Client)
41+
err := client.configure(options.Client())
42+
noerr(t, err)
43+
want, got := defaultLocalThreshold, client.localThreshold
44+
if got != want {
45+
t.Errorf("Default LocalThreshold not set on client. got %v; want %v", got, want)
46+
}
47+
})
3948
opts := options.Client().SetLocalThreshold(10 * time.Second)
4049
client := new(Client)
4150
err := client.configure(opts)

x/mongo/driver/operation.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import (
2424
"go.mongodb.org/mongo-driver/x/mongo/driver/wiremessage"
2525
)
2626

27+
const defaultLocalThreshold = 15 * time.Millisecond
28+
2729
var dollarCmd = [...]byte{'.', '$', 'c', 'm', 'd'}
2830

2931
var (
@@ -192,7 +194,7 @@ func (op Operation) selectServer(ctx context.Context) (Server, error) {
192194
}
193195
selector = description.CompositeSelector([]description.ServerSelector{
194196
description.ReadPrefSelector(rp),
195-
description.LatencySelector(15 * time.Millisecond),
197+
description.LatencySelector(defaultLocalThreshold),
196198
})
197199
}
198200

0 commit comments

Comments
 (0)