From ee4ff622e03e3c628a75feb9a2ae9f44e81e8a2c Mon Sep 17 00:00:00 2001 From: Noah Stapp Date: Thu, 29 Oct 2026 14:38:58 -0400 Subject: [PATCH 1/2] PYTHON-6205 Reduce flakiness of sharded cluster DNS tests --- test/asynchronous/test_dns.py | 3 +++ test/test_dns.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/test/asynchronous/test_dns.py b/test/asynchronous/test_dns.py index 6c8e864a44..2bc2a8c267 100644 --- a/test/asynchronous/test_dns.py +++ b/test/asynchronous/test_dns.py @@ -153,6 +153,9 @@ async def run_test(self): await client.aconnect() if num_seeds is not None: self.assertEqual(len(client._topology_settings.seeds), num_seeds) + # Wake every monitor now to ensure failed heartbeats retry quickly + # instead of waiting for the full 10-second heartbeat interval. + await client._topology.request_check_all() if hosts is not None: await async_wait_until( lambda: hosts == client.nodes, "match test hosts to client nodes" diff --git a/test/test_dns.py b/test/test_dns.py index bd7308c3d4..4fdcbe65fa 100644 --- a/test/test_dns.py +++ b/test/test_dns.py @@ -153,6 +153,9 @@ def run_test(self): client._connect() if num_seeds is not None: self.assertEqual(len(client._topology_settings.seeds), num_seeds) + # Wake every monitor now to ensure failed heartbeats retry quickly + # instead of waiting for the full 10-second heartbeat interval. + client._topology.request_check_all() if hosts is not None: wait_until(lambda: hosts == client.nodes, "match test hosts to client nodes") if num_hosts is not None: From b0812a696eb81cd688e59d19c0b041bf325cd106 Mon Sep 17 00:00:00 2001 From: Noah Stapp Date: Thu, 29 Oct 2026 15:32:35 -0400 Subject: [PATCH 2/2] Only wake monitors on sharded clusters --- test/asynchronous/test_dns.py | 6 ++++-- test/test_dns.py | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/test/asynchronous/test_dns.py b/test/asynchronous/test_dns.py index 2bc2a8c267..adb14c8862 100644 --- a/test/asynchronous/test_dns.py +++ b/test/asynchronous/test_dns.py @@ -153,9 +153,11 @@ async def run_test(self): await client.aconnect() if num_seeds is not None: self.assertEqual(len(client._topology_settings.seeds), num_seeds) - # Wake every monitor now to ensure failed heartbeats retry quickly + # For sharded clusters, wake every monitor now to ensure + # failed heartbeats retry quickly # instead of waiting for the full 10-second heartbeat interval. - await client._topology.request_check_all() + if async_client_context.is_mongos: + await client._topology.request_check_all() if hosts is not None: await async_wait_until( lambda: hosts == client.nodes, "match test hosts to client nodes" diff --git a/test/test_dns.py b/test/test_dns.py index 4fdcbe65fa..675fac1d81 100644 --- a/test/test_dns.py +++ b/test/test_dns.py @@ -153,9 +153,11 @@ def run_test(self): client._connect() if num_seeds is not None: self.assertEqual(len(client._topology_settings.seeds), num_seeds) - # Wake every monitor now to ensure failed heartbeats retry quickly + # For sharded clusters, wake every monitor now to ensure + # failed heartbeats retry quickly # instead of waiting for the full 10-second heartbeat interval. - client._topology.request_check_all() + if client_context.is_mongos: + client._topology.request_check_all() if hosts is not None: wait_until(lambda: hosts == client.nodes, "match test hosts to client nodes") if num_hosts is not None: