[Build Failure] test_connection_close_does_not_block_other_operations is flaky

XMLWordPrintableJSON

    • Type: Build Failure
    • Resolution: Unresolved
    • Priority: Unknown
    • None
    • Affects Version/s: None
    • Component/s: greenerbuild
    • None
    • Python Drivers
    • Not Needed
    • None
    • None
    • None
    • None
    • None
    • None

      Name of Failure:

      test/asynchronous/test_discovery_and_monitoring.py::TestPoolManagement::test_connection_close_does_not_block_other_operations - AssertionError: 0.5628197339999588 not less than or equal to 0.5

      Link to task:

      https://spruce.mongodb.com/task/mongo_python_driver_mongodb_v4.4_test_server_version_pypy3.10_async_auth_nossl_replica_set_0b2900d162ffeca355d7fa43111c4df02cf488be_25_07_01_20_42_58/logs?execution=0

      Context of when and why the failure occurred:

      Flaky test on pypy. Related to PYTHON-5011.

      Stack trace:

       [2025/07/01 16:19:38.865] ___ TestPoolManagement.test_connection_close_does_not_block_other_operations ___
       [2025/07/01 16:19:38.865] self = <test.asynchronous.test_discovery_and_monitoring.TestPoolManagement testMethod=test_connection_close_does_not_block_other_operations>
       [2025/07/01 16:19:38.865]     @async_client_context.require_failCommand_appName
       [2025/07/01 16:19:38.865]     @async_client_context.require_test_commands
       [2025/07/01 16:19:38.865]     @async_client_context.require_async
       [2025/07/01 16:19:38.865]     async def test_connection_close_does_not_block_other_operations(self):
       [2025/07/01 16:19:38.865]         listener = CMAPHeartbeatListener()
       [2025/07/01 16:19:38.865]         client = await self.async_single_client(
       [2025/07/01 16:19:38.865]             appName="SDAMConnectionCloseTest",
       [2025/07/01 16:19:38.865]             event_listeners=[listener],
       [2025/07/01 16:19:38.865]             heartbeatFrequencyMS=500,
       [2025/07/01 16:19:38.865]             minPoolSize=10,
       [2025/07/01 16:19:38.865]         )
       [2025/07/01 16:19:38.865]         server = await (await client._get_topology()).select_server(
       [2025/07/01 16:19:38.865]             writable_server_selector, _Op.TEST
       [2025/07/01 16:19:38.865]         )
       [2025/07/01 16:19:38.865]         await async_wait_until(
       [2025/07/01 16:19:38.865]             lambda: len(server._pool.conns) == 10,
       [2025/07/01 16:19:38.865]             "pool initialized with 10 connections",
       [2025/07/01 16:19:38.865]         )
       [2025/07/01 16:19:38.865]         await client.db.test.insert_one({"x": 1})
       [2025/07/01 16:19:38.865]         close_delay = 0.1
       [2025/07/01 16:19:38.865]         latencies = []
       [2025/07/01 16:19:38.865]         should_exit = []
       [2025/07/01 16:19:38.865]         async def run_task():
       [2025/07/01 16:19:38.865]             while True:
       [2025/07/01 16:19:38.865]                 start_time = time.monotonic()
       [2025/07/01 16:19:38.865]                 await client.db.test.find_one({})
       [2025/07/01 16:19:38.865]                 elapsed = time.monotonic() - start_time
       [2025/07/01 16:19:38.865]                 latencies.append(elapsed)
       [2025/07/01 16:19:38.865]                 if should_exit:
       [2025/07/01 16:19:38.865]                     break
       [2025/07/01 16:19:38.865]                 await asyncio.sleep(0.001)
       [2025/07/01 16:19:38.865]         task = ConcurrentRunner(target=run_task)
       [2025/07/01 16:19:38.865]         await task.start()
       [2025/07/01 16:19:38.865]         original_close = AsyncConnection.close_conn
       [2025/07/01 16:19:38.865]         try:
       [2025/07/01 16:19:38.865]             # Artificially delay the close operation to simulate a slow close
       [2025/07/01 16:19:38.865]             async def mock_close(self, reason):
       [2025/07/01 16:19:38.865]                 await asyncio.sleep(close_delay)
       [2025/07/01 16:19:38.865]                 await original_close(self, reason)
       [2025/07/01 16:19:38.865]             AsyncConnection.close_conn = mock_close
       [2025/07/01 16:19:38.865]             fail_hello = {
       [2025/07/01 16:19:38.865]                 "mode": {"times": 4},
       [2025/07/01 16:19:38.865]                 "data": {
       [2025/07/01 16:19:38.865]                     "failCommands": [HelloCompat.LEGACY_CMD, "hello"],
       [2025/07/01 16:19:38.865]                     "errorCode": 91,
       [2025/07/01 16:19:38.865]                     "appName": "SDAMConnectionCloseTest",
       [2025/07/01 16:19:38.865]                 },
       [2025/07/01 16:19:38.865]             }
       [2025/07/01 16:19:38.865]             async with self.fail_point(fail_hello):
       [2025/07/01 16:19:38.865]                 # Wait for server heartbeat to fail
       [2025/07/01 16:19:38.865]                 await listener.async_wait_for_event(monitoring.ServerHeartbeatFailedEvent, 1)
       [2025/07/01 16:19:38.865]             # Wait until all idle connections are closed to simulate real-world conditions
       [2025/07/01 16:19:38.865]             await listener.async_wait_for_event(monitoring.ConnectionClosedEvent, 10)
       [2025/07/01 16:19:38.865]             # Wait for one more find to complete after the pool has been reset, then shutdown the task
       [2025/07/01 16:19:38.865]             n = len(latencies)
       [2025/07/01 16:19:38.865]             await async_wait_until(lambda: len(latencies) >= n + 1, "run one more find")
       [2025/07/01 16:19:38.865]             should_exit.append(True)
       [2025/07/01 16:19:38.865]             await task.join()
       [2025/07/01 16:19:38.865]             # No operation latency should not significantly exceed close_delay
       [2025/07/01 16:19:38.865] >           self.assertLessEqual(max(latencies), close_delay * 5.0)
       [2025/07/01 16:19:38.865] E           AssertionError: 0.5628197339999588 not less than or equal to 0.5
      

            Assignee:
            Steve Silvester
            Reporter:
            Steve Silvester
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: