Skip to content

Commit

Permalink
Fix more timing issues on Mac and Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Neil Booth committed Feb 4, 2021
1 parent 4268d63 commit 3e604c5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
3 changes: 2 additions & 1 deletion aiorpcx/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ async def __aenter__(self):

async def __aexit__(self, exc_type, exc_value, traceback):
await self.transport.close()
assert self.process_messages_task.done()
# Disabled this as loop might not have processed the event, and don't want to sleep here
# assert self.process_messages_task.done()


def serve_ws(session_factory, *args, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_curio.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ async def test_tg_cm_all():

@pytest.mark.asyncio
async def test_tg_cm_any():
tasks = [await spawn(sleep, x/200) for x in (0.1, 0.01, -1)]
tasks = [await spawn(sleep, x/200) for x in (0.5, 0.5, -1)]
async with TaskGroup(tasks, wait=any) as t:
pass
assert all(task.done() for task in tasks)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_jsonrpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ async def receive_request():
requests = connection.receive_message(message)
assert not requests

async with timeout_after(0.01):
async with timeout_after(0.2):
async with TaskGroup() as group:
await group.spawn(receive_request)
await group.spawn(send_request)
Expand Down Expand Up @@ -915,7 +915,7 @@ async def receive_request():
for req, request in zip(batch, requests):
assert req == request

async with timeout_after(0.01):
async with timeout_after(0.2):
async with TaskGroup() as group:
await group.spawn(receive_request)
await group.spawn(send_request)
Expand Down Expand Up @@ -988,7 +988,7 @@ async def receive_request():
requests = connection.receive_message(message)
assert requests == [req]

async with timeout_after(0.01):
async with timeout_after(0.2):
async with TaskGroup() as group:
await group.spawn(receive_request)
await group.spawn(send_request)
Expand Down
14 changes: 8 additions & 6 deletions tests/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(self, *args, **kwargs):

@classmethod
async def current_server(self):
await sleep(0)
await sleep(0.05)
return self.sessions[0]

async def connection_lost(self):
Expand Down Expand Up @@ -190,12 +190,13 @@ async def test_error_base_cost(self, server_port):
server_session = await MyServerSession.current_server()
server_session.error_base_cost = server_session.cost_hard_limit * 1.1
await session._send_message(b'')
await sleep(0.01)
await sleep(0.05)
assert server_session.errors == 1
assert server_session.cost > server_session.cost_hard_limit
# Check next request raises and cuts us off
with pytest.raises(RPCError):
await session.send_request('echo', [23])
await sleep(0.02)
assert session.is_closing()

@pytest.mark.asyncio
Expand All @@ -207,7 +208,7 @@ async def test_RPCError_cost(self, server_port):
with pytest.raises(RPCError):
await session.send_request('costly_error', [1000])
# It can trigger a cost recalc which refunds a tad
epsilon = 0.1
epsilon = 1
assert server_session.cost > server_session.error_base_cost + 1000 - epsilon

@pytest.mark.asyncio
Expand Down Expand Up @@ -381,9 +382,9 @@ async def test_concurrency_decay(self, server_port):
async with connect_rs('localhost', server_port) as session:
session.cost_decay_per_sec = 100
session.cost = 1000
await sleep(0.01)
await sleep(0.1)
session.recalc_concurrency()
assert 990 < session.cost < 999.1
assert 970 < session.cost < 992

@pytest.mark.asyncio
async def test_concurrency_hard_limit_0(self, server_port):
Expand Down Expand Up @@ -450,6 +451,7 @@ async def test_reply_and_disconnect_error(self, server_port):
async with connect_rs('localhost', server_port) as session:
with pytest.raises(RPCError) as e:
assert await session.send_request('disconnect')
await sleep(0.001)
exc = e.value
assert exc.code == 1 and exc.message == 'incompatible version'
assert session.is_closing()
Expand Down Expand Up @@ -855,7 +857,7 @@ async def test_request_over_hard_limit(self, msg_server_port):
server = await MessageServer.current_server()
server.bump_cost(server.cost_hard_limit + 100)
await session.send_message((b'version', b'abc'))
await sleep(0.005)
await sleep(0.05)
assert session.is_closing()

@pytest.mark.asyncio
Expand Down

0 comments on commit 3e604c5

Please sign in to comment.