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

Method test_max_await_time_ms

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

Source from the content-addressed store, hash-verified

214 self.assertIn("(configured timeouts: connectTimeoutMS: 20000.0ms", str(error.exception))
215
216 def test_max_await_time_ms(self):
217 db = self.db
218 db.pymongo_test.drop()
219 coll = db.create_collection("pymongo_test", capped=True, size=4096)
220
221 with self.assertRaises(TypeError):
222 coll.find().max_await_time_ms("foo") # type: ignore[arg-type]
223 coll.insert_one({"amalia": 1})
224 coll.insert_one({"amalia": 2})
225
226 coll.find().max_await_time_ms(None)
227 coll.find().max_await_time_ms(1)
228
229 # When cursor is not tailable_await
230 cursor = coll.find()
231 self.assertEqual(None, cursor._max_await_time_ms)
232 cursor = coll.find().max_await_time_ms(99)
233 self.assertEqual(None, cursor._max_await_time_ms)
234
235 # If cursor is tailable_await and timeout is unset
236 cursor = coll.find(cursor_type=CursorType.TAILABLE_AWAIT)
237 self.assertEqual(None, cursor._max_await_time_ms)
238
239 # If cursor is tailable_await and timeout is set
240 cursor = coll.find(cursor_type=CursorType.TAILABLE_AWAIT).max_await_time_ms(99)
241 self.assertEqual(99, cursor._max_await_time_ms)
242
243 cursor = (
244 coll.find(cursor_type=CursorType.TAILABLE_AWAIT)
245 .max_await_time_ms(10)
246 .max_await_time_ms(90)
247 )
248 self.assertEqual(90, cursor._max_await_time_ms)
249
250 listener = AllowListEventListener("find", "getMore")
251 coll = (self.rs_or_single_client(event_listeners=[listener]))[self.db.name].pymongo_test
252
253 # Tailable_defaults.
254 coll.find(cursor_type=CursorType.TAILABLE_AWAIT).to_list()
255 # find
256 self.assertNotIn("maxTimeMS", listener.started_events[0].command)
257 # getMore
258 self.assertNotIn("maxTimeMS", listener.started_events[1].command)
259 listener.reset()
260
261 # Tailable_with max_await_time_ms set.
262 coll.find(cursor_type=CursorType.TAILABLE_AWAIT).max_await_time_ms(99).to_list()
263 # find
264 self.assertEqual("find", listener.started_events[0].command_name)
265 self.assertNotIn("maxTimeMS", listener.started_events[0].command)
266 # getMore
267 self.assertEqual("getMore", listener.started_events[1].command_name)
268 self.assertIn("maxTimeMS", listener.started_events[1].command)
269 self.assertEqual(99, listener.started_events[1].command["maxTimeMS"])
270 listener.reset()
271
272 # Tailable_with max_time_ms and make sure list() works on synchronous cursors
273 if _IS_SYNC:

Callers

nothing calls this directly

Calls 10

rs_or_single_clientMethod · 0.80
dropMethod · 0.45
create_collectionMethod · 0.45
max_await_time_msMethod · 0.45
findMethod · 0.45
insert_oneMethod · 0.45
to_listMethod · 0.45
resetMethod · 0.45
max_time_msMethod · 0.45

Tested by

no test coverage detected