Skip to content

Commit 619a2ce

Browse files
committed
Fix batch bulk tests
1 parent 8f6d738 commit 619a2ce

File tree

3 files changed

+23
-15
lines changed

3 files changed

+23
-15
lines changed

.evergreen/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ functions:
281281
"run tests":
282282
- command: subprocess.exec
283283
params:
284-
include_expansions_in_env: ["TEST_DATA_LAKE", "AUTH", "SSL", "TEST_INDEX_MANAGEMENT", "CRYPT_SHARED_LIB_PATH", "test_encryption", "test_encryption_pyopenssl", "test_crypt_shared", "test_pyopenssl", "test_loadbalancer", "test_serverless", "ORCHESTRATION_FILE"]
284+
include_expansions_in_env: ["TEST_DATA_LAKE", "PYTHON_BINARY", "AUTH", "SSL", "TEST_INDEX_MANAGEMENT", "CRYPT_SHARED_LIB_PATH", "test_encryption", "test_encryption_pyopenssl", "test_crypt_shared", "test_pyopenssl", "test_loadbalancer", "test_serverless", "ORCHESTRATION_FILE"]
285285
binary: bash
286286
working_dir: "src"
287287
args:

test/asynchronous/test_encryption.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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,13 +1486,12 @@ class AzureGCPEncryptionTestMixin(AsyncEncryptionIntegrationTest):
14821486
KEYVAULT_COLL = "datakeys"
14831487
client: AsyncMongoClient
14841488

1485-
async def asyncSetUp(self):
1486-
await super().asyncSetUp()
1487-
self.client = self.simple_client()
1489+
async def _setup(self):
14881490
keyvault = self.client.get_database(self.KEYVAULT_DB).get_collection(self.KEYVAULT_COLL)
14891491
await create_key_vault(keyvault, self.DEK)
14901492

14911493
async def _test_explicit(self, expectation):
1494+
await self._setup()
14921495
client_encryption = self.create_client_encryption(
14931496
self.KMS_PROVIDER_MAP, # type: ignore[arg-type]
14941497
".".join([self.KEYVAULT_DB, self.KEYVAULT_COLL]),
@@ -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])
@@ -1543,10 +1547,10 @@ async def _test_automatic(self, expectation_extjson, payload):
15431547
class TestAzureEncryption(AzureGCPEncryptionTestMixin, AsyncEncryptionIntegrationTest):
15441548
@unittest.skipUnless(any(AZURE_CREDS.values()), "Azure environment credentials are not set")
15451549
async def asyncSetUp(self):
1546-
await super().asyncSetUp()
15471550
self.KMS_PROVIDER_MAP = {"azure": AZURE_CREDS}
15481551
self.DEK = json_data(BASE, "custom", "azure-dek.json")
15491552
self.SCHEMA_MAP = json_data(BASE, "custom", "azure-gcp-schema.json")
1553+
await super().asyncSetUp()
15501554

15511555
async def test_explicit(self):
15521556
return await self._test_explicit(
@@ -1568,10 +1572,10 @@ async def test_automatic(self):
15681572
class TestGCPEncryption(AzureGCPEncryptionTestMixin, AsyncEncryptionIntegrationTest):
15691573
@unittest.skipUnless(any(GCP_CREDS.values()), "GCP environment credentials are not set")
15701574
async def asyncSetUp(self):
1571-
await super().asyncSetUp()
15721575
self.KMS_PROVIDER_MAP = {"gcp": GCP_CREDS}
15731576
self.DEK = json_data(BASE, "custom", "gcp-dek.json")
15741577
self.SCHEMA_MAP = json_data(BASE, "custom", "azure-gcp-schema.json")
1578+
await super().asyncSetUp()
15751579

15761580
async def test_explicit(self):
15771581
return await self._test_explicit(

test/test_encryption.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,9 @@ def test_03_bulk_batch_split(self):
12301230
doc2 = {"_id": "over_2mib_2", "unencrypted": "a" * _2_MiB}
12311231
self.listener.reset()
12321232
self.coll_encrypted.bulk_write([InsertOne(doc1), InsertOne(doc2)])
1233-
self.assertEqual(self.listener.started_command_names(), ["insert", "insert"])
1233+
self.assertEqual(
1234+
len([c for c in self.listener.started_command_names() if c == "insert"]), 2
1235+
)
12341236

12351237
def test_04_bulk_batch_split(self):
12361238
limits_doc = json_data("limits", "limits-doc.json")
@@ -1240,7 +1242,9 @@ def test_04_bulk_batch_split(self):
12401242
doc2.update(limits_doc)
12411243
self.listener.reset()
12421244
self.coll_encrypted.bulk_write([InsertOne(doc1), InsertOne(doc2)])
1243-
self.assertEqual(self.listener.started_command_names(), ["insert", "insert"])
1245+
self.assertEqual(
1246+
len([c for c in self.listener.started_command_names() if c == "insert"]), 2
1247+
)
12441248

12451249
def test_05_insert_succeeds_just_under_16MiB(self):
12461250
doc = {"_id": "under_16mib", "unencrypted": "a" * (_16_MiB - 2000)}
@@ -1476,13 +1480,12 @@ class AzureGCPEncryptionTestMixin(EncryptionIntegrationTest):
14761480
KEYVAULT_COLL = "datakeys"
14771481
client: MongoClient
14781482

1479-
def setUp(self):
1480-
super().setUp()
1481-
self.client = self.simple_client()
1483+
def _setup(self):
14821484
keyvault = self.client.get_database(self.KEYVAULT_DB).get_collection(self.KEYVAULT_COLL)
14831485
create_key_vault(keyvault, self.DEK)
14841486

14851487
def _test_explicit(self, expectation):
1488+
self._setup()
14861489
client_encryption = self.create_client_encryption(
14871490
self.KMS_PROVIDER_MAP, # type: ignore[arg-type]
14881491
".".join([self.KEYVAULT_DB, self.KEYVAULT_COLL]),
@@ -1500,6 +1503,7 @@ def _test_explicit(self, expectation):
15001503
self.assertEqual(client_encryption.decrypt(ciphertext), "string0")
15011504

15021505
def _test_automatic(self, expectation_extjson, payload):
1506+
self._setup()
15031507
encrypted_db = "db"
15041508
encrypted_coll = "coll"
15051509
keyvault_namespace = ".".join([self.KEYVAULT_DB, self.KEYVAULT_COLL])
@@ -1537,10 +1541,10 @@ def _test_automatic(self, expectation_extjson, payload):
15371541
class TestAzureEncryption(AzureGCPEncryptionTestMixin, EncryptionIntegrationTest):
15381542
@unittest.skipUnless(any(AZURE_CREDS.values()), "Azure environment credentials are not set")
15391543
def setUp(self):
1540-
super().setUp()
15411544
self.KMS_PROVIDER_MAP = {"azure": AZURE_CREDS}
15421545
self.DEK = json_data(BASE, "custom", "azure-dek.json")
15431546
self.SCHEMA_MAP = json_data(BASE, "custom", "azure-gcp-schema.json")
1547+
super().setUp()
15441548

15451549
def test_explicit(self):
15461550
return self._test_explicit(
@@ -1562,10 +1566,10 @@ def test_automatic(self):
15621566
class TestGCPEncryption(AzureGCPEncryptionTestMixin, EncryptionIntegrationTest):
15631567
@unittest.skipUnless(any(GCP_CREDS.values()), "GCP environment credentials are not set")
15641568
def setUp(self):
1565-
super().setUp()
15661569
self.KMS_PROVIDER_MAP = {"gcp": GCP_CREDS}
15671570
self.DEK = json_data(BASE, "custom", "gcp-dek.json")
15681571
self.SCHEMA_MAP = json_data(BASE, "custom", "azure-gcp-schema.json")
1572+
super().setUp()
15691573

15701574
def test_explicit(self):
15711575
return self._test_explicit(

0 commit comments

Comments
 (0)