Skip to content

Commit dcaa42b

Browse files
authored
PYTHON-4632 Fix test_connection_timeout_message (mongodb#1774)
1 parent 000e50c commit dcaa42b

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

test/test_pooling.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,8 @@ def find_one():
416416
@client_context.require_failCommand_fail_point
417417
def test_csot_timeout_message(self):
418418
client = rs_or_single_client(appName="connectionTimeoutApp")
419-
# Mock a connection failing due to timeout.
419+
self.addCleanup(client.close)
420+
# Mock an operation failing due to pymongo.timeout().
420421
mock_connection_timeout = {
421422
"configureFailPoint": "failCommand",
422423
"mode": "alwaysOn",
@@ -440,8 +441,8 @@ def test_csot_timeout_message(self):
440441
@client_context.require_failCommand_fail_point
441442
def test_socket_timeout_message(self):
442443
client = rs_or_single_client(socketTimeoutMS=500, appName="connectionTimeoutApp")
443-
444-
# Mock a connection failing due to timeout.
444+
self.addCleanup(client.close)
445+
# Mock an operation failing due to socketTimeoutMS.
445446
mock_connection_timeout = {
446447
"configureFailPoint": "failCommand",
447448
"mode": "alwaysOn",
@@ -469,7 +470,7 @@ def test_socket_timeout_message(self):
469470
4, 9, 0
470471
) # configureFailPoint does not allow failure on handshake before 4.9, fixed in SERVER-49336
471472
def test_connection_timeout_message(self):
472-
# Mock a connection failing due to timeout.
473+
# Mock a connection creation failing due to timeout.
473474
mock_connection_timeout = {
474475
"configureFailPoint": "failCommand",
475476
"mode": "alwaysOn",
@@ -481,9 +482,18 @@ def test_connection_timeout_message(self):
481482
},
482483
}
483484

485+
client = rs_or_single_client(
486+
connectTimeoutMS=500,
487+
socketTimeoutMS=500,
488+
appName="connectionTimeoutApp",
489+
heartbeatFrequencyMS=1000000,
490+
)
491+
self.addCleanup(client.close)
492+
client.admin.command("ping")
493+
pool = get_pool(client)
494+
pool.reset_without_pause()
484495
with self.fail_point(mock_connection_timeout):
485496
with self.assertRaises(Exception) as error:
486-
client = rs_or_single_client(connectTimeoutMS=500, appName="connectionTimeoutApp")
487497
client.admin.command("ping")
488498

489499
self.assertTrue(

0 commit comments

Comments
 (0)