Skip to content

Commit 634eb62

Browse files
author
Sam Kleinman
committed
GODRIVER-383: set server selection timeout in topology from connstring
Change-Id: I61ca1567ee8869756681940f432912306ac1eacd
1 parent 068e426 commit 634eb62

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

core/topology/topology_options.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ func WithConnString(fn func(connstring.ConnString) connstring.ConnString) Option
5050
return func(c *config) error {
5151
cs := fn(c.cs)
5252
c.cs = cs
53+
54+
if cs.ServerSelectionTimeoutSet {
55+
c.serverSelectionTimeout = cs.ServerSelectionTimeout
56+
}
57+
5358
var connOpts []connection.Option
5459

5560
if cs.AppName != "" {
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package topology
2+
3+
import (
4+
"testing"
5+
"time"
6+
7+
"github.com/mongodb/mongo-go-driver/core/connstring"
8+
"github.com/stretchr/testify/assert"
9+
)
10+
11+
func TestOptionsSetting(t *testing.T) {
12+
conf := &config{}
13+
ssts := time.Minute
14+
assert.Zero(t, conf.cs)
15+
16+
opt := WithConnString(func(connstring.ConnString) connstring.ConnString {
17+
return connstring.ConnString{
18+
ServerSelectionTimeout: ssts,
19+
ServerSelectionTimeoutSet: true,
20+
}
21+
22+
})
23+
24+
assert.NoError(t, opt(conf))
25+
26+
assert.Equal(t, ssts, conf.serverSelectionTimeout)
27+
}

0 commit comments

Comments
 (0)