Skip to content

Commit

Permalink
Merge branch 'release/0.3.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
robertmrk committed Jun 15, 2018
2 parents fe68a3d + 29a19e1 commit 8d72164
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 32 deletions.
2 changes: 1 addition & 1 deletion aiocometd/_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
DESCRIPTION = "CometD client for asyncio"
KEYWORDS = "asyncio aiohttp comet cometd bayeux push streaming"
URL = "https://github.com/robertmrk/aiocometd"
VERSION = "0.3.0"
VERSION = "0.3.1"
AUTHOR = "Róbert Márki"
AUTHOR_EMAIL = "gsmiko@gmail.com"
6 changes: 6 additions & 0 deletions aiocometd/transports/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class TransportBase(Transport): # pylint: disable=too-many-instance-attributes
"""
#: Timeout to give to HTTP session to close itself
_HTTP_SESSION_CLOSE_TIMEOUT = 0.250
#: The increase factor to use for request timeout
REQUEST_TIMEOUT_INCREASE_FACTOR = 1.2

def __init__(self, *, url, incoming_queue, client_id=None,
reconnection_timeout=1, ssl=None, extensions=None, auth=None,
Expand Down Expand Up @@ -177,7 +179,11 @@ def request_timeout(self):
"""Number of seconds after a network request should time out"""
timeout = self.reconnect_advice.get("timeout")
if timeout:
# convert milliseconds to seconds
timeout /= 1000
# increase the timeout specified by the server to avoid timing out
# by mistake
timeout *= self.__class__.REQUEST_TIMEOUT_INCREASE_FACTOR
return timeout

def _set_state_event(self, old_state, new_state):
Expand Down
12 changes: 0 additions & 12 deletions aiocometd/transports/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ async def _exit(self):
class WebSocketTransport(TransportBase):
"""WebSocket type transport"""

#: The increase factor to use for request timeout
REQUEST_TIMEOUT_INCREASE_FACTOR = 1.2

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
#: channels used during the connect task, requests on these channels
Expand All @@ -98,15 +95,6 @@ def __init__(self, *args, **kwargs):
#: exclusive lock for the objects created by _socket_factory_long
self._socket_lock_long = asyncio.Lock()

@property
def request_timeout(self):
timeout = super().request_timeout
if timeout:
# increase the timeout specified by the server to avoid timing out
# by mistake
timeout *= self.__class__.REQUEST_TIMEOUT_INCREASE_FACTOR
return timeout

async def _get_socket(self, channel, headers):
"""Get a websocket object for the given *channel*
Expand Down
5 changes: 5 additions & 0 deletions docs/source/changes.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
=========

0.3.1 (2018-06-15)
------------------

- Fix premature request timeout issue

0.3.0 (2018-05-04)
------------------

Expand Down
3 changes: 2 additions & 1 deletion tests/test_transports/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1235,7 +1235,8 @@ def test_request_timeout(self):
}

self.assertEqual(self.transport.request_timeout,
self.transport.reconnect_advice["timeout"] / 1000)
(self.transport.reconnect_advice["timeout"] / 1000) *
type(self.transport).REQUEST_TIMEOUT_INCREASE_FACTOR)

def test_request_timeout_none(self):
self.transport.reconnect_advice = {}
Expand Down
18 changes: 0 additions & 18 deletions tests/test_transports/test_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,24 +344,6 @@ async def test_send_final_payload_connection_timeout_error(self):
self.transport._send_socket_payload.assert_called_with(socket, payload)
self.transport._reset_sockets.assert_called()

@mock.patch("aiocometd.transports.websocket.super")
def test_request_timeout(self, super_mock):
super = mock.MagicMock()
super.request_timeout = 2000
super_mock.return_value = super

self.assertEqual(self.transport.request_timeout,
super.request_timeout *
type(self.transport).REQUEST_TIMEOUT_INCREASE_FACTOR)

@mock.patch("aiocometd.transports.websocket.super")
def test_request_timeout_none(self, super_mock):
super = mock.MagicMock()
super.request_timeout = None
super_mock.return_value = super

self.assertIsNone(self.transport.request_timeout)

@mock.patch("aiocometd.transports.websocket.WebSocketFactory")
async def test_reset_sockets(self, ws_factory_cls):
factory_short = object()
Expand Down

0 comments on commit 8d72164

Please sign in to comment.