diff --git a/tests/test_benchmarks_web_urldispatcher.py b/tests/test_benchmarks_web_urldispatcher.py index 452f4afa7b3..16a59516b35 100644 --- a/tests/test_benchmarks_web_urldispatcher.py +++ b/tests/test_benchmarks_web_urldispatcher.py @@ -173,7 +173,7 @@ def _run() -> None: loop.run_until_complete(run_url_dispatcher_benchmark()) -def test_resolve_dynamic_resource_url_with_many_routes( +def test_resolve_dynamic_resource_url_with_many_static_routes( loop: asyncio.AbstractEventLoop, benchmark: BenchmarkFixture, ) -> None: @@ -203,6 +203,68 @@ def _run() -> None: loop.run_until_complete(run_url_dispatcher_benchmark()) +def test_resolve_dynamic_resource_url_with_many_dynamic_routes( + loop: asyncio.AbstractEventLoop, + benchmark: BenchmarkFixture, +) -> None: + """Resolve different a DynamicResource when there are 250 DynamicResources registered.""" + + async def handler(request: web.Request) -> NoReturn: + assert False + + app = web.Application() + for count in range(250): + app.router.add_route( + "GET", f"/api/server/other/{{customer}}/update{count}", handler + ) + app.router.add_route("GET", "/api/server/dispatch/{customer}/update", handler) + app.freeze() + router = app.router + + requests = [ + _mock_request(method="GET", path=f"/api/server/dispatch/{customer}/update") + for customer in range(250) + ] + + async def run_url_dispatcher_benchmark() -> None: + for request in requests: + await router.resolve(request) + + @benchmark + def _run() -> None: + loop.run_until_complete(run_url_dispatcher_benchmark()) + + +def test_resolve_dynamic_resource_url_with_many_dynamic_routes_with_common_prefix( + loop: asyncio.AbstractEventLoop, + benchmark: BenchmarkFixture, +) -> None: + """Resolve different a DynamicResource when there are 250 DynamicResources registered with the same common prefix.""" + + async def handler(request: web.Request) -> NoReturn: + assert False + + app = web.Application() + for count in range(250): + app.router.add_route("GET", f"/api/{{customer}}/show_{count}", handler) + app.router.add_route("GET", "/api/{customer}/update", handler) + app.freeze() + router = app.router + + requests = [ + _mock_request(method="GET", path=f"/api/{customer}/update") + for customer in range(250) + ] + + async def run_url_dispatcher_benchmark() -> None: + for request in requests: + await router.resolve(request) + + @benchmark + def _run() -> None: + loop.run_until_complete(run_url_dispatcher_benchmark()) + + def test_resolve_gitapi( loop: asyncio.AbstractEventLoop, benchmark: BenchmarkFixture,