Skip to content

Commit 8f6d738

Browse files
committed
Fix async client unified closing
1 parent de90b45 commit 8f6d738

File tree

6 files changed

+10
-26
lines changed

6 files changed

+10
-26
lines changed

test/asynchronous/test_encryption.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,7 +1495,6 @@ async def _test_explicit(self, expectation):
14951495
async_client_context.client,
14961496
OPTS,
14971497
)
1498-
self.addAsyncCleanup(client_encryption.close)
14991498

15001499
ciphertext = await client_encryption.encrypt(
15011500
"string0",
@@ -1521,7 +1520,6 @@ async def _test_automatic(self, expectation_extjson, payload):
15211520
client = await self.async_rs_or_single_client(
15221521
auto_encryption_opts=encryption_opts, event_listeners=[insert_listener]
15231522
)
1524-
self.addAsyncCleanup(client.aclose)
15251523

15261524
coll = client.get_database(encrypted_db).get_collection(
15271525
encrypted_coll, codec_options=OPTS, write_concern=WriteConcern("majority")
@@ -1545,10 +1543,10 @@ async def _test_automatic(self, expectation_extjson, payload):
15451543
class TestAzureEncryption(AzureGCPEncryptionTestMixin, AsyncEncryptionIntegrationTest):
15461544
@unittest.skipUnless(any(AZURE_CREDS.values()), "Azure environment credentials are not set")
15471545
async def asyncSetUp(self):
1546+
await super().asyncSetUp()
15481547
self.KMS_PROVIDER_MAP = {"azure": AZURE_CREDS}
15491548
self.DEK = json_data(BASE, "custom", "azure-dek.json")
15501549
self.SCHEMA_MAP = json_data(BASE, "custom", "azure-gcp-schema.json")
1551-
await super().asyncSetUp()
15521550

15531551
async def test_explicit(self):
15541552
return await self._test_explicit(
@@ -1570,10 +1568,10 @@ async def test_automatic(self):
15701568
class TestGCPEncryption(AzureGCPEncryptionTestMixin, AsyncEncryptionIntegrationTest):
15711569
@unittest.skipUnless(any(GCP_CREDS.values()), "GCP environment credentials are not set")
15721570
async def asyncSetUp(self):
1571+
await super().asyncSetUp()
15731572
self.KMS_PROVIDER_MAP = {"gcp": GCP_CREDS}
15741573
self.DEK = json_data(BASE, "custom", "gcp-dek.json")
15751574
self.SCHEMA_MAP = json_data(BASE, "custom", "azure-gcp-schema.json")
1576-
await super().asyncSetUp()
15771575

15781576
async def test_explicit(self):
15791577
return await self._test_explicit(
@@ -1595,6 +1593,7 @@ async def test_automatic(self):
15951593
# https://github.com/mongodb/specifications/blob/master/source/client-side-encryption/tests/README.md#deadlock-tests
15961594
class TestDeadlockProse(AsyncEncryptionIntegrationTest):
15971595
async def asyncSetUp(self):
1596+
await super().asyncSetUp()
15981597
self.client_test = await self.async_rs_or_single_client(
15991598
maxPoolSize=1, readConcernLevel="majority", w="majority", uuidRepresentation="standard"
16001599
)
@@ -1627,7 +1626,6 @@ async def asyncSetUp(self):
16271626
self.ciphertext = await client_encryption.encrypt(
16281627
"string0", Algorithm.AEAD_AES_256_CBC_HMAC_SHA_512_Deterministic, key_alt_name="local"
16291628
)
1630-
await client_encryption.close()
16311629

16321630
self.client_listener = OvertCommandListener()
16331631
self.topology_listener = TopologyEventListener()
@@ -1822,6 +1820,7 @@ async def test_case_8(self):
18221820
# https://github.com/mongodb/specifications/blob/master/source/client-side-encryption/tests/README.md#14-decryption-events
18231821
class TestDecryptProse(AsyncEncryptionIntegrationTest):
18241822
async def asyncSetUp(self):
1823+
await super().asyncSetUp()
18251824
self.client = async_client_context.client
18261825
await self.client.db.drop_collection("decryption_events")
18271826
await create_key_vault(self.client.keyvault.datakeys)
@@ -2257,6 +2256,7 @@ async def test_06_named_kms_providers_apply_tls_options_kmip(self):
22572256
# https://github.com/mongodb/specifications/blob/50e26fe/source/client-side-encryption/tests/README.md#unique-index-on-keyaltnames
22582257
class TestUniqueIndexOnKeyAltNamesProse(AsyncEncryptionIntegrationTest):
22592258
async def asyncSetUp(self):
2259+
await super().asyncSetUp()
22602260
self.client = async_client_context.client
22612261
await create_key_vault(self.client.keyvault.datakeys)
22622262
kms_providers_map = {"local": {"key": LOCAL_MASTER_KEY}}
@@ -2606,8 +2606,6 @@ async def AsyncMongoClient(**kwargs):
26062606
assert isinstance(res["encrypted_indexed"], Binary)
26072607
assert isinstance(res["encrypted_unindexed"], Binary)
26082608

2609-
await client_encryption.close()
2610-
26112609

26122610
# https://github.com/mongodb/specifications/blob/master/source/client-side-encryption/tests/README.md#22-range-explicit-encryption
26132611
class TestRangeQueryProse(AsyncEncryptionIntegrationTest):

test/asynchronous/unified_format.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -499,10 +499,6 @@ async def asyncSetUp(self):
499499
# process file-level runOnRequirements
500500
run_on_spec = self.TEST_SPEC.get("runOnRequirements", [])
501501
if not await self.should_run_on(run_on_spec):
502-
# Explicitly close async clients here
503-
# to prevent leaky monitor tasks
504-
if not _IS_SYNC:
505-
await async_client_context.client.close()
506502
raise unittest.SkipTest(f"{self.__class__.__name__} runOnRequirements not satisfied")
507503

508504
# add any special-casing for skipping tests here

test/asynchronous/utils_spec_runner.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,8 +692,6 @@ async def run_scenario(self, scenario_def, test):
692692
self.listener = listener
693693
self.pool_listener = pool_listener
694694
self.server_listener = server_listener
695-
# Close the client explicitly to avoid having too many threads open.
696-
self.addAsyncCleanup(client.close)
697695

698696
# Create session0 and session1.
699697
sessions = {}

test/test_encryption.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,7 +1489,6 @@ def _test_explicit(self, expectation):
14891489
client_context.client,
14901490
OPTS,
14911491
)
1492-
self.addCleanup(client_encryption.close)
14931492

14941493
ciphertext = client_encryption.encrypt(
14951494
"string0",
@@ -1515,7 +1514,6 @@ def _test_automatic(self, expectation_extjson, payload):
15151514
client = self.rs_or_single_client(
15161515
auto_encryption_opts=encryption_opts, event_listeners=[insert_listener]
15171516
)
1518-
self.addCleanup(client.close)
15191517

15201518
coll = client.get_database(encrypted_db).get_collection(
15211519
encrypted_coll, codec_options=OPTS, write_concern=WriteConcern("majority")
@@ -1539,10 +1537,10 @@ def _test_automatic(self, expectation_extjson, payload):
15391537
class TestAzureEncryption(AzureGCPEncryptionTestMixin, EncryptionIntegrationTest):
15401538
@unittest.skipUnless(any(AZURE_CREDS.values()), "Azure environment credentials are not set")
15411539
def setUp(self):
1540+
super().setUp()
15421541
self.KMS_PROVIDER_MAP = {"azure": AZURE_CREDS}
15431542
self.DEK = json_data(BASE, "custom", "azure-dek.json")
15441543
self.SCHEMA_MAP = json_data(BASE, "custom", "azure-gcp-schema.json")
1545-
super().setUp()
15461544

15471545
def test_explicit(self):
15481546
return self._test_explicit(
@@ -1564,10 +1562,10 @@ def test_automatic(self):
15641562
class TestGCPEncryption(AzureGCPEncryptionTestMixin, EncryptionIntegrationTest):
15651563
@unittest.skipUnless(any(GCP_CREDS.values()), "GCP environment credentials are not set")
15661564
def setUp(self):
1565+
super().setUp()
15671566
self.KMS_PROVIDER_MAP = {"gcp": GCP_CREDS}
15681567
self.DEK = json_data(BASE, "custom", "gcp-dek.json")
15691568
self.SCHEMA_MAP = json_data(BASE, "custom", "azure-gcp-schema.json")
1570-
super().setUp()
15711569

15721570
def test_explicit(self):
15731571
return self._test_explicit(
@@ -1589,6 +1587,7 @@ def test_automatic(self):
15891587
# https://github.com/mongodb/specifications/blob/master/source/client-side-encryption/tests/README.md#deadlock-tests
15901588
class TestDeadlockProse(EncryptionIntegrationTest):
15911589
def setUp(self):
1590+
super().setUp()
15921591
self.client_test = self.rs_or_single_client(
15931592
maxPoolSize=1, readConcernLevel="majority", w="majority", uuidRepresentation="standard"
15941593
)
@@ -1619,7 +1618,6 @@ def setUp(self):
16191618
self.ciphertext = client_encryption.encrypt(
16201619
"string0", Algorithm.AEAD_AES_256_CBC_HMAC_SHA_512_Deterministic, key_alt_name="local"
16211620
)
1622-
client_encryption.close()
16231621

16241622
self.client_listener = OvertCommandListener()
16251623
self.topology_listener = TopologyEventListener()
@@ -1814,6 +1812,7 @@ def test_case_8(self):
18141812
# https://github.com/mongodb/specifications/blob/master/source/client-side-encryption/tests/README.md#14-decryption-events
18151813
class TestDecryptProse(EncryptionIntegrationTest):
18161814
def setUp(self):
1815+
super().setUp()
18171816
self.client = client_context.client
18181817
self.client.db.drop_collection("decryption_events")
18191818
create_key_vault(self.client.keyvault.datakeys)
@@ -2249,6 +2248,7 @@ def test_06_named_kms_providers_apply_tls_options_kmip(self):
22492248
# https://github.com/mongodb/specifications/blob/50e26fe/source/client-side-encryption/tests/README.md#unique-index-on-keyaltnames
22502249
class TestUniqueIndexOnKeyAltNamesProse(EncryptionIntegrationTest):
22512250
def setUp(self):
2251+
super().setUp()
22522252
self.client = client_context.client
22532253
create_key_vault(self.client.keyvault.datakeys)
22542254
kms_providers_map = {"local": {"key": LOCAL_MASTER_KEY}}
@@ -2590,8 +2590,6 @@ def MongoClient(**kwargs):
25902590
assert isinstance(res["encrypted_indexed"], Binary)
25912591
assert isinstance(res["encrypted_unindexed"], Binary)
25922592

2593-
client_encryption.close()
2594-
25952593

25962594
# https://github.com/mongodb/specifications/blob/master/source/client-side-encryption/tests/README.md#22-range-explicit-encryption
25972595
class TestRangeQueryProse(EncryptionIntegrationTest):

test/unified_format.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -498,10 +498,6 @@ def setUp(self):
498498
# process file-level runOnRequirements
499499
run_on_spec = self.TEST_SPEC.get("runOnRequirements", [])
500500
if not self.should_run_on(run_on_spec):
501-
# Explicitly close async clients here
502-
# to prevent leaky monitor tasks
503-
if not _IS_SYNC:
504-
client_context.client.close()
505501
raise unittest.SkipTest(f"{self.__class__.__name__} runOnRequirements not satisfied")
506502

507503
# add any special-casing for skipping tests here

test/utils_spec_runner.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -689,8 +689,6 @@ def run_scenario(self, scenario_def, test):
689689
self.listener = listener
690690
self.pool_listener = pool_listener
691691
self.server_listener = server_listener
692-
# Close the client explicitly to avoid having too many threads open.
693-
self.addCleanup(client.close)
694692

695693
# Create session0 and session1.
696694
sessions = {}

0 commit comments

Comments
 (0)