@@ -1234,7 +1234,9 @@ async def test_03_bulk_batch_split(self):
12341234 doc2 = {"_id" : "over_2mib_2" , "unencrypted" : "a" * _2_MiB }
12351235 self .listener .reset ()
12361236 await self .coll_encrypted .bulk_write ([InsertOne (doc1 ), InsertOne (doc2 )])
1237- self .assertEqual (self .listener .started_command_names (), ["insert" , "insert" ])
1237+ self .assertEqual (
1238+ len ([c for c in self .listener .started_command_names () if c == "insert" ]), 2
1239+ )
12381240
12391241 async def test_04_bulk_batch_split (self ):
12401242 limits_doc = json_data ("limits" , "limits-doc.json" )
@@ -1244,7 +1246,9 @@ async def test_04_bulk_batch_split(self):
12441246 doc2 .update (limits_doc )
12451247 self .listener .reset ()
12461248 await self .coll_encrypted .bulk_write ([InsertOne (doc1 ), InsertOne (doc2 )])
1247- self .assertEqual (self .listener .started_command_names (), ["insert" , "insert" ])
1249+ self .assertEqual (
1250+ len ([c for c in self .listener .started_command_names () if c == "insert" ]), 2
1251+ )
12481252
12491253 async def test_05_insert_succeeds_just_under_16MiB (self ):
12501254 doc = {"_id" : "under_16mib" , "unencrypted" : "a" * (_16_MiB - 2000 )}
@@ -1482,19 +1486,18 @@ class AzureGCPEncryptionTestMixin(AsyncEncryptionIntegrationTest):
14821486 KEYVAULT_COLL = "datakeys"
14831487 client : AsyncMongoClient
14841488
1485- async def asyncSetUp (self ):
1486- self .client = self .simple_client ()
1489+ async def _setup (self ):
14871490 keyvault = self .client .get_database (self .KEYVAULT_DB ).get_collection (self .KEYVAULT_COLL )
14881491 await create_key_vault (keyvault , self .DEK )
14891492
14901493 async def _test_explicit (self , expectation ):
1494+ await self ._setup ()
14911495 client_encryption = self .create_client_encryption (
14921496 self .KMS_PROVIDER_MAP , # type: ignore[arg-type]
14931497 "." .join ([self .KEYVAULT_DB , self .KEYVAULT_COLL ]),
14941498 async_client_context .client ,
14951499 OPTS ,
14961500 )
1497- self .addAsyncCleanup (client_encryption .close )
14981501
14991502 ciphertext = await client_encryption .encrypt (
15001503 "string0" ,
@@ -1506,6 +1509,7 @@ async def _test_explicit(self, expectation):
15061509 self .assertEqual (await client_encryption .decrypt (ciphertext ), "string0" )
15071510
15081511 async def _test_automatic (self , expectation_extjson , payload ):
1512+ await self ._setup ()
15091513 encrypted_db = "db"
15101514 encrypted_coll = "coll"
15111515 keyvault_namespace = "." .join ([self .KEYVAULT_DB , self .KEYVAULT_COLL ])
@@ -1520,7 +1524,6 @@ async def _test_automatic(self, expectation_extjson, payload):
15201524 client = await self .async_rs_or_single_client (
15211525 auto_encryption_opts = encryption_opts , event_listeners = [insert_listener ]
15221526 )
1523- self .addAsyncCleanup (client .aclose )
15241527
15251528 coll = client .get_database (encrypted_db ).get_collection (
15261529 encrypted_coll , codec_options = OPTS , write_concern = WriteConcern ("majority" )
@@ -1594,6 +1597,7 @@ async def test_automatic(self):
15941597# https://github.com/mongodb/specifications/blob/master/source/client-side-encryption/tests/README.md#deadlock-tests
15951598class TestDeadlockProse (AsyncEncryptionIntegrationTest ):
15961599 async def asyncSetUp (self ):
1600+ await super ().asyncSetUp ()
15971601 self .client_test = await self .async_rs_or_single_client (
15981602 maxPoolSize = 1 , readConcernLevel = "majority" , w = "majority" , uuidRepresentation = "standard"
15991603 )
@@ -1626,7 +1630,6 @@ async def asyncSetUp(self):
16261630 self .ciphertext = await client_encryption .encrypt (
16271631 "string0" , Algorithm .AEAD_AES_256_CBC_HMAC_SHA_512_Deterministic , key_alt_name = "local"
16281632 )
1629- await client_encryption .close ()
16301633
16311634 self .client_listener = OvertCommandListener ()
16321635 self .topology_listener = TopologyEventListener ()
@@ -1821,6 +1824,7 @@ async def test_case_8(self):
18211824# https://github.com/mongodb/specifications/blob/master/source/client-side-encryption/tests/README.md#14-decryption-events
18221825class TestDecryptProse (AsyncEncryptionIntegrationTest ):
18231826 async def asyncSetUp (self ):
1827+ await super ().asyncSetUp ()
18241828 self .client = async_client_context .client
18251829 await self .client .db .drop_collection ("decryption_events" )
18261830 await create_key_vault (self .client .keyvault .datakeys )
@@ -2256,6 +2260,7 @@ async def test_06_named_kms_providers_apply_tls_options_kmip(self):
22562260# https://github.com/mongodb/specifications/blob/50e26fe/source/client-side-encryption/tests/README.md#unique-index-on-keyaltnames
22572261class TestUniqueIndexOnKeyAltNamesProse (AsyncEncryptionIntegrationTest ):
22582262 async def asyncSetUp (self ):
2263+ await super ().asyncSetUp ()
22592264 self .client = async_client_context .client
22602265 await create_key_vault (self .client .keyvault .datakeys )
22612266 kms_providers_map = {"local" : {"key" : LOCAL_MASTER_KEY }}
@@ -2605,8 +2610,6 @@ async def AsyncMongoClient(**kwargs):
26052610 assert isinstance (res ["encrypted_indexed" ], Binary )
26062611 assert isinstance (res ["encrypted_unindexed" ], Binary )
26072612
2608- await client_encryption .close ()
2609-
26102613
26112614# https://github.com/mongodb/specifications/blob/master/source/client-side-encryption/tests/README.md#22-range-explicit-encryption
26122615class TestRangeQueryProse (AsyncEncryptionIntegrationTest ):
0 commit comments