Skip to content

Commit 3dda05c

Browse files
committed
Add tests for errors & exceptions
1 parent e86f88b commit 3dda05c

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

tests/test_urllib3.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,47 @@ def test_put_request(self):
5959
assert_equals("PUT", second_span.data.http.method)
6060
assert_equals(None, second_span.error)
6161
assert_equals(None, second_span.ec)
62+
63+
def test_5xx_request(self):
64+
span = tracer.start_span("test")
65+
r = self.http.request('GET', 'http://127.0.0.1:5000/504')
66+
span.finish()
67+
68+
spans = self.recorder.queued_spans()
69+
first_span = spans[1]
70+
second_span = spans[0]
71+
72+
assert(r)
73+
assert_equals(504, r.status)
74+
assert_equals(2, len(spans))
75+
assert_equals("test", first_span.data.sdk.name)
76+
assert_equals("urllib3", second_span.n)
77+
assert_equals(504, second_span.data.http.status)
78+
assert_equals("http://127.0.0.1:5000/504", second_span.data.http.url)
79+
assert_equals("GET", second_span.data.http.method)
80+
assert_equals(True, second_span.error)
81+
assert_equals(1, second_span.ec)
82+
83+
def test_exception_logging(self):
84+
span = tracer.start_span("test")
85+
try:
86+
r = self.http.request('GET', 'http://127.0.0.1:5000/exception')
87+
except Exception:
88+
pass
89+
90+
span.finish()
91+
92+
spans = self.recorder.queued_spans()
93+
first_span = spans[1]
94+
second_span = spans[0]
95+
96+
assert(r)
97+
assert_equals(500, r.status)
98+
assert_equals(2, len(spans))
99+
assert_equals("test", first_span.data.sdk.name)
100+
assert_equals("urllib3", second_span.n)
101+
assert_equals(500, second_span.data.http.status)
102+
assert_equals("http://127.0.0.1:5000/exception", second_span.data.http.url)
103+
assert_equals("GET", second_span.data.http.method)
104+
assert_equals(True, second_span.error)
105+
assert_equals(1, second_span.ec)

0 commit comments

Comments
 (0)