You've already forked request-coalescing-py
mirror of
https://github.com/hexolan/request-coalescing-py.git
synced 2026-03-26 18:21:16 +00:00
initial commit
This commit is contained in:
25
tests/test_coalesced.py
Normal file
25
tests/test_coalesced.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import asyncio
|
||||
from datetime import datetime
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_coalesced_requests(client) -> None:
|
||||
print("Making 5x100 concurrent requests (500 total)...")
|
||||
|
||||
async def make_requests():
|
||||
for _ in range(100):
|
||||
response = await client.get("/coalesced/1")
|
||||
assert response.status_code == 200
|
||||
|
||||
# Make the requests concurrently and wait until they complete
|
||||
start_time = datetime.now()
|
||||
tasks = [asyncio.create_task(make_requests()) for _ in range(5)]
|
||||
for task in tasks:
|
||||
await task
|
||||
print("Coalesced Requests: Took {delta}ms".format(delta=(datetime.now() - start_time).microseconds / 1000))
|
||||
|
||||
# View the metrics
|
||||
metrics = await client.get("/metrics")
|
||||
print("Coalesced Metrics:", metrics.json())
|
||||
Reference in New Issue
Block a user