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

Method test_exhaust

test/test_monitoring.py:423–481  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

421
422 @client_context.require_no_mongos
423 def test_exhaust(self):
424 self.client.pymongo_test.test.drop()
425 self.client.pymongo_test.test.insert_many([{} for _ in range(11)])
426 self.listener.reset()
427 cursor = self.client.pymongo_test.test.find(
428 projection={"_id": False}, batch_size=5, cursor_type=CursorType.EXHAUST
429 )
430 next(cursor)
431 cursor_id = cursor.cursor_id
432 started = self.listener.started_events[0]
433 succeeded = self.listener.succeeded_events[0]
434 self.assertEqual(0, len(self.listener.failed_events))
435 self.assertIsInstance(started, monitoring.CommandStartedEvent)
436 self.assertEqualCommand(
437 SON(
438 [("find", "test"), ("filter", {}), ("projection", {"_id": False}), ("batchSize", 5)]
439 ),
440 started.command,
441 )
442 self.assertEqual("find", started.command_name)
443 self.assertEqual(cursor.address, started.connection_id)
444 self.assertEqual("pymongo_test", started.database_name)
445 self.assertIsInstance(started.request_id, int)
446 self.assertIsInstance(succeeded, monitoring.CommandSucceededEvent)
447 self.assertIsInstance(succeeded.duration_micros, int)
448 self.assertEqual("find", succeeded.command_name)
449 self.assertIsInstance(succeeded.request_id, int)
450 self.assertEqual(cursor.address, succeeded.connection_id)
451 expected_result = {
452 "cursor": {
453 "id": cursor_id,
454 "ns": "pymongo_test.test",
455 "firstBatch": [{} for _ in range(5)],
456 },
457 "ok": 1,
458 }
459 self.assertEqualReply(expected_result, succeeded.reply)
460
461 self.listener.reset()
462 tuple(cursor.to_list())
463 self.assertEqual(0, len(self.listener.failed_events))
464 for event in self.listener.started_events:
465 self.assertIsInstance(event, monitoring.CommandStartedEvent)
466 self.assertEqualCommand(
467 SON([("getMore", cursor_id), ("collection", "test"), ("batchSize", 5)]),
468 event.command,
469 )
470 self.assertEqual("getMore", event.command_name)
471 self.assertEqual(cursor.address, event.connection_id)
472 self.assertEqual("pymongo_test", event.database_name)
473 self.assertIsInstance(event.request_id, int)
474 for event in self.listener.succeeded_events:
475 self.assertIsInstance(event, monitoring.CommandSucceededEvent)
476 self.assertIsInstance(event.duration_micros, int)
477 self.assertEqual("getMore", event.command_name)
478 self.assertIsInstance(event.request_id, int)
479 self.assertEqual(cursor.address, event.connection_id)
480 # Last getMore receives a response with cursor id 0.

Callers

nothing calls this directly

Calls 9

nextFunction · 0.90
SONClass · 0.90
dropMethod · 0.45
insert_manyMethod · 0.45
resetMethod · 0.45
findMethod · 0.45
assertEqualCommandMethod · 0.45
assertEqualReplyMethod · 0.45
to_listMethod · 0.45

Tested by

no test coverage detected