@@ -62,20 +62,20 @@ 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
+ SetHeartbeatInterval (500 * time .Millisecond ).
68
+ SetAppName ("loadBalancingTest" ))
68
69
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.
72
72
var wg sync.WaitGroup
73
73
for i := 0 ; i < 25 ; i ++ {
74
74
wg .Add (1 )
75
75
go func () {
76
76
defer wg .Done ()
77
77
78
- for i := 0 ; i < 10 ; i ++ {
78
+ for i := 0 ; i < 25 ; i ++ {
79
79
res := mt .Coll .FindOne (context .Background (), bson.D {})
80
80
assert .NoError (t , res .Err (), "FindOne() error" )
81
81
}
@@ -98,7 +98,11 @@ func TestServerSelectionProse(t *testing.T) {
98
98
// Calculate the frequency that the server with the failpoint was selected. Assert that it
99
99
// was selected less than 25% of the time.
100
100
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 )
102
106
})
103
107
104
108
mtOpts = mtest .NewOptions ().Topologies (mtest .Sharded )
@@ -113,23 +117,25 @@ func TestServerSelectionProse(t *testing.T) {
113
117
tpm := newTestPoolMonitor ()
114
118
mt .ResetClient (options .Client ().
115
119
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.
126
132
var wg sync.WaitGroup
127
133
for i := 0 ; i < 25 ; i ++ {
128
134
wg .Add (1 )
129
135
go func () {
130
136
defer wg .Done ()
131
137
132
- for i := 0 ; i < 10 ; i ++ {
138
+ for i := 0 ; i < 25 ; i ++ {
133
139
res := mt .Coll .FindOne (context .Background (), bson.D {})
134
140
assert .NoError (mt , res .Err (), "FindOne() error" )
135
141
}
0 commit comments