Skip to content

Commit 4bfca0b

Browse files
committed
Add test to validate tracing through client errors.
1 parent 226a4c1 commit 4bfca0b

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

tests/test_urllib3.py

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ def test_get_request(self):
2525
span.finish()
2626

2727
spans = self.recorder.queued_spans()
28+
assert_equals(2, len(spans))
2829
first_span = spans[1]
2930
second_span = spans[0]
3031

3132
assert(r)
3233
assert_equals(200, r.status)
33-
assert_equals(2, len(spans))
3434
assert_equals("test", first_span.data.sdk.name)
3535
assert_equals("urllib3", second_span.n)
3636
assert_equals(200, second_span.data.http.status)
@@ -46,12 +46,12 @@ def test_put_request(self):
4646
span.finish()
4747

4848
spans = self.recorder.queued_spans()
49+
assert_equals(2, len(spans))
4950
first_span = spans[1]
5051
second_span = spans[0]
5152

5253
assert(r)
5354
assert_equals(404, r.status)
54-
assert_equals(2, len(spans))
5555
assert_equals("test", first_span.data.sdk.name)
5656
assert_equals("urllib3", second_span.n)
5757
assert_equals(404, second_span.data.http.status)
@@ -66,12 +66,12 @@ def test_5xx_request(self):
6666
span.finish()
6767

6868
spans = self.recorder.queued_spans()
69+
assert_equals(2, len(spans))
6970
first_span = spans[1]
7071
second_span = spans[0]
7172

7273
assert(r)
7374
assert_equals(504, r.status)
74-
assert_equals(2, len(spans))
7575
assert_equals("test", first_span.data.sdk.name)
7676
assert_equals("urllib3", second_span.n)
7777
assert_equals(504, second_span.data.http.status)
@@ -90,16 +90,43 @@ def test_exception_logging(self):
9090
span.finish()
9191

9292
spans = self.recorder.queued_spans()
93+
assert_equals(2, len(spans))
9394
first_span = spans[1]
9495
second_span = spans[0]
9596

9697
assert(r)
9798
assert_equals(500, r.status)
98-
assert_equals(2, len(spans))
9999
assert_equals("test", first_span.data.sdk.name)
100100
assert_equals("urllib3", second_span.n)
101101
assert_equals(500, second_span.data.http.status)
102102
assert_equals("http://127.0.0.1:5000/exception", second_span.data.http.url)
103103
assert_equals("GET", second_span.data.http.method)
104104
assert_equals(True, second_span.error)
105105
assert_equals(1, second_span.ec)
106+
107+
def test_client_error(self):
108+
span = tracer.start_span("test")
109+
110+
r = None
111+
try:
112+
r = self.http.request('GET', 'http://doesnotexist.asdf:5000/504',
113+
retries=False,
114+
timeout=urllib3.Timeout(connect=0.5, read=0.5))
115+
except Exception:
116+
pass
117+
118+
span.finish()
119+
120+
spans = self.recorder.queued_spans()
121+
assert_equals(2, len(spans))
122+
first_span = spans[1]
123+
second_span = spans[0]
124+
125+
assert_equals(None, r)
126+
assert_equals("test", first_span.data.sdk.name)
127+
assert_equals("urllib3", second_span.n)
128+
assert_equals(None, second_span.data.http.status)
129+
assert_equals("http://doesnotexist.asdf:5000/504", second_span.data.http.url)
130+
assert_equals("GET", second_span.data.http.method)
131+
assert_equals(True, second_span.error)
132+
assert_equals(1, second_span.ec)

0 commit comments

Comments
 (0)