Skip to content

Commit f1f8d62

Browse files
committed
Revert all cleanup changes
1 parent 6547c3c commit f1f8d62

File tree

8 files changed

+28
-18
lines changed

8 files changed

+28
-18
lines changed

pymongo/asynchronous/mongo_client.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,8 +1559,6 @@ async def close(self) -> None:
15591559
# Stop the periodic task thread and then send pending killCursor
15601560
# requests before closing the topology.
15611561
self._kill_cursors_executor.close()
1562-
if not _IS_SYNC:
1563-
await self._kill_cursors_executor.join()
15641562
await self._process_kill_cursors()
15651563
await self._topology.close()
15661564
if self._encrypter:

pymongo/asynchronous/monitor.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,6 @@ def gc_safe_close(self) -> None:
191191

192192
async def close(self) -> None:
193193
self.gc_safe_close()
194-
if not _IS_SYNC:
195-
await self._executor.join()
196194
await self._rtt_monitor.close()
197195
# Increment the generation and maybe close the socket. If the executor
198196
# thread has the socket checked out, it will be closed when checked in.
@@ -460,8 +458,6 @@ def __init__(self, topology: Topology, topology_settings: TopologySettings, pool
460458

461459
async def close(self) -> None:
462460
self.gc_safe_close()
463-
if not _IS_SYNC:
464-
await self._executor.join()
465461
# Increment the generation and maybe close the socket. If the executor
466462
# thread has the socket checked out, it will be closed when checked in.
467463
await self._pool.reset()

pymongo/synchronous/mongo_client.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,8 +1553,6 @@ def close(self) -> None:
15531553
# Stop the periodic task thread and then send pending killCursor
15541554
# requests before closing the topology.
15551555
self._kill_cursors_executor.close()
1556-
if not _IS_SYNC:
1557-
self._kill_cursors_executor.join()
15581556
self._process_kill_cursors()
15591557
self._topology.close()
15601558
if self._encrypter:

pymongo/synchronous/monitor.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,6 @@ def gc_safe_close(self) -> None:
191191

192192
def close(self) -> None:
193193
self.gc_safe_close()
194-
if not _IS_SYNC:
195-
self._executor.join()
196194
self._rtt_monitor.close()
197195
# Increment the generation and maybe close the socket. If the executor
198196
# thread has the socket checked out, it will be closed when checked in.
@@ -460,8 +458,6 @@ def __init__(self, topology: Topology, topology_settings: TopologySettings, pool
460458

461459
def close(self) -> None:
462460
self.gc_safe_close()
463-
if not _IS_SYNC:
464-
self._executor.join()
465461
# Increment the generation and maybe close the socket. If the executor
466462
# thread has the socket checked out, it will be closed when checked in.
467463
self._pool.reset()

test/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,16 @@ def max_message_size_bytes(self):
864864
client_context = ClientContext()
865865

866866

867+
def reset_client_context():
868+
if _IS_SYNC:
869+
# sync tests don't need to reset a client context
870+
return
871+
elif client_context.client is not None:
872+
client_context.client.close()
873+
client_context.client = None
874+
client_context._init_client()
875+
876+
867877
class PyMongoTestCase(unittest.TestCase):
868878
def assertEqualCommand(self, expected, actual, msg=None):
869879
self.assertEqual(sanitize_cmd(expected), sanitize_cmd(actual), msg)
@@ -1126,6 +1136,8 @@ class IntegrationTest(PyMongoTestCase):
11261136

11271137
@client_context.require_connection
11281138
def setUp(self) -> None:
1139+
if not _IS_SYNC:
1140+
reset_client_context()
11291141
if client_context.load_balancer and not getattr(self, "RUN_ON_LOAD_BALANCER", False):
11301142
raise SkipTest("this test does not support load balancers")
11311143
if client_context.serverless and not getattr(self, "RUN_ON_SERVERLESS", False):

test/asynchronous/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,16 @@ async def max_message_size_bytes(self):
866866
async_client_context = AsyncClientContext()
867867

868868

869+
async def reset_client_context():
870+
if _IS_SYNC:
871+
# sync tests don't need to reset a client context
872+
return
873+
elif async_client_context.client is not None:
874+
await async_client_context.client.close()
875+
async_client_context.client = None
876+
await async_client_context._init_client()
877+
878+
869879
class AsyncPyMongoTestCase(unittest.IsolatedAsyncioTestCase):
870880
def assertEqualCommand(self, expected, actual, msg=None):
871881
self.assertEqual(sanitize_cmd(expected), sanitize_cmd(actual), msg)
@@ -1144,6 +1154,8 @@ class AsyncIntegrationTest(AsyncPyMongoTestCase):
11441154

11451155
@async_client_context.require_connection
11461156
async def asyncSetUp(self) -> None:
1157+
if not _IS_SYNC:
1158+
await reset_client_context()
11471159
if async_client_context.load_balancer and not getattr(self, "RUN_ON_LOAD_BALANCER", False):
11481160
raise SkipTest("this test does not support load balancers")
11491161
if async_client_context.serverless and not getattr(self, "RUN_ON_SERVERLESS", False):

test/asynchronous/utils_spec_runner.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -647,11 +647,10 @@ async def setup_scenario(self, scenario_def):
647647
async def run_scenario(self, scenario_def, test):
648648
self.maybe_skip_scenario(test)
649649

650-
# Kill all sessions before (sync only) and after each test to prevent an open
650+
# Kill all sessions before and after each test to prevent an open
651651
# transaction (from a test failure) from blocking collection/database
652652
# operations during test set up and tear down.
653-
if _IS_SYNC:
654-
await self.kill_all_sessions()
653+
await self.kill_all_sessions()
655654
self.addAsyncCleanup(self.kill_all_sessions)
656655
await self.setup_scenario(scenario_def)
657656
database_name = self.get_scenario_db_name(scenario_def)

test/utils_spec_runner.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -647,11 +647,10 @@ def setup_scenario(self, scenario_def):
647647
def run_scenario(self, scenario_def, test):
648648
self.maybe_skip_scenario(test)
649649

650-
# Kill all sessions before (sync only) and after each test to prevent an open
650+
# Kill all sessions before and after each test to prevent an open
651651
# transaction (from a test failure) from blocking collection/database
652652
# operations during test set up and tear down.
653-
if _IS_SYNC:
654-
self.kill_all_sessions()
653+
self.kill_all_sessions()
655654
self.addCleanup(self.kill_all_sessions)
656655
self.setup_scenario(scenario_def)
657656
database_name = self.get_scenario_db_name(scenario_def)

0 commit comments

Comments
 (0)