|
22 | 22 | import socket
|
23 | 23 | import subprocess
|
24 | 24 | import sys
|
| 25 | +import threading |
25 | 26 | import time
|
26 | 27 | import unittest
|
27 | 28 | import warnings
|
@@ -113,7 +114,7 @@ def __init__(self):
|
113 | 114 | self.default_client_options: Dict = {}
|
114 | 115 | self.sessions_enabled = False
|
115 | 116 | self.client = None # type: ignore
|
116 |
| - self.conn_lock = _async_create_lock() |
| 117 | + self.conn_lock = threading.Lock() |
117 | 118 | self.is_data_lake = False
|
118 | 119 | self.load_balancer = TEST_LOADBALANCER
|
119 | 120 | self.serverless = TEST_SERVERLESS
|
@@ -334,7 +335,7 @@ async def _init_client(self):
|
334 | 335 | await mongos_client.close()
|
335 | 336 |
|
336 | 337 | async def init(self):
|
337 |
| - async with self.conn_lock: |
| 338 | + with self.conn_lock: |
338 | 339 | if not self.client and not self.connection_attempts:
|
339 | 340 | await self._init_client()
|
340 | 341 |
|
@@ -699,7 +700,7 @@ async def is_topology_type(self, topologies):
|
699 | 700 | if "sharded" in topologies and self.is_mongos:
|
700 | 701 | return True
|
701 | 702 | 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() |
703 | 704 | for shard in shards:
|
704 | 705 | # For a 3-member RS-backed sharded cluster, shard['host']
|
705 | 706 | # will be 'replicaName/ip1:port1,ip2:port2,ip3:port3'
|
@@ -873,6 +874,16 @@ async def max_message_size_bytes(self):
|
873 | 874 | async_client_context = AsyncClientContext()
|
874 | 875 |
|
875 | 876 |
|
| 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 | + |
876 | 887 | class AsyncPyMongoTestCasePyTest:
|
877 | 888 | @asynccontextmanager
|
878 | 889 | async def fail_point(self, client, command_args):
|
@@ -1165,6 +1176,8 @@ class AsyncIntegrationTest(AsyncPyMongoTestCase):
|
1165 | 1176 |
|
1166 | 1177 | @async_client_context.require_connection
|
1167 | 1178 | async def asyncSetUp(self) -> None:
|
| 1179 | + if not _IS_SYNC: |
| 1180 | + await reset_client_context() |
1168 | 1181 | if async_client_context.load_balancer and not getattr(self, "RUN_ON_LOAD_BALANCER", False):
|
1169 | 1182 | raise SkipTest("this test does not support load balancers")
|
1170 | 1183 | if async_client_context.serverless and not getattr(self, "RUN_ON_SERVERLESS", False):
|
|
0 commit comments