Skip to content

Commit e58a590

Browse files
committed
test(transport): Add test for HTTP error status handling
Adds test coverage for the error handling path when HTTP requests return error status codes. GH-4568
1 parent 5f93332 commit e58a590

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

tests/test_transport.py

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -673,9 +673,9 @@ def test_record_lost_event_transaction_item(capturing_server, make_client, span_
673673
transport.record_lost_event(reason="test", item=transaction_item)
674674
client.flush()
675675

676-
(captured,) = capturing_server.captured # Should only be one envelope
676+
(captured,) = capturing_server.captured
677677
envelope = captured.envelope
678-
(item,) = envelope.items # Envelope should only have one item
678+
(item,) = envelope.items
679679

680680
assert item.type == "client_report"
681681

@@ -695,3 +695,38 @@ def test_record_lost_event_transaction_item(capturing_server, make_client, span_
695695
"reason": "test",
696696
"quantity": span_count + 1,
697697
} in discarded_events
698+
699+
700+
def test_handle_unexpected_status_invokes_handle_request_error(
701+
make_client, monkeypatch
702+
):
703+
client = make_client()
704+
transport = client.transport
705+
706+
monkeypatch.setattr(transport._worker, "submit", lambda fn: fn() or True)
707+
708+
def stub_request(method, endpoint, body=None, headers=None):
709+
class MockResponse:
710+
def __init__(self):
711+
self.status = 500 # Integer
712+
self.data = b"server error"
713+
self.headers = {}
714+
715+
def close(self):
716+
pass
717+
718+
return MockResponse()
719+
720+
monkeypatch.setattr(transport, "_request", stub_request)
721+
722+
seen = []
723+
monkeypatch.setattr(
724+
transport,
725+
"_handle_request_error",
726+
lambda envelope, loss_reason: seen.append(loss_reason),
727+
)
728+
729+
client.capture_event({"message": "test"})
730+
client.flush()
731+
732+
assert seen == ["status_500"]

0 commit comments

Comments
 (0)