From 8f11cb0cccc920242d6386d19708919c3d431381 Mon Sep 17 00:00:00 2001 From: Noah Stapp Date: Mon, 26 Oct 2026 16:49:41 -0400 Subject: [PATCH 1/2] PYTHON-6193 Add ServerDescription filter to test.test_client.TestClient.test_continuous_network_errors --- test/asynchronous/test_client.py | 9 ++++++--- test/test_client.py | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/test/asynchronous/test_client.py b/test/asynchronous/test_client.py index cc32639e18..fc8583cce5 100644 --- a/test/asynchronous/test_client.py +++ b/test/asynchronous/test_client.py @@ -2267,11 +2267,14 @@ async def test_direct_connection(self): AsyncMongoClient(["host1", "host2"], directConnection=True) async def test_continuous_network_errors(self): + # Only count this client's ServerDescriptions so that objects left + # alive by earlier tests' clients (e.g. monitor greenlets under gevent + # that have not exited yet) don't skew the count. def server_description_count(): i = 0 for obj in gc.get_objects(): try: - if isinstance(obj, ServerDescription): + if isinstance(obj, ServerDescription) and obj.address == ("invalid", 27017): i += 1 except ReferenceError: pass @@ -2290,8 +2293,8 @@ def server_description_count(): await client.close() # If a bug like PYTHON-2433 is reintroduced then too many # ServerDescriptions will be kept alive and this test will fail: - # AssertionError: 11 != 47 within 20 delta (36 difference) - self.assertAlmostEqual(initial_count, final_count, delta=30) + # AssertionError: 1 != 42 within 10 delta (41 difference) + self.assertAlmostEqual(initial_count, final_count, delta=10) @async_client_context.require_failCommand_fail_point async def test_network_error_message(self): diff --git a/test/test_client.py b/test/test_client.py index bca4270ad1..be2325b2b6 100644 --- a/test/test_client.py +++ b/test/test_client.py @@ -2220,11 +2220,14 @@ def test_direct_connection(self): MongoClient(["host1", "host2"], directConnection=True) def test_continuous_network_errors(self): + # Only count this client's ServerDescriptions so that objects left + # alive by earlier tests' clients (e.g. monitor greenlets under gevent + # that have not exited yet) don't skew the count. def server_description_count(): i = 0 for obj in gc.get_objects(): try: - if isinstance(obj, ServerDescription): + if isinstance(obj, ServerDescription) and obj.address == ("invalid", 27017): i += 1 except ReferenceError: pass @@ -2243,8 +2246,8 @@ def server_description_count(): client.close() # If a bug like PYTHON-2433 is reintroduced then too many # ServerDescriptions will be kept alive and this test will fail: - # AssertionError: 11 != 47 within 20 delta (36 difference) - self.assertAlmostEqual(initial_count, final_count, delta=30) + # AssertionError: 1 != 42 within 10 delta (41 difference) + self.assertAlmostEqual(initial_count, final_count, delta=10) @client_context.require_failCommand_fail_point def test_network_error_message(self): From 2c9b5e46190c10270f761a022402728c4ba16dd7 Mon Sep 17 00:00:00 2001 From: Noah Stapp Date: Mon, 26 Oct 2026 16:51:31 -0400 Subject: [PATCH 2/2] Shorter comment --- test/asynchronous/test_client.py | 5 ++--- test/test_client.py | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/test/asynchronous/test_client.py b/test/asynchronous/test_client.py index fc8583cce5..a39b5b1384 100644 --- a/test/asynchronous/test_client.py +++ b/test/asynchronous/test_client.py @@ -2267,9 +2267,8 @@ async def test_direct_connection(self): AsyncMongoClient(["host1", "host2"], directConnection=True) async def test_continuous_network_errors(self): - # Only count this client's ServerDescriptions so that objects left - # alive by earlier tests' clients (e.g. monitor greenlets under gevent - # that have not exited yet) don't skew the count. + # Only count this client's ServerDescriptions so that those left + # alive by earlier tests don't affect the count. def server_description_count(): i = 0 for obj in gc.get_objects(): diff --git a/test/test_client.py b/test/test_client.py index be2325b2b6..378f6c9f8f 100644 --- a/test/test_client.py +++ b/test/test_client.py @@ -2220,9 +2220,8 @@ def test_direct_connection(self): MongoClient(["host1", "host2"], directConnection=True) def test_continuous_network_errors(self): - # Only count this client's ServerDescriptions so that objects left - # alive by earlier tests' clients (e.g. monitor greenlets under gevent - # that have not exited yet) don't skew the count. + # Only count this client's ServerDescriptions so that those left + # alive by earlier tests don't affect the count. def server_description_count(): i = 0 for obj in gc.get_objects():