Skip to content

Commit 14a531b

Browse files
committed
tests: Add a timeout task to make sure the CI doesn't get stuck.
Signed-off-by: iabdalkader <[email protected]>
1 parent 5eca32a commit 14a531b

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

tests/ci.py

+21-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
# https://creativecommons.org/publicdomain/zero/1.0/
44
import logging
55
import os
6+
import time
67
import sys
78
import asyncio
89
from arduino_iot_cloud import ArduinoCloudClient
10+
from arduino_iot_cloud import Task
911
import argparse
1012

1113

@@ -20,6 +22,16 @@ def on_value_changed(client, value):
2022
sys.exit(0)
2123

2224

25+
def wdt_task(client, ts=[None]):
26+
if ts[0] is None:
27+
ts[0] = time.time()
28+
if time.time() - ts[0] > 5:
29+
loop = asyncio.get_event_loop()
30+
loop.set_exception_handler(exception_handler)
31+
logging.error("Timeout waiting for variable")
32+
sys.exit(1)
33+
34+
2335
if __name__ == "__main__":
2436
# Parse command line args.
2537
parser = argparse.ArgumentParser(description="arduino_iot_cloud.py")
@@ -35,6 +47,9 @@ def on_value_changed(client, value):
3547
parser.add_argument(
3648
"-f", "--file-auth", action="store_true", help="Use key/cert files"
3749
)
50+
parser.add_argument(
51+
"-s", "--sync", action="store_true", help="Run in synchronous mode"
52+
)
3853
args = parser.parse_args()
3954

4055
# Configure the logger.
@@ -56,6 +71,7 @@ def on_value_changed(client, value):
5671
device_id=os.getenv("DEVICE_ID"),
5772
username=os.getenv("DEVICE_ID"),
5873
password=os.getenv("SECRET_KEY"),
74+
sync_mode=args.sync,
5975
)
6076
elif args.file_auth:
6177
import ssl
@@ -67,6 +83,7 @@ def on_value_changed(client, value):
6783
"ca_certs": "ca-root.pem",
6884
"cert_reqs": ssl.CERT_REQUIRED,
6985
},
86+
sync_mode=args.sync,
7087
)
7188
elif args.crypto_device:
7289
import ssl
@@ -82,16 +99,17 @@ def on_value_changed(client, value):
8299
"engine_path": "/lib/x86_64-linux-gnu/engines-3/libpkcs11.so",
83100
"module_path": "/lib/x86_64-linux-gnu/softhsm/libsofthsm2.so",
84101
},
102+
sync_mode=args.sync,
85103
)
86104
else:
87105
parser.print_help()
88106
sys.exit(1)
89107

90108
# Register cloud objects.
91-
# Note: The following objects must be created first in the dashboard and linked to the device.
92-
# This cloud object is initialized with its last known value from the cloud. When this object is updated
93-
# from the dashboard, the on_switch_changed function is called with the client object and the new value.
109+
# When this object gets initialized from the cloud the test is complete.
94110
client.register("answer", value=None, on_write=on_value_changed)
111+
# This task will exist with failure after a timeout.
112+
client.register(Task("wdt_task", on_run=wdt_task, interval=1.0))
95113

96114
# Start the Arduino IoT cloud client.
97115
client.start()

0 commit comments

Comments
 (0)