import aiohttp
import asyncio


async def test_download_speed(session: aiohttp.ClientSession, url: str) -> int:
    """Count the amount of data successfully downloaded."""
    result = 0
    try:
        async with session.get(url) as resp:
            while True:
                chunk = await resp.content.read(56)
                if not chunk:
                    break
                else:
                    result += len(chunk)
    except asyncio.CancelledError:
        pass
    finally:
        return result