@@ -130,54 +130,42 @@ 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
-
136
+ # This test implements:
137
+ # https://github.com/mongodb/specifications/blob/6c5b2ac/source/server-discovery-and-monitoring/server-discovery-and-monitoring-tests.rst#monitors-sleep-at-least-minheartbeatfreqencyms-between-checks
144
138
fail_ismaster = {
145
- 'mode' : {'times' : 50 },
139
+ 'mode' : {'times' : 5 },
146
140
'data' : {
147
141
'failCommands' : ['isMaster' ],
148
- 'closeConnection' : False ,
149
- 'errorCode' : 91 ,
150
- # This can be uncommented after SERVER-49220 is fixed.
151
- # 'appName': 'waitAfterErrorTest',
142
+ 'errorCode' : 1234 ,
143
+ 'appName' : 'SDAMMinHeartbeatFrequencyTest' ,
152
144
},
153
145
}
154
146
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 )
147
+ start = time .time ()
148
+ client = single_client (
149
+ appName = 'SDAMMinHeartbeatFrequencyTest' ,
150
+ serverSelectionTimeoutMS = 5000 )
151
+ self .addCleanup (client .close )
152
+ # Force a connection.
153
+ client .admin .command ('ping' )
154
+ duration = time .time () - start
155
+ # Explanation of the expected events:
156
+ # 0ms: run configureFailPoint
157
+ # 1ms: create MongoClient
158
+ # 2ms: failed monitor handshake, 1
159
+ # 502ms: failed monitor handshake, 2
160
+ # 1002ms: failed monitor handshake, 3
161
+ # 1502ms: failed monitor handshake, 4
162
+ # 2002ms: failed monitor handshake, 5
163
+ # 2502ms: monitor handshake succeeds
164
+ # 2503ms: run awaitable isMaster
165
+ # 2504ms: application handshake succeeds
166
+ # 2505ms: ping command succeeds
167
+ self .assertGreaterEqual (duration , 2 )
168
+ self .assertLessEqual (duration , 3.5 )
181
169
182
170
@client_context .require_failCommand_appName
183
171
def test_heartbeat_awaited_flag (self ):
0 commit comments