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

Method test_close_kills_cursors

test/test_client.py:1074–1105  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1072 coll.count_documents({})
1073
1074 def test_close_kills_cursors(self):
1075 test_client = self.rs_or_single_client()
1076 # Kill any cursors possibly queued up by previous tests.
1077 gc.collect()
1078 test_client._process_periodic_tasks()
1079
1080 # Add some test data.
1081 coll = test_client.pymongo_test.test_close_kills_cursors
1082 docs_inserted = 1000
1083 coll.insert_many([{"i": i} for i in range(docs_inserted)])
1084
1085 # Open a cursor and leave it open on the server.
1086 cursor = coll.find().batch_size(10)
1087 self.assertTrue(bool(next(cursor)))
1088 self.assertLess(cursor.retrieved, docs_inserted)
1089
1090 # Open a command cursor and leave it open on the server.
1091 cursor = coll.aggregate([], batchSize=10)
1092 self.assertTrue(bool(next(cursor)))
1093 del cursor
1094 # Required for PyPy and other Python implementations that
1095 # don't use reference counting garbage collection.
1096 gc.collect()
1097
1098 # Close the client and ensure the topology is closed.
1099 self.assertTrue(test_client._topology._opened)
1100 test_client.close()
1101 self.assertFalse(test_client._topology._opened)
1102 test_client = self.rs_or_single_client()
1103 # The killCursors task should not need to re-open the topology.
1104 test_client._process_periodic_tasks()
1105 self.assertTrue(test_client._topology._opened)
1106
1107 def test_close_stops_kill_cursors_thread(self):
1108 client = self.rs_client()

Callers

nothing calls this directly

Calls 8

nextFunction · 0.90
rs_or_single_clientMethod · 0.80
insert_manyMethod · 0.45
batch_sizeMethod · 0.45
findMethod · 0.45
aggregateMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected