Skip to content

Commit 6880faf

Browse files
committed
Remove unneeded test_locks
1 parent 1fec0a1 commit 6880faf

File tree

8 files changed

+22
-525
lines changed

8 files changed

+22
-525
lines changed

pymongo/asynchronous/pool.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import socket
2424
import ssl
2525
import sys
26-
import threading
2726
import time
2827
import weakref
2928
from typing import (
@@ -992,8 +991,8 @@ def __init__(
992991
self.conns: collections.deque = collections.deque()
993992
self.active_contexts: set[_CancellationContext] = set()
994993
self.lock = _async_create_lock()
995-
self.size_cond = _async_create_condition(self.lock, threading.Condition)
996-
self._max_connecting_cond = _async_create_condition(self.lock, threading.Condition)
994+
self.size_cond = _async_create_condition(self.lock)
995+
self._max_connecting_cond = _async_create_condition(self.lock)
997996
self.active_sockets = 0
998997
# Monotonically increasing connection ID required for CMAP Events.
999998
self.next_connection_id = 1

pymongo/asynchronous/topology.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,9 @@ def __init__(self, topology_settings: TopologySettings):
174174
self._opened = False
175175
self._closed = False
176176
self._lock = _async_create_lock()
177-
self._condition = _async_create_condition(self._lock, self._settings.condition_class)
177+
self._condition = _async_create_condition(
178+
self._lock, self._settings.condition_class if _IS_SYNC else None
179+
)
178180
self._servers: dict[_Address, Server] = {}
179181
self._pid: Optional[int] = None
180182
self._max_cluster_time: Optional[ClusterTime] = None

pymongo/lock.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,21 @@ def _async_create_lock() -> asyncio.Lock:
4242
return asyncio.Lock()
4343

4444

45-
def _create_condition(lock: threading.Lock, dummy: Any) -> threading.Condition:
45+
def _create_condition(
46+
lock: threading.Lock, condition_class: Optional[Any] = None
47+
) -> threading.Condition:
4648
"""Represents a threading.Condition."""
49+
if condition_class:
50+
return condition_class(lock)
4751
return threading.Condition(lock)
4852

4953

50-
def _async_create_condition(lock: asyncio.Lock, dummy: Any) -> asyncio.Condition:
54+
def _async_create_condition(
55+
lock: asyncio.Lock, condition_class: Optional[Any] = None
56+
) -> asyncio.Condition:
5157
"""Represents an asyncio.Condition."""
58+
if condition_class:
59+
return condition_class(lock)
5260
return asyncio.Condition(lock)
5361

5462

pymongo/synchronous/pool.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import socket
2424
import ssl
2525
import sys
26-
import threading
2726
import time
2827
import weakref
2928
from typing import (
@@ -988,8 +987,8 @@ def __init__(
988987
self.conns: collections.deque = collections.deque()
989988
self.active_contexts: set[_CancellationContext] = set()
990989
self.lock = _create_lock()
991-
self.size_cond = _create_condition(self.lock, threading.Condition)
992-
self._max_connecting_cond = _create_condition(self.lock, threading.Condition)
990+
self.size_cond = _create_condition(self.lock)
991+
self._max_connecting_cond = _create_condition(self.lock)
993992
self.active_sockets = 0
994993
# Monotonically increasing connection ID required for CMAP Events.
995994
self.next_connection_id = 1

pymongo/synchronous/topology.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,9 @@ def __init__(self, topology_settings: TopologySettings):
174174
self._opened = False
175175
self._closed = False
176176
self._lock = _create_lock()
177-
self._condition = _create_condition(self._lock, self._settings.condition_class)
177+
self._condition = _create_condition(
178+
self._lock, self._settings.condition_class if _IS_SYNC else None
179+
)
178180
self._servers: dict[_Address, Server] = {}
179181
self._pid: Optional[int] = None
180182
self._max_cluster_time: Optional[ClusterTime] = None

test/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1131,7 +1131,7 @@ class IntegrationTest(PyMongoTestCase):
11311131

11321132
@client_context.require_connection
11331133
def setUp(self) -> None:
1134-
if not _IS_SYNC:
1134+
if not _IS_SYNC and client_context.client is not None:
11351135
reset_client_context()
11361136
if client_context.load_balancer and not getattr(self, "RUN_ON_LOAD_BALANCER", False):
11371137
raise SkipTest("this test does not support load balancers")

test/asynchronous/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1149,7 +1149,7 @@ class AsyncIntegrationTest(AsyncPyMongoTestCase):
11491149

11501150
@async_client_context.require_connection
11511151
async def asyncSetUp(self) -> None:
1152-
if not _IS_SYNC:
1152+
if not _IS_SYNC and async_client_context.client is not None:
11531153
await reset_client_context()
11541154
if async_client_context.load_balancer and not getattr(self, "RUN_ON_LOAD_BALANCER", False):
11551155
raise SkipTest("this test does not support load balancers")

0 commit comments

Comments
 (0)