-
Notifications
You must be signed in to change notification settings - Fork 641
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use HTTP mock server for tornado tests (#1855)
* Use HTTP mock server for tornado tests Fixes #1681 * Fix lint
- Loading branch information
Showing
3 changed files
with
36 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
|
||
from unittest.mock import Mock, patch | ||
|
||
from http_server_mock import HttpServerMock | ||
from tornado.testing import AsyncHTTPTestCase | ||
|
||
from opentelemetry import trace | ||
|
@@ -494,32 +495,35 @@ def test_response_headers(self): | |
self.memory_exporter.clear() | ||
set_global_response_propagator(orig) | ||
|
||
# todo(srikanthccv): fix this test | ||
# this test is making request to real httpbin.org/status/200 which | ||
# is not a good idea as it can fail due to availability of the | ||
# service. | ||
# def test_credential_removal(self): | ||
# response = self.fetch( | ||
# "http://username:[email protected]/status/200" | ||
# ) | ||
# self.assertEqual(response.code, 200) | ||
|
||
# spans = self.sorted_spans(self.memory_exporter.get_finished_spans()) | ||
# self.assertEqual(len(spans), 1) | ||
# client = spans[0] | ||
|
||
# self.assertEqual(client.name, "GET") | ||
# self.assertEqual(client.kind, SpanKind.CLIENT) | ||
# self.assertSpanHasAttributes( | ||
# client, | ||
# { | ||
# SpanAttributes.HTTP_URL: "http://httpbin.org/status/200", | ||
# SpanAttributes.HTTP_METHOD: "GET", | ||
# SpanAttributes.HTTP_STATUS_CODE: 200, | ||
# }, | ||
# ) | ||
|
||
# self.memory_exporter.clear() | ||
def test_credential_removal(self): | ||
app = HttpServerMock("test_credential_removal") | ||
|
||
@app.route("/status/200") | ||
def index(): | ||
return "hello" | ||
|
||
with app.run("localhost", 5000): | ||
response = self.fetch( | ||
"http://username:password@localhost:5000/status/200" | ||
) | ||
self.assertEqual(response.code, 200) | ||
|
||
spans = self.sorted_spans(self.memory_exporter.get_finished_spans()) | ||
self.assertEqual(len(spans), 1) | ||
client = spans[0] | ||
|
||
self.assertEqual(client.name, "GET") | ||
self.assertEqual(client.kind, SpanKind.CLIENT) | ||
self.assertSpanHasAttributes( | ||
client, | ||
{ | ||
SpanAttributes.HTTP_URL: "http://localhost:5000/status/200", | ||
SpanAttributes.HTTP_METHOD: "GET", | ||
SpanAttributes.HTTP_STATUS_CODE: 200, | ||
}, | ||
) | ||
|
||
self.memory_exporter.clear() | ||
|
||
|
||
class TestTornadoInstrumentationWithXHeaders(TornadoTest): | ||
|