Skip to content

Commit 8393f81

Browse files
authored
fix: resolve rich render error (#19)
1 parent 16e71de commit 8393f81

File tree

5 files changed

+629
-715
lines changed

5 files changed

+629
-715
lines changed

asgi_bench/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import click
1+
import rich_click as click
22

33
from asgi_bench import results
44
from asgi_bench.build import build_docker_images, remove_docker_images

asgi_bench/runner.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@
2727

2828

2929
def _header_args_from_spec(test_spec: TestSpec) -> list[str]:
30-
params = []
31-
for header, value in test_spec.headers:
32-
params.append(f'--header="{header}: {value}"')
33-
return params
30+
return [f'--header="{header}: {value}"' for header, value in test_spec.headers]
3431

3532

3633
def _args_from_spec(test_spec: TestSpec) -> list[str]:
@@ -42,8 +39,7 @@ def _args_from_spec(test_spec: TestSpec) -> list[str]:
4239
if duration := test_spec.time_limit:
4340
args.append(f"--duration={duration}s")
4441
if body_file := test_spec.body_file:
45-
args.append(f"--body-file=test_data/{body_file}")
46-
args.append("--method=POST")
42+
args.extend((f"--body-file=test_data/{body_file}", "--method=POST"))
4743
return args
4844

4945

@@ -109,8 +105,8 @@ def print_suite_config(self) -> None:
109105
if "rps" in self._benchmark_modes:
110106
table.add_row("RPS benchmarks duration", f"{self._time_limit} seconds")
111107
if "latency" in self._benchmark_modes:
112-
table.add_row("Latency benchmarks RPS limit", self._rate_limit)
113-
table.add_row("Latency benchmarks requests limit", self._request_limit)
108+
table.add_row("Latency benchmarks RPS limit", str(self._rate_limit))
109+
table.add_row("Latency benchmarks requests limit", str(self._request_limit))
114110
table.add_row("Warmup time", f"{self._warmup_time} seconds")
115111
table.add_row("Endpoint modes", ", ".join(self._endpoint_modes))
116112
table.add_row("Endpoint categories", ", ".join(self._categories))
@@ -193,8 +189,7 @@ def run_benchmark(self, test_spec: TestSpec) -> dict[str, Any]:
193189
*_args_from_spec(test_spec),
194190
)
195191
results = json.loads(res)
196-
error_percentage = get_error_percentage(results["result"])
197-
if error_percentage:
192+
if error_percentage := get_error_percentage(results["result"]):
198193
self.console.print(f" [red][Error][/red] {test_spec.pretty_name} with errors ({error_percentage}%)")
199194
else:
200195
self.console.print(f" [green][Completed][/green] {test_spec.pretty_name}")
@@ -212,7 +207,10 @@ def provide_service(self, spec: FrameworkSpec) -> Generator[bool, None, None]:
212207
try:
213208
container.kill()
214209
except APIError as error:
215-
if not (error.status_code == 409 and "not running" in error.explanation):
210+
if (
211+
error.status_code != 409
212+
or "not running" not in error.explanation
213+
):
216214
# the container stopped for reasons
217215
raise error
218216
yield False

0 commit comments

Comments
 (0)