Skip to content

Commit 90b4693

Browse files
committed
Undo unintended test/__init__.py changes
1 parent 1a643c3 commit 90b4693

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

test/__init__.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import socket
2323
import subprocess
2424
import sys
25+
import threading
2526
import time
2627
import unittest
2728
import warnings
@@ -113,7 +114,7 @@ def __init__(self):
113114
self.default_client_options: Dict = {}
114115
self.sessions_enabled = False
115116
self.client = None # type: ignore
116-
self.conn_lock = _create_lock()
117+
self.conn_lock = threading.Lock()
117118
self.is_data_lake = False
118119
self.load_balancer = TEST_LOADBALANCER
119120
self.serverless = TEST_SERVERLESS
@@ -697,7 +698,7 @@ def is_topology_type(self, topologies):
697698
if "sharded" in topologies and self.is_mongos:
698699
return True
699700
if "sharded-replicaset" in topologies and self.is_mongos:
700-
shards = self.client.config.shards.find().to_list()
701+
shards = client_context.client.config.shards.find().to_list()
701702
for shard in shards:
702703
# For a 3-member RS-backed sharded cluster, shard['host']
703704
# will be 'replicaName/ip1:port1,ip2:port2,ip3:port3'
@@ -871,6 +872,16 @@ def max_message_size_bytes(self):
871872
client_context = ClientContext()
872873

873874

875+
def reset_client_context():
876+
if _IS_SYNC:
877+
# sync tests don't need to reset a client context
878+
return
879+
elif client_context.client is not None:
880+
client_context.client.close()
881+
client_context.client = None
882+
client_context._init_client()
883+
884+
874885
class PyMongoTestCasePyTest:
875886
@contextmanager
876887
def fail_point(self, client, command_args):
@@ -1145,6 +1156,8 @@ class IntegrationTest(PyMongoTestCase):
11451156

11461157
@client_context.require_connection
11471158
def setUp(self) -> None:
1159+
if not _IS_SYNC:
1160+
reset_client_context()
11481161
if client_context.load_balancer and not getattr(self, "RUN_ON_LOAD_BALANCER", False):
11491162
raise SkipTest("this test does not support load balancers")
11501163
if client_context.serverless and not getattr(self, "RUN_ON_SERVERLESS", False):

test/asynchronous/__init__.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import socket
2323
import subprocess
2424
import sys
25+
import threading
2526
import time
2627
import unittest
2728
import warnings
@@ -113,7 +114,7 @@ def __init__(self):
113114
self.default_client_options: Dict = {}
114115
self.sessions_enabled = False
115116
self.client = None # type: ignore
116-
self.conn_lock = _async_create_lock()
117+
self.conn_lock = threading.Lock()
117118
self.is_data_lake = False
118119
self.load_balancer = TEST_LOADBALANCER
119120
self.serverless = TEST_SERVERLESS
@@ -334,7 +335,7 @@ async def _init_client(self):
334335
await mongos_client.close()
335336

336337
async def init(self):
337-
async with self.conn_lock:
338+
with self.conn_lock:
338339
if not self.client and not self.connection_attempts:
339340
await self._init_client()
340341

@@ -699,7 +700,7 @@ async def is_topology_type(self, topologies):
699700
if "sharded" in topologies and self.is_mongos:
700701
return True
701702
if "sharded-replicaset" in topologies and self.is_mongos:
702-
shards = await self.client.config.shards.find().to_list()
703+
shards = await async_client_context.client.config.shards.find().to_list()
703704
for shard in shards:
704705
# For a 3-member RS-backed sharded cluster, shard['host']
705706
# will be 'replicaName/ip1:port1,ip2:port2,ip3:port3'
@@ -873,6 +874,16 @@ async def max_message_size_bytes(self):
873874
async_client_context = AsyncClientContext()
874875

875876

877+
async def reset_client_context():
878+
if _IS_SYNC:
879+
# sync tests don't need to reset a client context
880+
return
881+
elif async_client_context.client is not None:
882+
await async_client_context.client.close()
883+
async_client_context.client = None
884+
await async_client_context._init_client()
885+
886+
876887
class AsyncPyMongoTestCasePyTest:
877888
@asynccontextmanager
878889
async def fail_point(self, client, command_args):
@@ -1165,6 +1176,8 @@ class AsyncIntegrationTest(AsyncPyMongoTestCase):
11651176

11661177
@async_client_context.require_connection
11671178
async def asyncSetUp(self) -> None:
1179+
if not _IS_SYNC:
1180+
await reset_client_context()
11681181
if async_client_context.load_balancer and not getattr(self, "RUN_ON_LOAD_BALANCER", False):
11691182
raise SkipTest("this test does not support load balancers")
11701183
if async_client_context.serverless and not getattr(self, "RUN_ON_SERVERLESS", False):

0 commit comments

Comments
 (0)