Browse Source
Fix: SimpleClient.call does not raise TimeoutError on timeout (#1501)
pull/1505/head
James Thistlewood
2 weeks ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with
25 additions and
0 deletions
-
src/socketio/async_simple_client.py
-
src/socketio/simple_client.py
-
tests/async/test_simple_client.py
-
tests/common/test_simple_client.py
|
@ -163,6 +163,8 @@ class AsyncSimpleClient: |
|
|
return await self.client.call(event, data, |
|
|
return await self.client.call(event, data, |
|
|
namespace=self.namespace, |
|
|
namespace=self.namespace, |
|
|
timeout=timeout) |
|
|
timeout=timeout) |
|
|
|
|
|
except TimeoutError: |
|
|
|
|
|
raise |
|
|
except SocketIOError: |
|
|
except SocketIOError: |
|
|
pass |
|
|
pass |
|
|
|
|
|
|
|
|
|
@ -155,6 +155,8 @@ class SimpleClient: |
|
|
try: |
|
|
try: |
|
|
return self.client.call(event, data, namespace=self.namespace, |
|
|
return self.client.call(event, data, namespace=self.namespace, |
|
|
timeout=timeout) |
|
|
timeout=timeout) |
|
|
|
|
|
except TimeoutError: |
|
|
|
|
|
raise |
|
|
except SocketIOError: |
|
|
except SocketIOError: |
|
|
pass |
|
|
pass |
|
|
|
|
|
|
|
|
|
@ -142,6 +142,17 @@ class TestAsyncAsyncSimpleClient: |
|
|
client.client.call.assert_awaited_with('foo', 'bar', namespace='/', |
|
|
client.client.call.assert_awaited_with('foo', 'bar', namespace='/', |
|
|
timeout=60) |
|
|
timeout=60) |
|
|
|
|
|
|
|
|
|
|
|
async def test_call_timeout(self): |
|
|
|
|
|
client = AsyncSimpleClient() |
|
|
|
|
|
client.connected_event.set() |
|
|
|
|
|
client.connected = True |
|
|
|
|
|
client.client = mock.MagicMock() |
|
|
|
|
|
client.client.call = mock.AsyncMock() |
|
|
|
|
|
client.client.call.side_effect = TimeoutError() |
|
|
|
|
|
|
|
|
|
|
|
with pytest.raises(TimeoutError): |
|
|
|
|
|
await client.call('foo', 'bar') |
|
|
|
|
|
|
|
|
async def test_receive_with_input_buffer(self): |
|
|
async def test_receive_with_input_buffer(self): |
|
|
client = AsyncSimpleClient() |
|
|
client = AsyncSimpleClient() |
|
|
client.input_buffer = ['foo', 'bar'] |
|
|
client.input_buffer = ['foo', 'bar'] |
|
|
|
@ -130,6 +130,16 @@ class TestSimpleClient: |
|
|
client.client.call.assert_called_with('foo', 'bar', namespace='/', |
|
|
client.client.call.assert_called_with('foo', 'bar', namespace='/', |
|
|
timeout=60) |
|
|
timeout=60) |
|
|
|
|
|
|
|
|
|
|
|
def test_call_timeout(self): |
|
|
|
|
|
client = SimpleClient() |
|
|
|
|
|
client.connected_event.set() |
|
|
|
|
|
client.connected = True |
|
|
|
|
|
client.client = mock.MagicMock() |
|
|
|
|
|
client.client.call.side_effect = TimeoutError() |
|
|
|
|
|
|
|
|
|
|
|
with pytest.raises(TimeoutError): |
|
|
|
|
|
client.call('foo', 'bar') |
|
|
|
|
|
|
|
|
def test_receive_with_input_buffer(self): |
|
|
def test_receive_with_input_buffer(self): |
|
|
client = SimpleClient() |
|
|
client = SimpleClient() |
|
|
client.input_buffer = ['foo', 'bar'] |
|
|
client.input_buffer = ['foo', 'bar'] |
|
|