Skip to content

Commit d71b953

Browse files
authored
Fix socket tests to not use example.com (#4627)
part of #4623
1 parent bc7ca86 commit d71b953

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

tests/integrations/socket/test_socket.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,27 @@
22

33
from sentry_sdk import start_transaction
44
from sentry_sdk.integrations.socket import SocketIntegration
5-
from tests.conftest import ApproxDict
5+
from tests.conftest import ApproxDict, create_mock_http_server
6+
7+
PORT = create_mock_http_server()
68

79

810
def test_getaddrinfo_trace(sentry_init, capture_events):
911
sentry_init(integrations=[SocketIntegration()], traces_sample_rate=1.0)
1012
events = capture_events()
1113

1214
with start_transaction():
13-
socket.getaddrinfo("example.com", 443)
15+
socket.getaddrinfo("localhost", PORT)
1416

1517
(event,) = events
1618
(span,) = event["spans"]
1719

1820
assert span["op"] == "socket.dns"
19-
assert span["description"] == "example.com:443"
21+
assert span["description"] == f"localhost:{PORT}" # noqa: E231
2022
assert span["data"] == ApproxDict(
2123
{
22-
"host": "example.com",
23-
"port": 443,
24+
"host": "localhost",
25+
"port": PORT,
2426
}
2527
)
2628

@@ -32,28 +34,28 @@ def test_create_connection_trace(sentry_init, capture_events):
3234
events = capture_events()
3335

3436
with start_transaction():
35-
socket.create_connection(("example.com", 443), timeout, None)
37+
socket.create_connection(("localhost", PORT), timeout, None)
3638

3739
(event,) = events
3840
(connect_span, dns_span) = event["spans"]
3941
# as getaddrinfo gets called in create_connection it should also contain a dns span
4042

4143
assert connect_span["op"] == "socket.connection"
42-
assert connect_span["description"] == "example.com:443"
44+
assert connect_span["description"] == f"localhost:{PORT}" # noqa: E231
4345
assert connect_span["data"] == ApproxDict(
4446
{
45-
"address": ["example.com", 443],
47+
"address": ["localhost", PORT],
4648
"timeout": timeout,
4749
"source_address": None,
4850
}
4951
)
5052

5153
assert dns_span["op"] == "socket.dns"
52-
assert dns_span["description"] == "example.com:443"
54+
assert dns_span["description"] == f"localhost:{PORT}" # noqa: E231
5355
assert dns_span["data"] == ApproxDict(
5456
{
55-
"host": "example.com",
56-
"port": 443,
57+
"host": "localhost",
58+
"port": PORT,
5759
}
5860
)
5961

@@ -66,7 +68,7 @@ def test_span_origin(sentry_init, capture_events):
6668
events = capture_events()
6769

6870
with start_transaction(name="foo"):
69-
socket.create_connection(("example.com", 443), 1, None)
71+
socket.create_connection(("localhost", PORT), 1, None)
7072

7173
(event,) = events
7274

0 commit comments

Comments
 (0)