Skip to content

Commit f303125

Browse files
authored
PYTHON-5114 Test suite reduce killAllSessions calls (#2721)
1 parent 38da6c3 commit f303125

2 files changed

Lines changed: 18 additions & 10 deletions

File tree

test/asynchronous/unified_format.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,11 +1464,6 @@ async def verify_outcome(self, spec):
14641464
self.assertListEqual(sorted_expected_documents, actual_documents)
14651465

14661466
async def run_scenario(self, spec, uri=None):
1467-
# Kill all sessions before and after each test to prevent an open
1468-
# transaction (from a test failure) from blocking collection/database
1469-
# operations during test set up and tear down.
1470-
await self.kill_all_sessions()
1471-
14721467
# Handle flaky tests.
14731468
flaky_tests = [
14741469
("PYTHON-5170", ".*test_discovery_and_monitoring.*"),
@@ -1504,6 +1499,15 @@ async def _run_scenario(self, spec, uri=None):
15041499
if skip_reason is not None:
15051500
raise unittest.SkipTest(f"{skip_reason}")
15061501

1502+
# Kill all sessions after each test with transactions to prevent an open
1503+
# transaction (from a test failure) from blocking collection/database
1504+
# operations during test set up and tear down.
1505+
for op in spec["operations"]:
1506+
name = op["name"]
1507+
if name == "startTransaction" or name == "withTransaction":
1508+
self.addAsyncCleanup(self.kill_all_sessions)
1509+
break
1510+
15071511
# process createEntities
15081512
self._uri = uri
15091513
self.entity_map = EntityMapUtil(self)

test/unified_format.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,11 +1451,6 @@ def verify_outcome(self, spec):
14511451
self.assertListEqual(sorted_expected_documents, actual_documents)
14521452

14531453
def run_scenario(self, spec, uri=None):
1454-
# Kill all sessions before and after each test to prevent an open
1455-
# transaction (from a test failure) from blocking collection/database
1456-
# operations during test set up and tear down.
1457-
self.kill_all_sessions()
1458-
14591454
# Handle flaky tests.
14601455
flaky_tests = [
14611456
("PYTHON-5170", ".*test_discovery_and_monitoring.*"),
@@ -1491,6 +1486,15 @@ def _run_scenario(self, spec, uri=None):
14911486
if skip_reason is not None:
14921487
raise unittest.SkipTest(f"{skip_reason}")
14931488

1489+
# Kill all sessions after each test with transactions to prevent an open
1490+
# transaction (from a test failure) from blocking collection/database
1491+
# operations during test set up and tear down.
1492+
for op in spec["operations"]:
1493+
name = op["name"]
1494+
if name == "startTransaction" or name == "withTransaction":
1495+
self.addCleanup(self.kill_all_sessions)
1496+
break
1497+
14941498
# process createEntities
14951499
self._uri = uri
14961500
self.entity_map = EntityMapUtil(self)

0 commit comments

Comments
 (0)