1616import os
1717import subprocess
1818import time
19-
19+ import pytest
2020import requests
2121import yaml
2222from prometheus_client .parser import text_string_to_metric_families
2323
24-
24+ @ pytest . mark . timeout ( 30 )
2525def 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