Skip to content

Commit f0e3e22

Browse files
committed
add test
1 parent 0b35dff commit f0e3e22

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

test/asynchronous/test_cursor.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,24 @@ async def test_explain_with_read_concern(self):
362362
self.assertEqual(len(started), 1)
363363
self.assertNotIn("readConcern", started[0].command)
364364

365+
# https://github.com/mongodb/specifications/blob/master/source/crud/tests/README.md#14-explain-helpers-allow-users-to-specify-maxtimems
366+
async def test_explain_csot(self):
367+
# Create a MongoClient with command monitoring enabled (referred to as client).
368+
listener = AllowListEventListener("explain")
369+
client = await self.rs_or_single_client(event_listeners=[listener])
370+
371+
# Create a collection, referred to as collection, with the namespace explain-test.collection.
372+
collection = client["explain-test"]["collection"]
373+
374+
# 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.
375+
with pymongo.timeout(2.0):
376+
self.assertTrue(await collection.find({"name": "john doe"}).explain())
377+
378+
# Obtain the command started event for the explain. Confirm that the top-level explain command should has a maxTimeMS value of 2000.
379+
started = listener.started_events
380+
self.assertEqual(len(started), 1)
381+
assert 1990 < started[0].command["maxTimeMS"] <= 2000
382+
365383
async def test_hint(self):
366384
db = self.db
367385
with self.assertRaises(TypeError):

test/test_cursor.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,24 @@ def test_explain_with_read_concern(self):
354354
self.assertEqual(len(started), 1)
355355
self.assertNotIn("readConcern", started[0].command)
356356

357+
# https://github.com/mongodb/specifications/blob/master/source/crud/tests/README.md#14-explain-helpers-allow-users-to-specify-maxtimems
358+
def test_explain_csot(self):
359+
# Create a MongoClient with command monitoring enabled (referred to as client).
360+
listener = AllowListEventListener("explain")
361+
client = self.rs_or_single_client(event_listeners=[listener])
362+
363+
# Create a collection, referred to as collection, with the namespace explain-test.collection.
364+
collection = client["explain-test"]["collection"]
365+
366+
# 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.
367+
with pymongo.timeout(2.0):
368+
self.assertTrue(collection.find({"name": "john doe"}).explain())
369+
370+
# Obtain the command started event for the explain. Confirm that the top-level explain command should has a maxTimeMS value of 2000.
371+
started = listener.started_events
372+
self.assertEqual(len(started), 1)
373+
assert 1990 < started[0].command["maxTimeMS"] <= 2000
374+
357375
def test_hint(self):
358376
db = self.db
359377
with self.assertRaises(TypeError):

0 commit comments

Comments
 (0)