Skip to content

Commit ce6fb9a

Browse files
fix: convert event request timeout to seconds
1 parent 75f8155 commit ce6fb9a

2 files changed

Lines changed: 48 additions & 1 deletion

File tree

‎devcycle_python_sdk/api/event_client.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def publish_events(self, batch: List[UserEventsBatchRecord]) -> str:
3636
Attempts to send a batch of events to the server
3737
"""
3838
retries_remaining = self.max_batch_retries + 1
39-
timeout = self.options.event_request_timeout_ms
39+
timeout = self.options.event_request_timeout_ms / 1000.0
4040

4141
payload_json = json.dumps(
4242
{

‎test/api/test_event_timeout.py‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import unittest
2+
3+
import responses
4+
from responses.matchers import request_kwargs_matcher
5+
6+
from devcycle_python_sdk.api.event_client import EventAPIClient
7+
from devcycle_python_sdk.models.event import UserEventsBatchRecord
8+
from devcycle_python_sdk.models.user import DevCycleUser
9+
from devcycle_python_sdk.options import DevCycleLocalOptions
10+
11+
12+
class EventTimeoutTest(unittest.TestCase):
13+
@responses.activate
14+
def _check_timeout(self, timeout_ms=None):
15+
options = (
16+
DevCycleLocalOptions()
17+
if timeout_ms is None
18+
else DevCycleLocalOptions(event_request_timeout_ms=timeout_ms)
19+
)
20+
client = EventAPIClient("dvc_server_test", options)
21+
expected_seconds = (10000 if timeout_ms is None else timeout_ms) / 1000.0
22+
responses.add(
23+
responses.POST,
24+
client.batch_url,
25+
json={"message": "received"},
26+
match=[request_kwargs_matcher({"timeout": expected_seconds})],
27+
)
28+
batch = [
29+
UserEventsBatchRecord(user=DevCycleUser(user_id="test-user"), events=[])
30+
]
31+
try:
32+
self.assertEqual(client.publish_events(batch), "received")
33+
self.assertEqual(len(responses.calls), 1)
34+
finally:
35+
client.session.close()
36+
37+
def test_default_timeout(self):
38+
self._check_timeout()
39+
40+
def test_one_millisecond_timeout(self):
41+
self._check_timeout(1)
42+
43+
def test_subsecond_timeout(self):
44+
self._check_timeout(250)
45+
46+
def test_fractional_second_timeout(self):
47+
self._check_timeout(1250)

0 commit comments

Comments
 (0)