Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some flaky tests #7896

Merged
merged 1 commit into from
Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions tests/test_web_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,11 @@ async def test_no_handler_cancellation(aiohttp_unused_port) -> None:
timeout_event = asyncio.Event()
done_event = asyncio.Event()
port = aiohttp_unused_port()
started = False

async def on_request(_: web.Request) -> web.Response:
nonlocal done_event, timeout_event
nonlocal done_event, started, timeout_event
started = True
await asyncio.wait_for(timeout_event.wait(), timeout=5)
done_event.set()
return web.Response()
Expand All @@ -273,7 +275,7 @@ async def on_request(_: web.Request) -> web.Response:

try:
async with client.ClientSession(
timeout=client.ClientTimeout(total=0.1)
timeout=client.ClientTimeout(total=0.2)
) as sess:
with pytest.raises(asyncio.TimeoutError):
await sess.get(f"http://localhost:{port}/")
Expand All @@ -282,6 +284,7 @@ async def on_request(_: web.Request) -> web.Response:

with suppress(asyncio.TimeoutError):
await asyncio.wait_for(done_event.wait(), timeout=1)
assert started
assert done_event.is_set()
finally:
await asyncio.gather(runner.shutdown(), site.stop())
12 changes: 6 additions & 6 deletions tests/test_web_urldispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ async def test_access_root_of_static_handler(
client = await aiohttp_client(app)

# Request the root of the static directory.
r = await client.get(prefix)
assert r.status == status
async with await client.get(prefix) as r:
assert r.status == status

if data:
assert r.headers["Content-Type"] == "text/html; charset=utf-8"
read_ = await r.read()
assert read_ == data
if data:
assert r.headers["Content-Type"] == "text/html; charset=utf-8"
read_ = await r.read()
assert read_ == data


async def test_follow_symlink(
Expand Down