From b65fd9ebe9fe5363b1efb7a3b3ccfb884a73a857 Mon Sep 17 00:00:00 2001 From: Hugo Herter Date: Thu, 14 Mar 2024 09:38:09 +0100 Subject: [PATCH] Fix typing: FakeRequest class was not of type Request --- src/aleph/vm/orchestrator/cli.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/aleph/vm/orchestrator/cli.py b/src/aleph/vm/orchestrator/cli.py index 2a7cf783c..94b17d305 100644 --- a/src/aleph/vm/orchestrator/cli.py +++ b/src/aleph/vm/orchestrator/cli.py @@ -8,6 +8,7 @@ from pathlib import Path from statistics import mean from typing import Callable +from typing import Callable, Optional, cast from aiohttp.web import Request, Response from sqlalchemy.ext.asyncio import create_async_engine @@ -157,6 +158,15 @@ def parse_args(args): return parser.parse_args(args) +class FakeRequest: + headers: dict[str, str] + raw_headers: list[tuple[bytes, bytes]] + match_info: dict + method: str + query_string: str + read: Callable + + async def benchmark(runs: int): """Measure program performance by immediately running the supervisor with fake requests. @@ -167,16 +177,6 @@ async def benchmark(runs: int): ref = ItemHash("cafecafecafecafecafecafecafecafecafecafecafecafecafecafecafecafe") settings.FAKE_DATA_PROGRAM = settings.BENCHMARK_FAKE_DATA_PROGRAM - FakeRequest: Request - - class FakeRequest: # type: ignore[no-redef] - headers: dict[str, str] - raw_headers: list[tuple[bytes, bytes]] - match_info: dict - method: str - query_string: str - read: Callable - fake_request = FakeRequest() # type: ignore[operator] fake_request.match_info = {"ref": ref, "suffix": "/"} fake_request.method = "GET" @@ -219,7 +219,9 @@ async def fake_read() -> bytes: "/cache/keys", ): fake_request.match_info["suffix"] = path - response: Response = await run_code_on_request(vm_hash=ref, path=path, pool=pool, request=fake_request) + response: Response = await run_code_on_request( + vm_hash=ref, path=path, pool=pool, request=cast(Request, fake_request) + ) assert response.status == 200 # Disable VM timeout to exit benchmark properly @@ -228,7 +230,9 @@ async def fake_read() -> bytes: for _run in range(runs): t0 = time.time() fake_request.match_info["suffix"] = path - response2: Response = await run_code_on_request(vm_hash=ref, path=path, pool=pool, request=fake_request) + response2: Response = await run_code_on_request( + vm_hash=ref, path=path, pool=pool, request=cast(Request, fake_request) + ) assert response2.status == 200 bench.append(time.time() - t0)