Repository navigation
fix: convert event request timeout to seconds - #122
Draft
Kayvan-Zahiri wants to merge 2 commits into
Draft
Kayvan-Zahiri wants to merge 2 commits into
Kayvan-Zahiri wants to merge 2 commits into
Conversation
jonathannorris
left a comment
Member
There was a problem hiding this comment.
Thanks for the contribution @Kayvan-Zahiri! Good catch on the ms vs seconds mismatch, the fix itself looks good and matches what config_client.py already does.
I think it probably makes sense to simplify the tests a bit though:
- Assert on the timeout directly instead of through
request_kwargs_matcher. With the matcher, a wrong value surfaces as aConnectionErrorfromresponsesthat gets wrapped inAPIClientError: Retries exceeded, so you have to dig through the logs to see why it failed.responsesalready records the request kwargs, so asserting onresponses.calls[0].request.req_kwargs["timeout"]fails with10000 != 10.0instead. - Move them into
EventAPIClientTestintest/api/test_event_client.py, which already sets up the client, batch URL, and batch insetUp, rather than adding a new file. - Two cases are enough: the default and one custom value. The four cases are all exercising the same division.
Something like:
@responses.activate
def test_publish_events_timeout_in_seconds(self):
responses.add(responses.POST, self.test_batch_url, json={"message": "ok"})
self.test_client.publish_events(self.test_batch)
self.assertEqual(responses.calls[0].request.req_kwargs["timeout"], 10.0)
@responses.activate
def test_publish_events_custom_timeout_in_seconds(self):
client = EventAPIClient(
self.sdk_key,
DevCycleLocalOptions(
events_api_uri="http://localhost:8080", event_request_timeout_ms=250
),
)
responses.add(responses.POST, self.test_batch_url, json={"message": "ok"})
client.publish_events(self.test_batch)
self.assertEqual(responses.calls[0].request.req_kwargs["timeout"], 0.25)and test/api/test_event_timeout.py can be dropped.
If it's easier, I'm happy to make these changes myself in a separate branch, just let me know.
Author
|
Thanks, done in 2ec10c6. The two tests now live in |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
EventAPIClient.publish_eventspassesevent_request_timeout_msdirectly torequests.Session.request, whose timeout parameter is in seconds. The default 10000 ms is therefore sent as 10000 seconds (2 hours 46 minutes 40 seconds), rather than 10 seconds. Custom subsecond values are likewise off by a factor of 1000.Change
Convert the configured milliseconds to seconds at the HTTP request boundary, matching the existing config client's conversion. Retry behavior and the configured option remain unchanged.
Validation
publish_eventswith the default, 1 ms, 250 ms, and 1250 ms settings.responsesverifies the actual Requests timeout argument and returns a successful event-batch response only for the expected seconds value.git diff --checkpasses.AI assistance: OpenAI Codex assisted with reproduction, patch, tests, and this description.