@@ -62,13 +62,12 @@ func TestServerSelectionProse(t *testing.T) {
62
62
// Reset the client with exactly 2 mongos hosts.
63
63
tpm := newTestPoolMonitor ()
64
64
mt .ResetClient (options .Client ().
65
- SetAppName ("loadBalancingTest" ).
66
65
SetHosts (hosts [:2 ]).
67
- SetPoolMonitor (tpm .PoolMonitor ))
66
+ SetPoolMonitor (tpm .PoolMonitor ).
67
+ SetAppName ("loadBalancingTest" ))
68
68
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.
72
71
var wg sync.WaitGroup
73
72
for i := 0 ; i < 25 ; i ++ {
74
73
wg .Add (1 )
@@ -98,7 +97,11 @@ func TestServerSelectionProse(t *testing.T) {
98
97
// Calculate the frequency that the server with the failpoint was selected. Assert that it
99
98
// was selected less than 25% of the time.
100
99
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 )
102
105
})
103
106
104
107
mtOpts = mtest .NewOptions ().Topologies (mtest .Sharded )
@@ -113,23 +116,24 @@ func TestServerSelectionProse(t *testing.T) {
113
116
tpm := newTestPoolMonitor ()
114
117
mt .ResetClient (options .Client ().
115
118
SetHosts (hosts [:2 ]).
116
- SetPoolMonitor (tpm .PoolMonitor ))
119
+ SetPoolMonitor (tpm .PoolMonitor ).
120
+ SetHeartbeatInterval (500 * time .Millisecond ))
117
121
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 )
122
127
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.
126
130
var wg sync.WaitGroup
127
131
for i := 0 ; i < 25 ; i ++ {
128
132
wg .Add (1 )
129
133
go func () {
130
134
defer wg .Done ()
131
135
132
- for i := 0 ; i < 10 ; i ++ {
136
+ for i := 0 ; i < 200 ; i ++ {
133
137
res := mt .Coll .FindOne (context .Background (), bson.D {})
134
138
assert .NoError (mt , res .Err (), "FindOne() error" )
135
139
}
0 commit comments