Skip to content

Commit 1671d29

Browse files
committed
refactoring and fixes
1 parent 07542aa commit 1671d29

File tree

3 files changed

+24
-27
lines changed

3 files changed

+24
-27
lines changed

examples/src/multithreading/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
22
# SPDX-License-Identifier: Apache-2.0
33
"""init file for multi-threading examples."""
4+
import time
5+
46
from aws_cryptographic_materialproviders.mpl.references import IKeyring
57
from typing import Dict # noqa pylint: disable=wrong-import-order
68

79
import aws_encryption_sdk
8-
import time
910

1011

1112
def encrypt_and_decrypt_with_keyring(

examples/test/multithreading/test_i_raw_aes_keyring_multithreaded_example.py

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,11 @@
1111
from ...src.multithreading import run_encrypt_and_decrypt_with_keyring_for_duration_seconds
1212
from ...src.multithreading.raw_aes_keyring import create_keyring
1313

14-
import time
15-
1614
pytestmark = [pytest.mark.examples]
1715

1816

19-
def test_encrypt_and_decrypt_with_keyring_multithreaded_helper(n_threads=16, duration=60):
17+
def encrypt_and_decrypt_with_keyring_multithreaded_helper(n_threads=64, duration=60):
2018
"""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)
2419
keyring = create_keyring()
2520
plaintext_data = b"Hello World"
2621
client = aws_encryption_sdk.EncryptionSDKClient(
@@ -36,15 +31,10 @@ def test_encrypt_and_decrypt_with_keyring_multithreaded_helper(n_threads=16, dur
3631

3732
for future in as_completed(thread_futures):
3833
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)
34+
35+
36+
def test_encrypt_and_decrypt_with_keyring_multithreaded(n_threads_list: list = [1, 4, 16, 64], duration_list: list = [2, 10, 60]):
37+
"""Test function for multi-threaded encrypt and decrypt using a keyring for different n_threads and duration."""
38+
for n in n_threads_list:
39+
for d in duration_list:
40+
encrypt_and_decrypt_with_keyring_multithreaded_helper(n_threads=n, duration=d)

examples/test/multithreading/test_i_raw_rsa_keyring_multithreaded_example.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
import aws_encryption_sdk
99
from aws_encryption_sdk import CommitmentPolicy
1010

11-
from ...src.multithreading import encrypt_and_decrypt_with_keyring
11+
from ...src.multithreading import run_encrypt_and_decrypt_with_keyring_for_duration_seconds
1212
from ...src.multithreading.raw_rsa_keyring import create_keyring, generate_rsa_keys
1313

1414
pytestmark = [pytest.mark.examples]
1515

1616

17-
def test_encrypt_and_decrypt_with_keyring(n_threads=10):
18-
"""Test function for multi-threaded encrypt and decrypt using the Raw RSA Keyring example."""
17+
def encrypt_and_decrypt_with_keyring_multithreaded_helper(n_threads=64, duration=60):
18+
"""Helper function for multi-threaded encrypt and decrypt using a keyring for fixed n_threads and duration."""
1919
public_key, private_key = generate_rsa_keys()
2020
keyring = create_keyring(public_key=public_key, private_key=private_key)
2121
plaintext_data = b"Hello World"
@@ -24,12 +24,18 @@ def test_encrypt_and_decrypt_with_keyring(n_threads=10):
2424
)
2525

2626
with ThreadPoolExecutor(max_workers=n_threads) as executor:
27-
thread_futures = {executor.submit(encrypt_and_decrypt_with_keyring,
27+
thread_futures = {executor.submit(run_encrypt_and_decrypt_with_keyring_for_duration_seconds,
2828
plaintext_data=plaintext_data,
2929
keyring=keyring,
30-
client=client): i for i in range(n_threads)}
30+
client=client,
31+
duration=duration): i for i in range(n_threads)}
3132

3233
for future in as_completed(thread_futures):
33-
decrypted_plaintext_data = future.result()
34-
assert decrypted_plaintext_data == plaintext_data, \
35-
"Decrypted plaintext should be identical to the original plaintext. Invalid decryption"
34+
future.result()
35+
36+
37+
def test_encrypt_and_decrypt_with_keyring_multithreaded(n_threads_list: list = [1, 4, 16, 64], duration_list: list = [2, 10, 60]):
38+
"""Test function for multi-threaded encrypt and decrypt using a keyring for different n_threads and duration."""
39+
for n in n_threads_list:
40+
for d in duration_list:
41+
encrypt_and_decrypt_with_keyring_multithreaded_helper(n_threads=n, duration=d)

0 commit comments

Comments
 (0)