Skip to content

Commit 34cbc49

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

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

mongo/integration/server_selection_prose_test.go

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,12 @@ 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+
SetAppName("loadBalancingTest"))
6868

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.
69+
// Start 25 goroutines that each run 10 findOne operations. Run more operations than the
70+
// prose test specifies to get more samples and reduce intermittent test failures.
7271
var wg sync.WaitGroup
7372
for i := 0; i < 25; i++ {
7473
wg.Add(1)
@@ -98,7 +97,11 @@ func TestServerSelectionProse(t *testing.T) {
9897
// Calculate the frequency that the server with the failpoint was selected. Assert that it
9998
// was selected less than 25% of the time.
10099
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)
100+
assert.Lessf(mt,
101+
frequency,
102+
0.25,
103+
"expected failpoint host %q to be selected less than 25%% of the time",
104+
failpointHost)
102105
})
103106

104107
mtOpts = mtest.NewOptions().Topologies(mtest.Sharded)
@@ -113,23 +116,24 @@ func TestServerSelectionProse(t *testing.T) {
113116
tpm := newTestPoolMonitor()
114117
mt.ResetClient(options.Client().
115118
SetHosts(hosts[:2]).
116-
SetPoolMonitor(tpm.PoolMonitor))
119+
SetPoolMonitor(tpm.PoolMonitor).
120+
SetHeartbeatInterval(500 * time.Millisecond))
117121

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+
// Sleep for 1s to allow server state discovery and at least 1 heartbeat to complete. We
123+
// need both servers to be selectable when we start running the test or the distribution of
124+
// selected servers will be skewed. Unfortunately there's not currently another signal we
125+
// can wait on.
126+
time.Sleep(1 * time.Second)
122127

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.
128+
// Start 25 goroutines that each run 200 findOne operations. Run more operations than the
129+
// prose test specifies to get more samples and reduce intermittent test failures.
126130
var wg sync.WaitGroup
127131
for i := 0; i < 25; i++ {
128132
wg.Add(1)
129133
go func() {
130134
defer wg.Done()
131135

132-
for i := 0; i < 10; i++ {
136+
for i := 0; i < 200; i++ {
133137
res := mt.Coll.FindOne(context.Background(), bson.D{})
134138
assert.NoError(mt, res.Err(), "FindOne() error")
135139
}

0 commit comments

Comments
 (0)