Skip to content

Commit 7205661

Browse files
[PR #10553/55c5f1fc backport][3.11] Add benchmark for JSON post requests that check the content type (#10554)
**This is a backport of PR #10553 as merged into master (55c5f1f).** <!-- Thank you for your contribution! --> ## What do these changes do? Add benchmark for JSON post requests that check the content type ## Are there changes in behavior for the user? no ## Is it a substantial burden for the maintainers to support this? no Co-authored-by: J. Nick Koston <[email protected]>
1 parent 40fe535 commit 7205661

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

tests/test_benchmarks_client.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,3 +319,30 @@ async def run_client_benchmark() -> None:
319319
@benchmark
320320
def _run() -> None:
321321
loop.run_until_complete(run_client_benchmark())
322+
323+
324+
def test_one_hundred_json_post_requests(
325+
loop: asyncio.AbstractEventLoop,
326+
aiohttp_client: AiohttpClient,
327+
benchmark: BenchmarkFixture,
328+
) -> None:
329+
"""Benchmark 100 JSON POST requests that check the content-type."""
330+
message_count = 100
331+
332+
async def handler(request: web.Request) -> web.Response:
333+
_ = request.content_type
334+
_ = request.charset
335+
return web.Response()
336+
337+
app = web.Application()
338+
app.router.add_route("POST", "/", handler)
339+
340+
async def run_client_benchmark() -> None:
341+
client = await aiohttp_client(app)
342+
for _ in range(message_count):
343+
await client.post("/", json={"key": "value"})
344+
await client.close()
345+
346+
@benchmark
347+
def _run() -> None:
348+
loop.run_until_complete(run_client_benchmark())

0 commit comments

Comments
 (0)