Skip to content

Commit

Permalink
tests: rm redundant calls, cover unreachable call
Browse files Browse the repository at this point in the history
  • Loading branch information
Olegt0rr committed Dec 5, 2023
1 parent 8e3d591 commit c2da88b
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions tests/test_sse.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,19 +399,27 @@ async def func(request):
@pytest.mark.asyncio
async def test_connection_is_not_alive(loop, unused_tcp_port, session):
async def func(request):

# within context manager first preparation is already done
async with sse_response(request) as resp: # type: EventSourceResponse
resp.ping_interval = 1

# we should sleep to switch asyncio Task
# and let connection to be closed
await asyncio.sleep(0.1)

# this call should be cancelled, cause connection is closed
await resp.prepare(request)
return resp

return resp # pragma: no cover

app = web.Application()
app.router.add_route("GET", "/", func)

host = "127.0.0.1"
runner = await make_runner(app, host, unused_tcp_port)

async with session.request("GET", f"http://{host}:{unused_tcp_port}/") as resp:
resp.close()
async with session.get(f"http://{host}:{unused_tcp_port}/") as resp:
assert resp.status == 200

await runner.cleanup()

0 comments on commit c2da88b

Please sign in to comment.