Skip to content

Commit b65fd9e

Browse files
committed
Fix typing: FakeRequest class was not of type Request
1 parent a6508f1 commit b65fd9e

File tree

1 file changed

+16
-12
lines changed
  • src/aleph/vm/orchestrator

1 file changed

+16
-12
lines changed

src/aleph/vm/orchestrator/cli.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from pathlib import Path
99
from statistics import mean
1010
from typing import Callable
11+
from typing import Callable, Optional, cast
1112

1213
from aiohttp.web import Request, Response
1314
from sqlalchemy.ext.asyncio import create_async_engine
@@ -157,6 +158,15 @@ def parse_args(args):
157158
return parser.parse_args(args)
158159

159160

161+
class FakeRequest:
162+
headers: dict[str, str]
163+
raw_headers: list[tuple[bytes, bytes]]
164+
match_info: dict
165+
method: str
166+
query_string: str
167+
read: Callable
168+
169+
160170
async def benchmark(runs: int):
161171
"""Measure program performance by immediately running the supervisor
162172
with fake requests.
@@ -167,16 +177,6 @@ async def benchmark(runs: int):
167177
ref = ItemHash("cafecafecafecafecafecafecafecafecafecafecafecafecafecafecafecafe")
168178
settings.FAKE_DATA_PROGRAM = settings.BENCHMARK_FAKE_DATA_PROGRAM
169179

170-
FakeRequest: Request
171-
172-
class FakeRequest: # type: ignore[no-redef]
173-
headers: dict[str, str]
174-
raw_headers: list[tuple[bytes, bytes]]
175-
match_info: dict
176-
method: str
177-
query_string: str
178-
read: Callable
179-
180180
fake_request = FakeRequest() # type: ignore[operator]
181181
fake_request.match_info = {"ref": ref, "suffix": "/"}
182182
fake_request.method = "GET"
@@ -219,7 +219,9 @@ async def fake_read() -> bytes:
219219
"/cache/keys",
220220
):
221221
fake_request.match_info["suffix"] = path
222-
response: Response = await run_code_on_request(vm_hash=ref, path=path, pool=pool, request=fake_request)
222+
response: Response = await run_code_on_request(
223+
vm_hash=ref, path=path, pool=pool, request=cast(Request, fake_request)
224+
)
223225
assert response.status == 200
224226

225227
# Disable VM timeout to exit benchmark properly
@@ -228,7 +230,9 @@ async def fake_read() -> bytes:
228230
for _run in range(runs):
229231
t0 = time.time()
230232
fake_request.match_info["suffix"] = path
231-
response2: Response = await run_code_on_request(vm_hash=ref, path=path, pool=pool, request=fake_request)
233+
response2: Response = await run_code_on_request(
234+
vm_hash=ref, path=path, pool=pool, request=cast(Request, fake_request)
235+
)
232236
assert response2.status == 200
233237
bench.append(time.time() - t0)
234238

0 commit comments

Comments
 (0)