Skip to content

Commit

Permalink
Reduce reliance on timing issues
Browse files Browse the repository at this point in the history
Install websockets as separate step to uvloop which isn't on Windows

More timing fixes
  • Loading branch information
Neil Booth committed Feb 4, 2021
1 parent 8d38b47 commit 7bf5f97
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .azure-pipelines/prepare-env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ parameters:

steps:
- script: |
python -m pip install websockets uvloop
python -m pip install websockets
python -m pip install uvloop
python -m pip install pycodestyle pylint
python -m pip install coveralls coverage
python -m pip install pytest pytest-asyncio Sphinx
Expand Down
12 changes: 6 additions & 6 deletions tests/test_curio.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ async def test_tg_spawn():

@pytest.mark.asyncio
async def test_tg_cancel_remaining():
tasks = [await spawn(sleep, x/200) for x in range(1, 4)]
tasks = [await spawn(sleep, x) for x in (0.001, 0.2, 0.3, 0.4)]
t = TaskGroup(tasks)
assert await t.next_done()
await t.cancel_remaining()
Expand Down Expand Up @@ -175,7 +175,7 @@ async def test_tg_join_object():

tasks = [await spawn(return_value(None, 0.01)),
await spawn(return_value(4, 0.02)),
await spawn(return_value(2, 0.03))]
await spawn(return_value(2, 0.1))]
t = TaskGroup(tasks, wait=object)
await t.join()
assert tasks[0].result() == None
Expand All @@ -196,7 +196,7 @@ async def test_tg_cm_object():

tasks = [await spawn(return_value(None, 0.01)),
await spawn(return_value(4, 0.02)),
await spawn(return_value(2, 0.03))]
await spawn(return_value(2, 0.1))]
async with TaskGroup(tasks, wait=object) as t:
pass
assert tasks[0].result() == None
Expand Down Expand Up @@ -370,10 +370,10 @@ async def t1(*values):
@pytest.mark.asyncio
async def test_timeout_after_no_expire():
async def t1(*values):
return await return_after_sleep(1 + sum(values), 0.01)
return await return_after_sleep(1 + sum(values), 0.005)

try:
assert await timeout_after(0.02, t1, 1) == 2
assert await timeout_after(0.04, t1, 1) == 2
except TaskTimeout:
assert False
await sleep(0.02)
Expand Down Expand Up @@ -733,7 +733,7 @@ async def test_ignore_after_no_expire():
async def t1(*values):
return await return_after_sleep(1 + sum(values), 0.001)

assert await ignore_after(0.005, t1, 1) == 2
assert await ignore_after(0.02, t1, 1) == 2
await sleep(0.002)


Expand Down
4 changes: 2 additions & 2 deletions tests/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ async def test_slow_connection_aborted(self, server_port):
protocol.pause_writing()
assert not protocol._can_send.is_set()
task = await spawn(session._send_message(b'a'))
await sleep(session.max_send_delay * 3)
await sleep(0.1)
assert task.cancelled()
assert protocol._can_send.is_set()
assert session.is_closing()
Expand Down Expand Up @@ -391,7 +391,7 @@ async def test_concurrency_decay(self, server_port):
session.cost = 1000
await sleep(0.01)
session.recalc_concurrency()
assert 995 < session.cost < 999.1
assert 990 < session.cost < 999.1

@pytest.mark.asyncio
async def test_concurrency_hard_limit_0(self, server_port):
Expand Down

0 comments on commit 7bf5f97

Please sign in to comment.