MCPcopy Create free account
hub / github.com/mongodb/mongo-python-driver / _run_scenario

Function _run_scenario

test/asynchronous/test_sdam_monitoring_spec.py:191–251  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

189 await _run_scenario(self)
190
191 async def _run_scenario(self):
192 class NoopMonitor(Monitor):
193 """Override the _run method to do nothing."""
194
195 async def _run(self):
196 await asyncio.sleep(0.05)
197
198 m = AsyncMongoClient(
199 host=scenario_def["uri"],
200 port=27017,
201 event_listeners=[self.all_listener],
202 _monitor_class=NoopMonitor,
203 )
204 topology = await m._get_topology()
205
206 try:
207 for phase in scenario_def["phases"]:
208 for source, response in phase.get("responses", []):
209 source_address = clean_node(source)
210 await topology.on_change(
211 ServerDescription(
212 address=source_address, hello=Hello(response), round_trip_time=0
213 )
214 )
215
216 expected_results = phase["outcome"]["events"]
217 expected_len = len(expected_results)
218 await async_wait_until(
219 lambda: len(self.all_listener.results) >= expected_len,
220 "publish all events",
221 timeout=15,
222 )
223
224 # Wait some time to catch possible lagging extra events.
225 await async_wait_until(lambda: topology._events.empty(), "publish lagging events")
226
227 i = 0
228 while i < expected_len:
229 result = (
230 self.all_listener.results[i] if len(self.all_listener.results) > i else None
231 )
232 # The order of ServerOpening/ClosedEvents doesn't matter
233 if isinstance(
234 result, (monitoring.ServerOpeningEvent, monitoring.ServerClosedEvent)
235 ):
236 i, passed, message = compare_multiple_events(
237 i, expected_results, self.all_listener.results
238 )
239 self.assertTrue(passed, message)
240 else:
241 self.assertTrue(*compare_events(expected_results[i], result))
242 i += 1
243
244 # Assert no extra events.
245 extra_events = self.all_listener.results[expected_len:]
246 if extra_events:
247 self.fail(f"Extra events {extra_events!r}")
248

Callers 1

run_scenarioFunction · 0.70

Calls 12

_get_topologyMethod · 0.95
closeMethod · 0.95
AsyncMongoClientClass · 0.90
clean_nodeFunction · 0.90
ServerDescriptionClass · 0.90
HelloClass · 0.90
async_wait_untilFunction · 0.85
compare_multiple_eventsFunction · 0.70
compare_eventsFunction · 0.70
getMethod · 0.45
on_changeMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected