Skip to content

PYTHON-5173 Adjust test_continuous_network_errors to be less flaky #2183

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions test/asynchronous/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1824,20 +1824,20 @@ def server_description_count():
return i

gc.collect()
with client_knobs(min_heartbeat_interval=0.003):
with client_knobs(min_heartbeat_interval=0.002):
client = self.simple_client(
"invalid:27017", heartbeatFrequencyMS=3, serverSelectionTimeoutMS=150
"invalid:27017", heartbeatFrequencyMS=2, serverSelectionTimeoutMS=200
)
initial_count = server_description_count()
with self.assertRaises(ServerSelectionTimeoutError):
await client.test.test.find_one()
gc.collect()
final_count = 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: 19 != 46 within 15 delta (27 difference)
# On Python 3.11 we seem to get more of a delta.
self.assertAlmostEqual(initial_count, final_count, delta=20)
# AssertionError: 11 != 47 within 20 delta (36 difference)
self.assertAlmostEqual(initial_count, final_count, delta=30)

@async_client_context.require_failCommand_fail_point
async def test_network_error_message(self):
Expand Down
10 changes: 5 additions & 5 deletions test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1781,20 +1781,20 @@ def server_description_count():
return i

gc.collect()
with client_knobs(min_heartbeat_interval=0.003):
with client_knobs(min_heartbeat_interval=0.002):
client = self.simple_client(
"invalid:27017", heartbeatFrequencyMS=3, serverSelectionTimeoutMS=150
"invalid:27017", heartbeatFrequencyMS=2, serverSelectionTimeoutMS=200
)
initial_count = server_description_count()
with self.assertRaises(ServerSelectionTimeoutError):
client.test.test.find_one()
gc.collect()
final_count = 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: 19 != 46 within 15 delta (27 difference)
# On Python 3.11 we seem to get more of a delta.
self.assertAlmostEqual(initial_count, final_count, delta=20)
# AssertionError: 11 != 47 within 20 delta (36 difference)
self.assertAlmostEqual(initial_count, final_count, delta=30)

@client_context.require_failCommand_fail_point
def test_network_error_message(self):
Expand Down
Loading