66from opentracing .ext import tags
77from opentracing .mocktracer import MockTracer
88from flask_opentracing import FlaskTracing
9+ from flaky import flaky
910
1011
1112app = Flask (__name__ )
1920
2021
2122def flush_spans (tcr ):
22- for req in tcr ._current_scopes :
23- tcr . _current_scopes [ req ] .close ()
23+ for span in tcr ._current_scopes . values () :
24+ span .close ()
2425 tcr ._current_scopes = {}
2526
2627
@@ -101,9 +102,9 @@ def test_span_tags(self):
101102 tags .HTTP_METHOD : 'GET' ,
102103 tags .SPAN_KIND : tags .SPAN_KIND_RPC_SERVER ,
103104 tags .HTTP_URL : 'http://localhost/another_test_simple' ,
104- 'is_xhr' : 'False' ,
105105 }
106106
107+ @flaky (max_runs = 5 )
107108 def test_requests_distinct (self ):
108109 with app .test_request_context ('/test' ):
109110 app .preprocess_request ()
@@ -176,6 +177,7 @@ def _verify_error(self, span):
176177 RuntimeError
177178 )
178179
180+ @flaky (max_runs = 5 )
179181 def test_over_wire (self ):
180182 rv = test_app .get ('/wire' )
181183 assert '200' in str (rv .status_code )
@@ -193,33 +195,3 @@ def test_child_span(self):
193195 assert len (spans ) == 2
194196 assert spans [0 ].context .trace_id == spans [1 ].context .trace_id
195197 assert spans [0 ].parent_id == spans [1 ].context .span_id
196-
197-
198- class TestTracingStartSpanCallback (unittest .TestCase ):
199- def test_simple (self ):
200- def start_span_cb (span , request ):
201- span .set_tag ('component' , 'not-flask' )
202- span .set_tag ('mytag' , 'myvalue' )
203-
204- tracing = FlaskTracing (MockTracer (), True , app ,
205- start_span_cb = start_span_cb )
206- rv = test_app .get ('/test' )
207- assert '200' in str (rv .status_code )
208-
209- spans = tracing .tracer .finished_spans ()
210- assert len (spans ) == 1
211- assert spans [0 ].tags .get (tags .COMPONENT , None ) == 'not-flask'
212- assert spans [0 ].tags .get ('mytag' , None ) == 'myvalue'
213-
214- def test_error (self ):
215- def start_span_cb (span , request ):
216- raise RuntimeError ('Should not happen' )
217-
218- tracing = FlaskTracing (MockTracer (), True , app ,
219- start_span_cb = start_span_cb )
220- rv = test_app .get ('/test' )
221- assert '200' in str (rv .status_code )
222-
223- spans = tracing .tracer .finished_spans ()
224- assert len (spans ) == 1
225- assert spans [0 ].tags .get (tags .ERROR , None ) is None
0 commit comments