PYTHON-3390 Test for encrypted client post-fork (#1037)

This commit is contained in:
Ben Warner 2022-08-15 12:07:49 -07:00 committed by GitHub
parent c0dadcb6ca
commit a20ff68d51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 3 deletions

View File

@ -329,6 +329,25 @@ class TestClientSimple(EncryptionIntegrationTest):
with self.assertRaisesRegex(InvalidOperation, "Cannot use MongoClient after close"):
client.admin.command("ping")
# Not available for versions of Python without "register_at_fork"
@unittest.skipIf(
not hasattr(os, "register_at_fork"),
"register_at_fork not available in this version of Python",
)
def test_fork(self):
opts = AutoEncryptionOpts(KMS_PROVIDERS, "keyvault.datakeys")
client = rs_or_single_client(auto_encryption_opts=opts)
lock_pid = os.fork()
if lock_pid == 0:
client.admin.command("ping")
client.close()
os._exit(0)
else:
self.assertEqual(0, os.waitpid(lock_pid, 0)[1])
client.admin.command("ping")
client.close()
class TestEncryptedBulkWrite(BulkTestBase, EncryptionIntegrationTest):
def test_upsert_uuid_standard_encrypt(self):

View File

@ -53,7 +53,7 @@ class TestFork(IntegrationTest):
if lock_pid == 0:
os._exit(exit_cond())
else:
self.assertEqual(0, os.waitpid(lock_pid, 0)[1] >> 8)
self.assertEqual(0, os.waitpid(lock_pid, 0)[1])
def test_lock_object_id(self):
"""
@ -67,7 +67,7 @@ class TestFork(IntegrationTest):
if lock_pid == 0:
os._exit(int(ObjectId._inc_lock.locked()))
else:
self.assertEqual(0, os.waitpid(lock_pid, 0)[1] >> 8)
self.assertEqual(0, os.waitpid(lock_pid, 0)[1])
def test_topology_reset(self):
"""
@ -92,7 +92,7 @@ class TestFork(IntegrationTest):
)
os._exit(0)
else: # Parent
self.assertEqual(0, os.waitpid(lock_pid, 0)[1] >> 8)
self.assertEqual(0, os.waitpid(lock_pid, 0)[1])
self.assertEqual(self.client._topology._pid, init_id)
child_id = parent_conn.recv()
self.assertNotEqual(child_id, init_id)