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

Refactor sendfile #3383

Merged
merged 18 commits into from
Nov 8, 2018
Prev Previous commit
Next Next commit
Improve test
  • Loading branch information
asvetlov committed Nov 6, 2018
commit e1c029ece4fa24659c4ae5254c74a565f811fa7f
31 changes: 12 additions & 19 deletions tests/test_web_sendfile_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,22 +753,6 @@ async def handler(request):
await resp.release()


async def test_static_file_cancel(aiohttp_client) -> None:
filepath = pathlib.Path(__file__).parent / 'data.unknown_mime_type'

async def handler(request):
ret = web.FileResponse(filepath)
request.task.cancel()
return ret

app = web.Application()
app.router.add_get('/', handler)
client = await aiohttp_client(app)

resp = await client.get('/')
assert resp.status == 200 # cancelled after sending response headers


async def test_static_file_huge_cancel(aiohttp_client, tmpdir) -> None:
filename = 'huge_data.unknown_mime_type'

Expand All @@ -777,10 +761,12 @@ async def test_static_file_huge_cancel(aiohttp_client, tmpdir) -> None:
for i in range(1024*20):
f.write(chr(i % 64 + 0x20) * 1024)

task = None

async def handler(request):
nonlocal task
task = request.task
ret = web.FileResponse(pathlib.Path(tmpdir.join(filename)))
loop = asyncio.get_event_loop()
loop.call_later(0.01, request.task.cancel)
return ret

app = web.Application()
Expand All @@ -789,4 +775,11 @@ async def handler(request):
client = await aiohttp_client(app)

resp = await client.get('/')
assert resp.status == 200 # cancelled after sending response headers
task.cancel()
data = b''
while True:
try:
data += await resp.read()
except aiohttp.ClientPayloadError:
break
assert len(data) < 1024 * 1024 * 20