Skip to content

Commit 3ff6da8

Browse files
committed
cleanup
1 parent 91f950e commit 3ff6da8

File tree

4 files changed

+8
-82
lines changed

4 files changed

+8
-82
lines changed

pymongo/asynchronous/pool.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,7 @@ def __init__(
789789
# Also used for: clearing the wait queue
790790
self._max_connecting_cond = _async_create_condition(self.lock)
791791
self._pending = 0
792+
self._max_connecting = self.opts.max_connecting
792793
self._client_id = client_id
793794
if self.enabled_for_cmap:
794795
assert self.opts._event_listeners is not None
@@ -993,7 +994,7 @@ async def remove_stale_sockets(self, reference_generation: int) -> None:
993994
async with self._max_connecting_cond:
994995
# If maxConnecting connections are already being created
995996
# by this pool then try again later instead of waiting.
996-
if self._pending >= self.opts.max_connecting:
997+
if self._pending >= self._max_connecting:
997998
return
998999
self._pending += 1
9991000
incremented = True
@@ -1299,12 +1300,12 @@ async def _get_conn(
12991300
# to be checked back into the pool.
13001301
async with self._max_connecting_cond:
13011302
self._raise_if_not_ready(checkout_started_time, emit_event=False)
1302-
while not (self.conns or self._pending < self.opts.max_connecting):
1303+
while not (self.conns or self._pending < self._max_connecting):
13031304
timeout = deadline - time.monotonic() if deadline else None
13041305
if not await _async_cond_wait(self._max_connecting_cond, timeout):
13051306
# Timed out, notify the next thread to ensure a
13061307
# timeout doesn't consume the condition.
1307-
if self.conns or self._pending < self.max_connecting:
1308+
if self.conns or self._pending < self._max_connecting:
13081309
self._max_connecting_cond.notify()
13091310
emitted_event = True
13101311
self._raise_wait_queue_timeout(checkout_started_time)

pymongo/synchronous/pool.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,7 @@ def __init__(
787787
# Also used for: clearing the wait queue
788788
self._max_connecting_cond = _create_condition(self.lock)
789789
self._pending = 0
790+
self._max_connecting = self.opts.max_connecting
790791
self._client_id = client_id
791792
if self.enabled_for_cmap:
792793
assert self.opts._event_listeners is not None
@@ -989,7 +990,7 @@ def remove_stale_sockets(self, reference_generation: int) -> None:
989990
with self._max_connecting_cond:
990991
# If maxConnecting connections are already being created
991992
# by this pool then try again later instead of waiting.
992-
if self._pending >= self.opts.max_connecting:
993+
if self._pending >= self._max_connecting:
993994
return
994995
self._pending += 1
995996
incremented = True
@@ -1295,12 +1296,12 @@ def _get_conn(
12951296
# to be checked back into the pool.
12961297
with self._max_connecting_cond:
12971298
self._raise_if_not_ready(checkout_started_time, emit_event=False)
1298-
while not (self.conns or self._pending < self.opts.max_connecting):
1299+
while not (self.conns or self._pending < self._max_connecting):
12991300
timeout = deadline - time.monotonic() if deadline else None
13001301
if not _cond_wait(self._max_connecting_cond, timeout):
13011302
# Timed out, notify the next thread to ensure a
13021303
# timeout doesn't consume the condition.
1303-
if self.conns or self._pending < self.max_connecting:
1304+
if self.conns or self._pending < self._max_connecting:
13041305
self._max_connecting_cond.notify()
13051306
emitted_event = True
13061307
self._raise_wait_queue_timeout(checkout_started_time)

test/asynchronous/test_pooling.py

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -514,31 +514,6 @@ async def test_connection_timeout_message(self):
514514
str(error.exception),
515515
)
516516

517-
async def test_pool_check_backoff(self):
518-
# Test that Pool recovers from two connection failures in a row.
519-
# This exercises code at the end of Pool._check().
520-
cx_pool = await self.create_pool(max_pool_size=1, connect_timeout=1, wait_queue_timeout=1)
521-
self.addAsyncCleanup(cx_pool.close)
522-
523-
async with cx_pool.checkout() as conn:
524-
# Simulate a closed socket without telling the Connection it's
525-
# closed.
526-
await conn.conn.close()
527-
528-
# Enable backoff.
529-
cx_pool._backoff = 1
530-
531-
# Swap pool's address with a bad one.
532-
address, cx_pool.address = cx_pool.address, ("foo.com", 1234)
533-
with self.assertRaises(AutoReconnect):
534-
async with cx_pool.checkout():
535-
pass
536-
537-
# Back to normal, semaphore was correctly released.
538-
cx_pool.address = address
539-
async with cx_pool.checkout():
540-
pass
541-
542517
@async_client_context.require_failCommand_appName
543518
async def test_pool_backoff_preserves_existing_connections(self):
544519
client = await self.async_rs_or_single_client()
@@ -564,9 +539,6 @@ async def test_pool_backoff_preserves_existing_connections(self):
564539
async with self.fail_point(mock_connection_fail):
565540
await coll.find_one({})
566541

567-
# Make sure the pool is out of backoff state.
568-
assert pool._backoff == 0
569-
570542
# Make sure the existing socket was not affected.
571543
assert not t.sock.conn_closed()
572544

@@ -575,16 +547,6 @@ async def test_pool_backoff_preserves_existing_connections(self):
575547
await t.join()
576548
await pool.close()
577549

578-
async def test_pool_backoff_limits_maxConnecting(self):
579-
client = await self.async_rs_or_single_client(maxConnecting=10)
580-
pool = await async_get_pool(client)
581-
assert pool.max_connecting == 10
582-
pool._backoff = 1
583-
assert pool.max_connecting == 1
584-
pool._backoff = 0
585-
assert pool.max_connecting == 10
586-
await client.close()
587-
588550

589551
class TestPoolMaxSize(_TestPoolingBase):
590552
async def test_max_pool_size(self):

test/test_pooling.py

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -512,31 +512,6 @@ def test_connection_timeout_message(self):
512512
str(error.exception),
513513
)
514514

515-
def test_pool_check_backoff(self):
516-
# Test that Pool recovers from two connection failures in a row.
517-
# This exercises code at the end of Pool._check().
518-
cx_pool = self.create_pool(max_pool_size=1, connect_timeout=1, wait_queue_timeout=1)
519-
self.addCleanup(cx_pool.close)
520-
521-
with cx_pool.checkout() as conn:
522-
# Simulate a closed socket without telling the Connection it's
523-
# closed.
524-
conn.conn.close()
525-
526-
# Enable backoff.
527-
cx_pool._backoff = 1
528-
529-
# Swap pool's address with a bad one.
530-
address, cx_pool.address = cx_pool.address, ("foo.com", 1234)
531-
with self.assertRaises(AutoReconnect):
532-
with cx_pool.checkout():
533-
pass
534-
535-
# Back to normal, semaphore was correctly released.
536-
cx_pool.address = address
537-
with cx_pool.checkout():
538-
pass
539-
540515
@client_context.require_failCommand_appName
541516
def test_pool_backoff_preserves_existing_connections(self):
542517
client = self.rs_or_single_client()
@@ -562,9 +537,6 @@ def test_pool_backoff_preserves_existing_connections(self):
562537
with self.fail_point(mock_connection_fail):
563538
coll.find_one({})
564539

565-
# Make sure the pool is out of backoff state.
566-
assert pool._backoff == 0
567-
568540
# Make sure the existing socket was not affected.
569541
assert not t.sock.conn_closed()
570542

@@ -573,16 +545,6 @@ def test_pool_backoff_preserves_existing_connections(self):
573545
t.join()
574546
pool.close()
575547

576-
def test_pool_backoff_limits_maxConnecting(self):
577-
client = self.rs_or_single_client(maxConnecting=10)
578-
pool = get_pool(client)
579-
assert pool.max_connecting == 10
580-
pool._backoff = 1
581-
assert pool.max_connecting == 1
582-
pool._backoff = 0
583-
assert pool.max_connecting == 10
584-
client.close()
585-
586548

587549
class TestPoolMaxSize(_TestPoolingBase):
588550
def test_max_pool_size(self):

0 commit comments

Comments
 (0)