Skip to content

Commit

Permalink
Add waiting logic for shadow test
Browse files Browse the repository at this point in the history
  • Loading branch information
sfodagain committed Jan 2, 2024
1 parent 77e1bb6 commit 0249f99
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions servicetests/test_cases/test_shadow_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,25 +80,33 @@ def main():
if test_result == 0:
print("Verifying that shadow was updated")
shadow_value = None
try:
if shadow_name:
thing_shadow = iot_data_client.get_thing_shadow(thingName=thing_name, shadowName=shadow_name)
else:
thing_shadow = iot_data_client.get_thing_shadow(thingName=thing_name)

payload = thing_shadow['payload'].read()
data = json.loads(payload)
shadow_value = data.get('state', {}).get('reported', {}).get(shadow_property, None)
if shadow_value != shadow_desired_value:
print(f"ERROR: Could not verify thing shadow: {shadow_property} is not set to desired value "
f"'{shadow_desired_value}'; shadow actual state: {data}")
i = 0
while i < 10:
try:
if shadow_name:
thing_shadow = iot_data_client.get_thing_shadow(thingName=thing_name, shadowName=shadow_name)
else:
thing_shadow = iot_data_client.get_thing_shadow(thingName=thing_name)

payload = thing_shadow['payload'].read()
data = json.loads(payload)
shadow_value = data.get('state', {}).get('reported', {}).get(shadow_property, None)
if shadow_value == shadow_desired_value:
test_result = 0
break
else:
print(f"ERROR: Could not verify thing shadow: {shadow_property} is not set to desired value "
f"'{shadow_desired_value}'; shadow actual state: {data}")
test_result = -1
except KeyError as e:
print(f"ERROR: Could not verify thing shadow: key {e} does not exist in shadow response: {thing_shadow}")
test_result = -1
except KeyError as e:
print(f"ERROR: Could not verify thing shadow: key {e} does not exist in shadow response: {thing_shadow}")
test_result = -1
except Exception as e:
print(f"ERROR: Could not verify thing shadow: {e}")
test_result = -1
except Exception as e:
print(f"ERROR: Could not verify thing shadow: {e}")
test_result = -1
i = i + 1
time.sleep(1);


if test_result == 0:
print("Test succeeded")
Expand Down

0 comments on commit 0249f99

Please sign in to comment.