Skip to content

Commit 5e9a347

Browse files
author
Roberto Sora
committed
Wait for repertory and kill daemon
1 parent 20f2251 commit 5e9a347

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

test/requirements.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ pyserial==3.4
55
pyyaml==5.3
66
prometheus-client==0.7.1
77
requests==2.22.0
8+
pytest-timeout==1.3.4
89
# temporary, replaces invoke==1.3.0 in favour of https://github.com/pyinvoke/invoke/pull/661
910
git+https://github.com/flazzarini/invoke.git

test/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ prometheus-client==0.7.1
1717
py==1.8.0 # via pytest
1818
pyparsing==2.4.0 # via packaging
1919
pyserial==3.4
20+
pytest-timeout==1.3.4
2021
pytest==5.3.4
2122
pyyaml==5.3
2223
requests==2.22.0

test/test_daemon.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,28 @@
1616
import os
1717
import subprocess
1818
import time
19-
19+
import pytest
2020
import requests
2121
import yaml
2222
from prometheus_client.parser import text_string_to_metric_families
2323

24-
24+
@pytest.mark.timeout(30)
2525
def test_telemetry_prometheus_endpoint(pytestconfig, data_dir, downloads_dir):
26-
# Init the environment explicitly
26+
27+
# Use raw subprocess here due to a missing functionality in pinned pyinvoke ver,
28+
# in order to launch and detach the cli process in daemon mode
2729
cli_path = os.path.join(str(pytestconfig.rootdir), "..", "arduino-cli")
2830
env = os.environ.copy()
2931
env["ARDUINO_DATA_DIR"] = data_dir
3032
env["ARDUINO_DOWNLOADS_DIR"] = downloads_dir
3133
env["ARDUINO_SKETCHBOOK_DIR"] = data_dir
34+
daemon = subprocess.Popen([cli_path, "daemon"], env=env)
3235

33-
subprocess.Popen([cli_path, "daemon"], env=env)
34-
35-
time.sleep(5)
3636

37-
# parse repertory file
37+
# wait for and then parse repertory file
3838
repertory_file = os.path.join(data_dir, "repertory.yaml")
39+
while not os.path.exists(repertory_file):
40+
time.sleep(1)
3941
with open(repertory_file, 'r') as stream:
4042
repertory = yaml.safe_load(stream)
4143

@@ -45,3 +47,5 @@ def test_telemetry_prometheus_endpoint(pytestconfig, data_dir, downloads_dir):
4547
family = next(text_string_to_metric_families(metrics))
4648
sample = family.samples[0]
4749
assert repertory["installation"]["id"] == sample.labels["installationID"]
50+
#add a fixture here!
51+
daemon.kill()

0 commit comments

Comments
 (0)