MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / test_explain_csot

Method test_explain_csot

test/test_cursor.py:374–394  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

372
373 # https://github.com/mongodb/specifications/blob/master/source/crud/tests/README.md#14-explain-helpers-allow-users-to-specify-maxtimems
374 def test_explain_csot(self):
375 # Create a MongoClient with command monitoring enabled (referred to as client).
376 listener = AllowListEventListener("explain")
377 client = self.rs_or_single_client(event_listeners=[listener])
378
379 # Create a collection, referred to as collection, with the namespace explain-test.collection.
380 # Workaround for SERVER-108463
381 names = client["explain-test"].list_collection_names()
382 if "collection" not in names:
383 collection = client["explain-test"].create_collection("collection")
384 else:
385 collection = client["explain-test"]["collection"]
386
387 # Run an explained find on collection. The find will have the query predicate { name: 'john doe' }. Specify a maxTimeMS value of 2000ms for the explain.
388 with pymongo.timeout(2.0):
389 self.assertTrue(collection.find({"name": "john doe"}).explain())
390
391 # Obtain the command started event for the explain. Confirm that the top-level explain command should has a maxTimeMS value of 2000.
392 started = listener.started_events
393 self.assertEqual(len(started), 1)
394 assert 1500 < started[0].command["maxTimeMS"] <= 2000
395
396 def test_hint(self):
397 db = self.db

Callers

nothing calls this directly

Calls 7

rs_or_single_clientMethod · 0.80
list_collection_namesMethod · 0.45
create_collectionMethod · 0.45
timeoutMethod · 0.45
explainMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected