@@ -130,54 +130,28 @@ def changed_event(event):
130
130
self .assertEqual (1 , len (events ))
131
131
self .assertGreater (events [0 ].new_description .round_trip_time , 0 )
132
132
133
+ @client_context .require_version_min (4 , 9 , - 1 )
133
134
@client_context .require_failCommand_appName
134
135
def test_monitor_waits_after_server_check_error (self ):
135
- hb_listener = HeartbeatEventListener ()
136
- client = rs_or_single_client (
137
- event_listeners = [hb_listener ], heartbeatFrequencyMS = 500 ,
138
- appName = 'waitAfterErrorTest' )
139
- self .addCleanup (client .close )
140
- # Force a connection.
141
- client .admin .command ('ping' )
142
- address = client .address
143
-
144
136
fail_ismaster = {
145
- 'mode' : {'times' : 50 },
137
+ 'mode' : {'times' : 5 },
146
138
'data' : {
147
139
'failCommands' : ['isMaster' ],
148
- 'closeConnection' : False ,
149
- 'errorCode' : 91 ,
150
- # This can be uncommented after SERVER-49220 is fixed.
151
- # 'appName': 'waitAfterErrorTest',
140
+ 'errorCode' : 1234 ,
141
+ 'appName' : 'SDAMMinHeartbeatFrequencyTest' ,
152
142
},
153
143
}
154
144
with self .fail_point (fail_ismaster ):
155
- time .sleep (2 )
156
-
157
- # Server should be selectable.
158
- client .admin .command ('ping' )
159
-
160
- def hb_started (event ):
161
- return (isinstance (event , monitoring .ServerHeartbeatStartedEvent )
162
- and event .connection_id == address )
163
-
164
- hb_started_events = hb_listener .matching (hb_started )
165
- # Explanation of the expected heartbeat events:
166
- # Time: event
167
- # 0ms: create MongoClient
168
- # 1ms: run monitor handshake, 1
169
- # 2ms: run awaitable isMaster, 2
170
- # 3ms: run configureFailPoint
171
- # 502ms: isMaster fails for the first time with command error
172
- # 1002ms: run monitor handshake, 3
173
- # 1502ms: run monitor handshake, 4
174
- # 2002ms: run monitor handshake, 5
175
- # 2003ms: disable configureFailPoint
176
- # 2004ms: isMaster succeeds, 6
177
- # 2004ms: awaitable isMaster, 7
178
- self .assertGreater (len (hb_started_events ), 7 )
179
- # This can be reduced to ~15 after SERVER-49220 is fixed.
180
- self .assertLess (len (hb_started_events ), 40 )
145
+ start = time .time ()
146
+ client = single_client (
147
+ appName = 'SDAMMinHeartbeatFrequencyTest' ,
148
+ serverSelectionTimeoutMS = 5000 )
149
+ self .addCleanup (client .close )
150
+ # Force a connection.
151
+ client .admin .command ('ping' )
152
+ duration = time .time () - start
153
+ self .assertGreaterEqual (duration , 2 )
154
+ self .assertLessEqual (duration , 3.5 )
181
155
182
156
@client_context .require_failCommand_appName
183
157
def test_heartbeat_awaited_flag (self ):
0 commit comments