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

Method _test_cursor_helper

test/test_session.py:693–719  ·  view source on GitHub ↗
(self, create_cursor, close_cursor)

Source from the content-addressed store, hash-verified

691 self.assertIn(lsid, session_ids(client))
692
693 def _test_cursor_helper(self, create_cursor, close_cursor):
694 coll = self.client.pymongo_test.collection
695 coll.insert_many([{} for _ in range(1000)])
696
697 cursor = create_cursor(coll, None)
698 next(cursor)
699 # Session is "owned" by cursor.
700 session = cursor._session
701 self.assertIsNotNone(session)
702 lsid = session.session_id
703 next(cursor)
704
705 # Cursor owns its session unto death.
706 self.assertNotIn(lsid, session_ids(self.client))
707 close_cursor(cursor)
708 self.assertIn(lsid, session_ids(self.client))
709
710 # An explicit session is not ended by cursor.close() or list(cursor).
711 with self.client.start_session() as s:
712 cursor = create_cursor(coll, s)
713 next(cursor)
714 close_cursor(cursor)
715 self.assertFalse(s.has_ended)
716 lsid = s.session_id
717
718 self.assertTrue(s.has_ended)
719 self.assertIn(lsid, session_ids(self.client))
720
721 def test_cursor_close(self):
722 def find(coll, session):

Calls 4

nextFunction · 0.90
session_idsFunction · 0.70
insert_manyMethod · 0.45
start_sessionMethod · 0.45

Tested by

no test coverage detected