|
8 | 8 | import aws_encryption_sdk
|
9 | 9 | from aws_encryption_sdk import CommitmentPolicy
|
10 | 10 |
|
11 |
| -from ...src.multithreading import encrypt_and_decrypt_with_keyring |
| 11 | +from ...src.multithreading import run_encrypt_and_decrypt_with_keyring_for_duration_seconds |
12 | 12 | from ...src.multithreading.raw_aes_keyring import create_keyring
|
13 | 13 |
|
| 14 | +import time |
| 15 | + |
14 | 16 | pytestmark = [pytest.mark.examples]
|
15 | 17 |
|
16 | 18 |
|
17 |
| -def test_encrypt_and_decrypt_with_keyring(n_threads=10): |
18 |
| - """Test function for multi-threaded encrypt and decrypt using the Raw AES Keyring example.""" |
| 19 | +def test_encrypt_and_decrypt_with_keyring_multithreaded_helper(n_threads=16, duration=60): |
| 20 | + """Helper function for multi-threaded encrypt and decrypt using a keyring for fixed n_threads and duration.""" |
| 21 | + print(n_threads, duration) |
| 22 | + start_time = time.time() |
| 23 | + print('start_time', start_time) |
19 | 24 | keyring = create_keyring()
|
20 | 25 | plaintext_data = b"Hello World"
|
21 | 26 | client = aws_encryption_sdk.EncryptionSDKClient(
|
22 | 27 | commitment_policy=CommitmentPolicy.REQUIRE_ENCRYPT_REQUIRE_DECRYPT
|
23 | 28 | )
|
24 | 29 |
|
25 | 30 | with ThreadPoolExecutor(max_workers=n_threads) as executor:
|
26 |
| - thread_futures = {executor.submit(encrypt_and_decrypt_with_keyring, |
| 31 | + thread_futures = {executor.submit(run_encrypt_and_decrypt_with_keyring_for_duration_seconds, |
27 | 32 | plaintext_data=plaintext_data,
|
28 | 33 | keyring=keyring,
|
29 |
| - client=client): i for i in range(n_threads)} |
| 34 | + client=client, |
| 35 | + duration=duration): i for i in range(n_threads)} |
30 | 36 |
|
31 | 37 | for future in as_completed(thread_futures):
|
32 |
| - decrypted_plaintext_data = future.result() |
33 |
| - assert decrypted_plaintext_data == plaintext_data, \ |
34 |
| - "Decrypted plaintext should be identical to the original plaintext. Invalid decryption" |
| 38 | + future.result() |
| 39 | + end_time = time.time() |
| 40 | + print('end_time', end_time) |
| 41 | + print('duration', end_time - start_time) |
| 42 | + |
| 43 | + |
| 44 | +# def test_encrypt_and_decrypt_with_keyring_multithreaded(n_threads_list: list = [4, 16, 64], duration_list: list = [2, 10, 60]): |
| 45 | +# """Test function for multi-threaded encrypt and decrypt using a keyring for different n_threads and duration.""" |
| 46 | +# print('hello', n_threads_list, duration_list) |
| 47 | +# for n in n_threads_list: |
| 48 | +# for d in duration_list: |
| 49 | +# print(n, d, time.time()) |
| 50 | +# encrypt_and_decrypt_with_keyring_helper(n_threads=n, duration=d) |
0 commit comments