Skip to content

Commit 40b1aaf

Browse files
committed
Test that Pool releases its semaphore after connection error. PYTHON-580
1 parent 2c161ce commit 40b1aaf

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

test/test_pooling_base.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,28 @@ def test_max_pool_size_with_end_request_only(self):
999999
# Call end_request() but not start_request()
10001000
self._test_max_pool_size(0, 1)
10011001

1002+
def test_max_pool_size_with_connection_failure(self):
1003+
# The pool acquires its semaphore before attempting to connect; ensure
1004+
# it releases the semaphore on connection failure.
1005+
class TestPool(Pool):
1006+
def connect(self, pair):
1007+
raise socket.error()
1008+
1009+
test_pool = TestPool(
1010+
pair=('example.com', 27017),
1011+
max_size=1,
1012+
net_timeout=1,
1013+
conn_timeout=1,
1014+
use_ssl=False,
1015+
wait_queue_timeout=1,
1016+
use_greenlets=self.use_greenlets)
1017+
1018+
# First call to get_socket fails; if pool doesn't release its semaphore
1019+
# then the second call raises "ConnectionFailure: Timed out waiting for
1020+
# socket from pool" instead of the socket.error.
1021+
for i in range(2):
1022+
self.assertRaises(socket.error, test_pool.get_socket)
1023+
10021024

10031025
class SocketGetter(MongoThread):
10041026
"""Utility for _TestMaxOpenSockets and _TestWaitQueueMultiple"""

0 commit comments

Comments
 (0)