Skip to content
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
8 changes: 5 additions & 3 deletions test/asynchronous/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2267,11 +2267,13 @@ 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 those left
# alive by earlier tests don't affect 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
Expand All @@ -2290,8 +2292,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):
Expand Down
8 changes: 5 additions & 3 deletions test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2220,11 +2220,13 @@ def test_direct_connection(self):
MongoClient(["host1", "host2"], directConnection=True)

def test_continuous_network_errors(self):
# 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():
try:
if isinstance(obj, ServerDescription):
if isinstance(obj, ServerDescription) and obj.address == ("invalid", 27017):
i += 1
except ReferenceError:
pass
Expand All @@ -2243,8 +2245,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):
Expand Down
Loading