Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Hybrid approach to service testing
  • Loading branch information
Bret Ambrose committed May 19, 2025
commit 0613bee86e643fbb878cba09d461aba319777788
19 changes: 14 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,22 +158,31 @@ jobs:
- name: Install AWS SDK for Python
run: |
python3 -m pip install boto3
- name: Checkout Sources
uses: actions/checkout@v2
- name: configure AWS credentials (containers)
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ env.CI_BUILD_AND_TEST_ROLE }}
aws-region: ${{ env.AWS_DEFAULT_REGION }}
- name: Build ${{ env.PACKAGE_NAME }}
run: |
python3 -m pip install .
python -c "from urllib.request import urlretrieve; urlretrieve('${{ env.BUILDER_HOST }}/${{ env.BUILDER_SOURCE }}/${{ env.BUILDER_VERSION }}/builder.pyz?run=${{ env.RUN }}', 'builder.pyz')"
python builder.pyz build -p ${{ env.PACKAGE_NAME }}
- name: configure AWS credentials (MQTT5)
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: ${{ env.CI_MQTT5_ROLE }}
aws-region: ${{ env.AWS_DEFAULT_REGION }}
- name: Local tests
- name: Service tests
shell: bash
run: |
cd aws-iot-device-sdk-python-v2
python3 -m pip install .
source utils/test_setup.sh s3://iot-sdk-ci-bucket-us-east1/IotUsProdMqtt5EnvironmentVariables.txt us-east-1
python3 -m unittest test
python3 -m unittest test.test_shadow
python3 -m unittest test.test_jobs
python3 -m unittest test.test_identity
source utils/test_cleanup.sh
cd ..
- name: configure AWS credentials (PubSub)
uses: aws-actions/configure-aws-credentials@v4
with:
Expand Down
12 changes: 8 additions & 4 deletions test/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import threading

from awscrt import io, mqtt, mqtt5, mqtt_request_response
from awscrt.mqtt_request_response import SubscriptionStatusEvent, SubscriptionStatusEventType

import awsiot
from awsiot import iotjobs

Expand Down Expand Up @@ -246,8 +248,9 @@ def on_incoming_publish_event(event):
test_context.job_executions_changed_events.append(event)
test_context.signal.notify_all()

def on_subscription_event(event):
subscribed.set_result(event)
def on_subscription_event(event : SubscriptionStatusEvent):
if event.type == SubscriptionStatusEventType.SUBSCRIPTION_ESTABLISHED:
subscribed.set_result(event)

stream_options = awsiot.ServiceStreamOptions(
incoming_event_listener=on_incoming_publish_event,
Expand All @@ -273,8 +276,9 @@ def on_incoming_publish_event(event):
test_context.next_job_execution_changed_events.append(event)
test_context.signal.notify_all()

def on_subscription_event(event):
subscribed.set_result(event)
def on_subscription_event(event : SubscriptionStatusEvent):
if event.type == SubscriptionStatusEventType.SUBSCRIPTION_ESTABLISHED:
subscribed.set_result(event)

stream_options = awsiot.ServiceStreamOptions(
incoming_event_listener=on_incoming_publish_event,
Expand Down
24 changes: 18 additions & 6 deletions test/test_shadow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# SPDX-License-Identifier: Apache-2.0.

from awscrt import io, mqtt, mqtt5, mqtt_request_response
from awscrt.mqtt_request_response import SubscriptionStatusEvent, SubscriptionStatusEventType

import awsiot
from awsiot import iotshadow

Expand Down Expand Up @@ -62,8 +64,8 @@ class ShadowServiceTest(unittest.TestCase):
def _create_protocol_client5(self):

input_host_name = _get_env_variable("AWS_TEST_MQTT5_IOT_CORE_HOST")
input_cert = _get_env_variable("AWS_TEST_MQTT5_IOT_CORE_RSA_CERT")
input_key = _get_env_variable("AWS_TEST_MQTT5_IOT_CORE_RSA_KEY")
input_cert = _get_env_variable("AWS_TEST_MQTT5_IOT_CERTIFICATE_PATH")
input_key = _get_env_variable("AWS_TEST_MQTT5_IOT_KEY_PATH")

client_options = mqtt5.ClientOptions(
host_name=input_host_name,
Expand Down Expand Up @@ -100,8 +102,8 @@ def _shutdown_protocol_client5(self, protocol_client, callbacks):
def _create_protocol_client311(self):

input_host_name = _get_env_variable("AWS_TEST_MQTT5_IOT_CORE_HOST")
input_cert = _get_env_variable("AWS_TEST_MQTT5_IOT_CORE_RSA_CERT")
input_key = _get_env_variable("AWS_TEST_MQTT5_IOT_CORE_RSA_KEY")
input_cert = _get_env_variable("AWS_TEST_MQTT5_IOT_CERTIFICATE_PATH")
input_key = _get_env_variable("AWS_TEST_MQTT5_IOT_KEY_PATH")

tls_ctx_options = io.TlsContextOptions.create_client_with_mtls_from_path(
input_cert,
Expand Down Expand Up @@ -270,13 +272,18 @@ def _do_update_shadow_test(self, shadow_client):

delta_subscription_future = Future()
delta_future = Future()

def on_delta_subscription_event(event : SubscriptionStatusEvent):
if event.type == SubscriptionStatusEventType.SUBSCRIPTION_ESTABLISHED:
delta_subscription_future.set_result(event)

delta_event_stream = shadow_client.create_named_shadow_delta_updated_stream(
iotshadow.NamedShadowDeltaUpdatedSubscriptionRequest(
thing_name=thing_name,
shadow_name=shadow_name,
),
awsiot.ServiceStreamOptions(
subscription_status_listener=lambda event: delta_subscription_future.set_result(event),
subscription_status_listener=on_delta_subscription_event,
incoming_event_listener=lambda event: delta_future.set_result(event),
)
)
Expand All @@ -289,13 +296,18 @@ def _do_update_shadow_test(self, shadow_client):

update_subscription_future = Future()
update_future = Future()

def on_updated_subscription_event(event : SubscriptionStatusEvent):
if event.type == SubscriptionStatusEventType.SUBSCRIPTION_ESTABLISHED:
update_subscription_future.set_result(event)

update_event_stream = shadow_client.create_named_shadow_updated_stream(
iotshadow.NamedShadowUpdatedSubscriptionRequest(
thing_name=thing_name,
shadow_name=shadow_name,
),
awsiot.ServiceStreamOptions(
subscription_status_listener=lambda event: update_subscription_future.set_result(event),
subscription_status_listener=on_updated_subscription_event,
incoming_event_listener=lambda event: update_future.set_result(event),
)
)
Expand Down
Loading