Skip to content

Commit cb7150a

Browse files
GODRIVER-2573 re-apply default serverSelectionTimeout (#1089)
1 parent b088660 commit cb7150a

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

x/mongo/driver/topology/topology_options.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import (
2121
"go.mongodb.org/mongo-driver/x/mongo/driver/session"
2222
)
2323

24+
const defaultServerSelectionTimeout = 30 * time.Second
25+
2426
// Config is used to construct a topology.
2527
type Config struct {
2628
Mode MonitorMode
@@ -61,6 +63,12 @@ func NewConfig(co *options.ClientOptions, clock *session.ClusterClock) (*Config,
6163

6264
cfgp := new(Config)
6365

66+
// Set the default "ServerSelectionTimeout" to 30 seconds.
67+
cfgp.ServerSelectionTimeout = defaultServerSelectionTimeout
68+
69+
// Set the default "SeedList" to localhost.
70+
cfgp.SeedList = []string{"localhost:27017"}
71+
6472
// TODO(GODRIVER-814): Add tests for topology, server, and connection related options.
6573

6674
// ServerAPIOptions need to be handled early as other client and server options below reference

x/mongo/driver/topology/topology_options_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"fmt"
1111
"net/url"
1212
"testing"
13+
"time"
1314

1415
"github.com/stretchr/testify/assert"
1516
"go.mongodb.org/mongo-driver/mongo/options"
@@ -80,3 +81,26 @@ func TestLoadBalancedFromConnString(t *testing.T) {
8081
})
8182
}
8283
}
84+
85+
func TestTopologyNewConfig(t *testing.T) {
86+
t.Run("default ServerSelectionTimeout", func(t *testing.T) {
87+
cfg, err := NewConfig(options.Client(), nil)
88+
assert.Nil(t, err, "error constructing topology config: %v", err)
89+
assert.Equal(t, defaultServerSelectionTimeout, cfg.ServerSelectionTimeout)
90+
})
91+
t.Run("non-default ServerSelectionTimeout", func(t *testing.T) {
92+
cfg, err := NewConfig(options.Client().SetServerSelectionTimeout(1), nil)
93+
assert.Nil(t, err, "error constructing topology config: %v", err)
94+
assert.Equal(t, time.Duration(1), cfg.ServerSelectionTimeout)
95+
})
96+
t.Run("default SeedList", func(t *testing.T) {
97+
cfg, err := NewConfig(options.Client(), nil)
98+
assert.Nil(t, err, "error constructing topology config: %v", err)
99+
assert.Equal(t, []string{"localhost:27017"}, cfg.SeedList)
100+
})
101+
t.Run("non-default SeedList", func(t *testing.T) {
102+
cfg, err := NewConfig(options.Client().ApplyURI("mongodb://localhost:27018"), nil)
103+
assert.Nil(t, err, "error constructing topology config: %v", err)
104+
assert.Equal(t, []string{"localhost:27018"}, cfg.SeedList)
105+
})
106+
}

0 commit comments

Comments
 (0)