Skip to content

Commit 9904e77

Browse files
committed
Increase server selection prose test iteration to increase reliability.
1 parent e20a58c commit 9904e77

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

mongo/integration/server_selection_prose_test.go

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,20 @@ func TestServerSelectionProse(t *testing.T) {
6262
// Reset the client with exactly 2 mongos hosts.
6363
tpm := newTestPoolMonitor()
6464
mt.ResetClient(options.Client().
65-
SetAppName("loadBalancingTest").
6665
SetHosts(hosts[:2]).
67-
SetPoolMonitor(tpm.PoolMonitor))
66+
SetPoolMonitor(tpm.PoolMonitor).
67+
SetHeartbeatInterval(500 * time.Millisecond).
68+
SetAppName("loadBalancingTest"))
6869

69-
// Start 25 goroutines that each run 10 findOne operations. Run 25 goroutines instead of the
70-
// 10 that the prose test specifies to reduce intermittent test failures caused by the
71-
// random selections not being perfectly even over small numbers of operations.
70+
// Start 25 goroutines that each run 10 findOne operations. Run more operations than the
71+
// prose test specifies to reduce intermittent test failures.
7272
var wg sync.WaitGroup
7373
for i := 0; i < 25; i++ {
7474
wg.Add(1)
7575
go func() {
7676
defer wg.Done()
7777

78-
for i := 0; i < 10; i++ {
78+
for i := 0; i < 25; i++ {
7979
res := mt.Coll.FindOne(context.Background(), bson.D{})
8080
assert.NoError(t, res.Err(), "FindOne() error")
8181
}
@@ -98,7 +98,11 @@ func TestServerSelectionProse(t *testing.T) {
9898
// Calculate the frequency that the server with the failpoint was selected. Assert that it
9999
// was selected less than 25% of the time.
100100
frequency := float64(counts[failpointHost]) / float64(len(checkOutEvents))
101-
assert.Lessf(mt, frequency, 0.25, "expected failpoint host %q to be selected less than 25%% of the time", failpointHost)
101+
assert.Lessf(mt,
102+
frequency,
103+
0.25,
104+
"expected failpoint host %q to be selected less than 25%% of the time",
105+
failpointHost)
102106
})
103107

104108
mtOpts = mtest.NewOptions().Topologies(mtest.Sharded)
@@ -113,23 +117,25 @@ func TestServerSelectionProse(t *testing.T) {
113117
tpm := newTestPoolMonitor()
114118
mt.ResetClient(options.Client().
115119
SetHosts(hosts[:2]).
116-
SetPoolMonitor(tpm.PoolMonitor))
117-
118-
// Sleep for 100ms to allow all server state discovery to complete. We need both servers to
119-
// be selectable when we start running the test or the distribution of selected servers will
120-
// be skewed. Unfortunately there's not currently another signal we can block on.
121-
time.Sleep(100 * time.Millisecond)
122-
123-
// Start 25 goroutines that each run 10 findOne operations. Run 25 goroutines instead of the
124-
// 10 that the prose test specifies to reduce intermittent test failures caused by the
125-
// random selections not being perfectly even over small numbers of operations.
120+
SetPoolMonitor(tpm.PoolMonitor).
121+
SetHeartbeatInterval(500 * time.Millisecond))
122+
123+
// Sleep for 1s to allow server state discovery and at least 1 heartbeat to complete. We
124+
// need both servers to be selectable when we start running the test or the distribution of
125+
// selected servers will be skewed. Unfortunately there's not currently another signal we
126+
// can wait on.
127+
time.Sleep(1 * time.Second)
128+
129+
// Start 25 goroutines that each run 25 findOne operations. Run more goroutines and
130+
// operations than the prose test specifies to reduce intermittent test failures caused by
131+
// the random selections not being perfectly even over small numbers of operations.
126132
var wg sync.WaitGroup
127133
for i := 0; i < 25; i++ {
128134
wg.Add(1)
129135
go func() {
130136
defer wg.Done()
131137

132-
for i := 0; i < 10; i++ {
138+
for i := 0; i < 25; i++ {
133139
res := mt.Coll.FindOne(context.Background(), bson.D{})
134140
assert.NoError(mt, res.Err(), "FindOne() error")
135141
}

0 commit comments

Comments
 (0)