1+ import json
12import os .path
23import shutil
34import subprocess
910
1011FLASK_PORT = 5000
1112
13+ DIR = os .path .join (os .path .dirname (__file__ ))
14+
1215
1316@pytest .fixture (scope = "function" )
1417def weaver_container_v1_36 ():
1518 weaver = WeaverContainer (
1619 schema_version = "1.36.0" ,
20+ templates_dir = os .path .join (DIR , "../templates" ),
1721 )
1822 yield weaver .start (timeout = 20 )
1923 weaver .stop ()
2024
2125
26+ @pytest .fixture ()
27+ def weaver_binary ():
28+ # FIXME: don't hardcode weaver bin path
29+ weaver_bin = "/home/rm/src/weaver/./target/release/weaver"
30+ application_path = os .path .join (os .path .dirname (__file__ ))
31+
32+ weaver = subprocess .Popen (
33+ [
34+ weaver_bin ,
35+ "registry" ,
36+ "live-check" ,
37+ "--inactivity-timeout=10" , # FIXME: don't hardcode timeout
38+ "--format=json" ,
39+ "--no-stats" ,
40+ "--output" ,
41+ DIR ,
42+ ],
43+ cwd = application_path ,
44+ stdout = subprocess .PIPE ,
45+ stderr = subprocess .PIPE ,
46+ )
47+
48+ time .sleep (2 )
49+
50+ ready = False
51+ for i in range (10 ):
52+ try :
53+ response = requests .post ("http://localhost:4320" , timeout = 5 )
54+ except Exception :
55+ continue
56+ if response .status_code == 404 :
57+ ready = True
58+ break
59+ time .sleep (0.5 )
60+
61+ if not ready :
62+ weaver .terminate ()
63+ weaver .wait (timeout = 5 )
64+ raise Exception ("sad trombone" )
65+
66+ yield weaver
67+
68+
2269@pytest .fixture
2370def flask_fixture (): # weaver_container_v1_36):
2471 # otlp_endpoint = weaver_container_v1_36.get_otlp_endpoint()
2572 wrapper = shutil .which ("opentelemetry-instrument" )
2673 opentelemetry_instrumentation = [
2774 wrapper ,
2875 "--metric_export_interval" ,
29- "1000 " ,
76+ "4000 " ,
3077 # "--exporter_otlp_endpoint",
3178 # otlp_endpoint,
3279 ]
80+
3381 application_path = os .path .join (os .path .dirname (__file__ ))
3482 handler = subprocess .Popen (
3583 opentelemetry_instrumentation
@@ -47,15 +95,25 @@ def flask_fixture(): # weaver_container_v1_36):
4795 handler .wait (timeout = 5 )
4896
4997
50- def test_flask_request (flask_fixture ): # , weaver_container_v1_36 ):
98+ def test_flask_request (weaver_binary , flask_fixture ):
5199 response = requests .get (f"http://127.0.0.1:{ FLASK_PORT } /rolldice" )
52100 assert response .status_code == 200
53101
54102 response = requests .get (f"http://127.0.0.1:{ FLASK_PORT } /" )
55103 assert response .status_code == 404
56104
57- """
58- full_report = weaver_container_v1_36.end_live_check()
105+ # 5 seconds are needed to avoid grpc errors
106+ time .sleep (5 )
107+
108+ # stop weaver
109+ requests .post ("http://localhost:4320/stop" )
110+
111+ outs , errs = weaver_binary .communicate (timeout = 5 )
112+
113+ report_path = os .path .join (DIR , "live_check.json" )
114+ with open (report_path , "r" ) as f :
115+ report_content = f .read ()
116+ report = json .loads (report_content )
59117
60- assert full_report
61- """
118+ assert report
119+ assert report [ "span" ]
0 commit comments