Skip to content

Commit 7a03190

Browse files
committed
Add unit tests for http error.
1 parent 5b3470c commit 7a03190

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

tests/agent_unittests/test_agent_protocol.py

+21
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
DiscardDataForRequest,
2424
ForceAgentDisconnect,
2525
ForceAgentRestart,
26+
NetworkInterfaceException,
2627
RetryDataForRequest,
2728
)
2829

@@ -88,6 +89,18 @@ def close_connection(self):
8889
HttpClientRecorder.STATE -= 1
8990

9091

92+
class HttpClientException(DeveloperModeClient):
93+
def send_request(
94+
self,
95+
method="POST",
96+
path="/agent_listener/invoke_raw_method",
97+
params=None,
98+
headers=None,
99+
payload=None,
100+
):
101+
raise NetworkInterfaceException
102+
103+
91104
@pytest.fixture(autouse=True)
92105
def clear_sent_values():
93106
yield
@@ -246,6 +259,14 @@ def test_status_code_exceptions(status_code, expected_exc, log_level, caplog):
246259
assert "123LICENSEKEY" not in message
247260

248261

262+
def test_protocol_http_error_causes_retry():
263+
protocol = AgentProtocol(
264+
finalize_application_settings(), client_cls=HttpClientException
265+
)
266+
with pytest.raises(RetryDataForRequest):
267+
protocol.send("analytic_event_data")
268+
269+
249270
def test_protocol_context_manager():
250271
protocol = AgentProtocol(
251272
finalize_application_settings(), client_cls=HttpClientRecorder

0 commit comments

Comments
 (0)