16
16
import os
17
17
import subprocess
18
18
import time
19
-
19
+ import pytest
20
20
import requests
21
21
import yaml
22
22
from prometheus_client .parser import text_string_to_metric_families
23
23
24
-
24
+ @ pytest . mark . timeout ( 30 )
25
25
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
27
29
cli_path = os .path .join (str (pytestconfig .rootdir ), ".." , "arduino-cli" )
28
30
env = os .environ .copy ()
29
31
env ["ARDUINO_DATA_DIR" ] = data_dir
30
32
env ["ARDUINO_DOWNLOADS_DIR" ] = downloads_dir
31
33
env ["ARDUINO_SKETCHBOOK_DIR" ] = data_dir
34
+ daemon = subprocess .Popen ([cli_path , "daemon" ], env = env )
32
35
33
- subprocess .Popen ([cli_path , "daemon" ], env = env )
34
-
35
- time .sleep (5 )
36
36
37
- # parse repertory file
37
+ # wait for and then parse repertory file
38
38
repertory_file = os .path .join (data_dir , "repertory.yaml" )
39
+ while not os .path .exists (repertory_file ):
40
+ time .sleep (1 )
39
41
with open (repertory_file , 'r' ) as stream :
40
42
repertory = yaml .safe_load (stream )
41
43
@@ -45,3 +47,5 @@ def test_telemetry_prometheus_endpoint(pytestconfig, data_dir, downloads_dir):
45
47
family = next (text_string_to_metric_families (metrics ))
46
48
sample = family .samples [0 ]
47
49
assert repertory ["installation" ]["id" ] == sample .labels ["installationID" ]
50
+ #add a fixture here!
51
+ daemon .kill ()
0 commit comments