(self)
| 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 |
nothing calls this directly
no test coverage detected