Skip to content

Commit

Permalink
Push timeout calculation to service call
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Cederstrand committed Jan 6, 2022
1 parent ab2e247 commit 1bbae0e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
4 changes: 1 addition & 3 deletions exchangelib/folders/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,9 +656,7 @@ def get_streaming_events(self, subscription_id_or_ids, connection_timeout=1, max
sync methods.
"""
from ..services import GetStreamingEvents
# Add 60 seconds to the timeout, to allow us to always get the final message containing ConnectionStatus=Closed
request_timeout = connection_timeout*60 + 60
svc = GetStreamingEvents(account=self.account, timeout=request_timeout)
svc = GetStreamingEvents(account=self.account)
subscription_ids = subscription_id_or_ids if is_iterable(subscription_id_or_ids, generators_allowed=True) \
else [subscription_id_or_ids]
for i, notification in enumerate(
Expand Down
2 changes: 2 additions & 0 deletions exchangelib/services/get_streaming_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def call(self, subscription_ids, connection_timeout):
raise InvalidTypeError('connection_timeout', connection_timeout, int)
if connection_timeout < 1:
raise ValueError(f"'connection_timeout' {connection_timeout} must be a positive integer")
# Add 60 seconds to the timeout, to allow us to always get the final message containing ConnectionStatus=Closed
self.timeout = connection_timeout * 60 + 60
return self._elems_to_objs(self._get_elements(payload=self.get_payload(
subscription_ids=subscription_ids, connection_timeout=connection_timeout,
)))
Expand Down
2 changes: 1 addition & 1 deletion tests/test_items/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ def test_streaming_invalid_subscription(self):

# Test with bad connection_timeout
with self.assertRaises(TypeError) as e:
list(test_folder.get_streaming_events('AAA-', connection_timeout=-1, max_notifications_returned='XXX'))
list(test_folder.get_streaming_events('AAA-', connection_timeout='XXX', max_notifications_returned=1))
self.assertEqual(e.exception.args[0], "'connection_timeout' 'XXX' must be of type <class 'int'>")
with self.assertRaises(ValueError) as e:
list(test_folder.get_streaming_events('AAA-', connection_timeout=-1, max_notifications_returned=1))
Expand Down

0 comments on commit 1bbae0e

Please sign in to comment.