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

Method test_max_time_ms

test/asynchronous/test_cursor.py:159–201  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

157 self.assertEqual(False, cursor._allow_disk_use)
158
159 async def test_max_time_ms(self):
160 db = self.db
161 await db.pymongo_test.drop()
162 coll = db.pymongo_test
163 with self.assertRaises(TypeError):
164 coll.find().max_time_ms("foo") # type: ignore[arg-type]
165 await coll.insert_one({"amalia": 1})
166 await coll.insert_one({"amalia": 2})
167
168 coll.find().max_time_ms(None)
169 coll.find().max_time_ms(1)
170
171 cursor = coll.find().max_time_ms(999)
172 self.assertEqual(999, cursor._max_time_ms)
173 cursor = coll.find().max_time_ms(10).max_time_ms(1000)
174 self.assertEqual(1000, cursor._max_time_ms)
175
176 cursor = coll.find().max_time_ms(999)
177 c2 = cursor.clone()
178 self.assertEqual(999, c2._max_time_ms)
179 self.assertIn("$maxTimeMS", cursor._query_spec())
180 self.assertIn("$maxTimeMS", c2._query_spec())
181
182 self.assertTrue(await coll.find_one(max_time_ms=1000))
183
184 client = self.client
185 if not async_client_context.is_mongos and async_client_context.test_commands_enabled:
186 # Cursor parses server timeout error in response to initial query.
187 await client.admin.command(
188 "configureFailPoint", "maxTimeAlwaysTimeOut", mode="alwaysOn"
189 )
190 try:
191 cursor = coll.find().max_time_ms(1)
192 try:
193 await anext(cursor)
194 except ExecutionTimeout:
195 pass
196 else:
197 self.fail("ExecutionTimeout not raised")
198 with self.assertRaises(ExecutionTimeout):
199 await coll.find_one(max_time_ms=1)
200 finally:
201 await client.admin.command("configureFailPoint", "maxTimeAlwaysTimeOut", mode="off")
202
203 async def test_maxtime_ms_message(self):
204 db = self.db

Callers

nothing calls this directly

Calls 9

anextFunction · 0.90
dropMethod · 0.45
max_time_msMethod · 0.45
findMethod · 0.45
insert_oneMethod · 0.45
cloneMethod · 0.45
_query_specMethod · 0.45
find_oneMethod · 0.45
commandMethod · 0.45

Tested by

no test coverage detected