Skip to content

Commit fe6af09

Browse files
committed
chore(multi-threaded examples: Added keyring examples
1 parent fc8fd38 commit fe6af09

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
"""Stub module indicator to make linter configuration simpler."""
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
"""Test suite for the Raw AES keyring example with multi-threading."""
4+
from concurrent.futures import ThreadPoolExecutor, as_completed
5+
import pytest
6+
7+
from ...src.raw_aes_keyring_example import encrypt_and_decrypt_with_keyring
8+
9+
pytestmark = [pytest.mark.examples]
10+
11+
12+
def test_encrypt_and_decrypt_with_keyring(n_threads=10):
13+
"""Test function for multi-threaded encrypt and decrypt using the Raw AES Keyring example."""
14+
with ThreadPoolExecutor(max_workers=n_threads) as executor:
15+
thread_futures = {executor.submit(encrypt_and_decrypt_with_keyring): i for i in range(n_threads)}
16+
17+
for future in as_completed(thread_futures):
18+
thread_id = thread_futures[future]
19+
try:
20+
result = future.result()
21+
print(f"Thread {thread_id} passed with result: {result}")
22+
except Exception as e:
23+
raise e
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
"""Test suite for the Raw RSA keyring example with multi-threading."""
4+
from concurrent.futures import ThreadPoolExecutor, as_completed
5+
import pytest
6+
7+
from ...src.raw_rsa_keyring_example import encrypt_and_decrypt_with_keyring
8+
9+
pytestmark = [pytest.mark.examples]
10+
11+
12+
def test_encrypt_and_decrypt_with_keyring(n_threads=10):
13+
"""Test function for multi-threaded encrypt and decrypt using the Raw RSA Keyring example."""
14+
with ThreadPoolExecutor(max_workers=n_threads) as executor:
15+
thread_futures = {executor.submit(encrypt_and_decrypt_with_keyring): i for i in range(n_threads)}
16+
17+
for future in as_completed(thread_futures):
18+
thread_id = thread_futures[future]
19+
try:
20+
result = future.result()
21+
print(f"Thread {thread_id} passed with result: {result}")
22+
except Exception as e:
23+
raise e

0 commit comments

Comments
 (0)