|
2 | 2 |
|
3 | 3 | import asyncio
|
4 | 4 | from http.cookies import Morsel
|
| 5 | +from typing import Union |
5 | 6 |
|
6 | 7 | from pytest_codspeed import BenchmarkFixture
|
7 | 8 | from yarl import URL
|
@@ -65,3 +66,46 @@ def _run() -> None:
|
65 | 66 | chunked=None,
|
66 | 67 | expect100=False,
|
67 | 68 | )
|
| 69 | + |
| 70 | + |
| 71 | +def test_send_client_request_one_hundred( |
| 72 | + loop: asyncio.AbstractEventLoop, benchmark: BenchmarkFixture |
| 73 | +) -> None: |
| 74 | + url = URL("http://python.org") |
| 75 | + req = ClientRequest("get", url, loop=loop) |
| 76 | + |
| 77 | + class MockTransport(asyncio.Transport): |
| 78 | + """Mock transport for testing that do no real I/O.""" |
| 79 | + |
| 80 | + def is_closing(self) -> bool: |
| 81 | + """Swallow is_closing.""" |
| 82 | + return False |
| 83 | + |
| 84 | + def write(self, data: Union[bytes, bytearray, memoryview]) -> None: |
| 85 | + """Swallow writes.""" |
| 86 | + |
| 87 | + class MockProtocol(asyncio.BaseProtocol): |
| 88 | + |
| 89 | + def __init__(self) -> None: |
| 90 | + self.transport = MockTransport() |
| 91 | + |
| 92 | + async def _drain_helper(self) -> None: |
| 93 | + """Swallow drain.""" |
| 94 | + |
| 95 | + def start_timeout(self) -> None: |
| 96 | + """Swallow start_timeout.""" |
| 97 | + |
| 98 | + class MockConnection: |
| 99 | + def __init__(self) -> None: |
| 100 | + self.transport = None |
| 101 | + self.protocol = MockProtocol() |
| 102 | + |
| 103 | + conn = MockConnection() |
| 104 | + |
| 105 | + async def send_requests() -> None: |
| 106 | + for _ in range(100): |
| 107 | + await req.send(conn) # type: ignore[arg-type] |
| 108 | + |
| 109 | + @benchmark |
| 110 | + def _run() -> None: |
| 111 | + loop.run_until_complete(send_requests()) |
0 commit comments