diff --git a/test/asynchronous/test_cursor.py b/test/asynchronous/test_cursor.py index 925584b89..833493ce3 100644 --- a/test/asynchronous/test_cursor.py +++ b/test/asynchronous/test_cursor.py @@ -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) diff --git a/test/test_cursor.py b/test/test_cursor.py index 26f0575da..e995bd529 100644 --- a/test/test_cursor.py +++ b/test/test_cursor.py @@ -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)