PYTHON-4610 More robust to_list tests (#1773)
This commit is contained in:
parent
d08fec6342
commit
da59318327
@ -1380,41 +1380,39 @@ class TestCursor(AsyncIntegrationTest):
|
||||
self.assertEqual("getMore", started[1].command_name)
|
||||
self.assertNotIn("$readPreference", started[1].command)
|
||||
|
||||
@async_client_context.require_version_min(4, 0)
|
||||
@async_client_context.require_replica_set
|
||||
async def test_to_list_tailable(self):
|
||||
oplog = self.client.local.oplog.rs
|
||||
last = await oplog.find().sort("$natural", pymongo.DESCENDING).limit(-1).next()
|
||||
ts = last["ts"]
|
||||
|
||||
# Set maxAwaitTimeMS=1 to speed up the test and avoid blocking on the noop writer.
|
||||
c = oplog.find(
|
||||
{"ts": {"$gte": ts}}, cursor_type=pymongo.CursorType.TAILABLE_AWAIT, oplog_replay=True
|
||||
)
|
||||
|
||||
).max_await_time_ms(1)
|
||||
self.addAsyncCleanup(c.close)
|
||||
docs = await c.to_list()
|
||||
|
||||
self.assertGreaterEqual(len(docs), 1)
|
||||
|
||||
async def test_to_list_empty(self):
|
||||
c = self.db.does_not_exist.find()
|
||||
|
||||
docs = await c.to_list()
|
||||
|
||||
self.assertEqual([], docs)
|
||||
|
||||
@async_client_context.require_replica_set
|
||||
@async_client_context.require_change_streams
|
||||
async def test_command_cursor_to_list(self):
|
||||
c = await self.db.test.aggregate([{"$changeStream": {}}])
|
||||
|
||||
# Set maxAwaitTimeMS=1 to speed up the test.
|
||||
c = await self.db.test.aggregate([{"$changeStream": {}}], maxAwaitTimeMS=1)
|
||||
self.addAsyncCleanup(c.close)
|
||||
docs = await c.to_list()
|
||||
|
||||
self.assertGreaterEqual(len(docs), 0)
|
||||
|
||||
@async_client_context.require_replica_set
|
||||
@async_client_context.require_change_streams
|
||||
async def test_command_cursor_to_list_empty(self):
|
||||
c = await self.db.does_not_exist.aggregate([{"$changeStream": {}}])
|
||||
|
||||
# Set maxAwaitTimeMS=1 to speed up the test.
|
||||
c = await self.db.does_not_exist.aggregate([{"$changeStream": {}}], maxAwaitTimeMS=1)
|
||||
self.addAsyncCleanup(c.close)
|
||||
docs = await c.to_list()
|
||||
|
||||
self.assertEqual([], docs)
|
||||
|
||||
|
||||
|
||||
@ -1371,41 +1371,39 @@ class TestCursor(IntegrationTest):
|
||||
self.assertEqual("getMore", started[1].command_name)
|
||||
self.assertNotIn("$readPreference", started[1].command)
|
||||
|
||||
@client_context.require_version_min(4, 0)
|
||||
@client_context.require_replica_set
|
||||
def test_to_list_tailable(self):
|
||||
oplog = self.client.local.oplog.rs
|
||||
last = oplog.find().sort("$natural", pymongo.DESCENDING).limit(-1).next()
|
||||
ts = last["ts"]
|
||||
|
||||
# Set maxAwaitTimeMS=1 to speed up the test and avoid blocking on the noop writer.
|
||||
c = oplog.find(
|
||||
{"ts": {"$gte": ts}}, cursor_type=pymongo.CursorType.TAILABLE_AWAIT, oplog_replay=True
|
||||
)
|
||||
|
||||
).max_await_time_ms(1)
|
||||
self.addCleanup(c.close)
|
||||
docs = c.to_list()
|
||||
|
||||
self.assertGreaterEqual(len(docs), 1)
|
||||
|
||||
def test_to_list_empty(self):
|
||||
c = self.db.does_not_exist.find()
|
||||
|
||||
docs = c.to_list()
|
||||
|
||||
self.assertEqual([], docs)
|
||||
|
||||
@client_context.require_replica_set
|
||||
@client_context.require_change_streams
|
||||
def test_command_cursor_to_list(self):
|
||||
c = self.db.test.aggregate([{"$changeStream": {}}])
|
||||
|
||||
# Set maxAwaitTimeMS=1 to speed up the test.
|
||||
c = self.db.test.aggregate([{"$changeStream": {}}], maxAwaitTimeMS=1)
|
||||
self.addCleanup(c.close)
|
||||
docs = c.to_list()
|
||||
|
||||
self.assertGreaterEqual(len(docs), 0)
|
||||
|
||||
@client_context.require_replica_set
|
||||
@client_context.require_change_streams
|
||||
def test_command_cursor_to_list_empty(self):
|
||||
c = self.db.does_not_exist.aggregate([{"$changeStream": {}}])
|
||||
|
||||
# Set maxAwaitTimeMS=1 to speed up the test.
|
||||
c = self.db.does_not_exist.aggregate([{"$changeStream": {}}], maxAwaitTimeMS=1)
|
||||
self.addCleanup(c.close)
|
||||
docs = c.to_list()
|
||||
|
||||
self.assertEqual([], docs)
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user