mirror of
https://github.com/fusion44/blitz_api.git
synced 2026-08-14 12:02:46 +02:00
'from redis.asyncio import ... TimeoutError' shadowed the builtin TimeoutError. redis's TimeoutError is a RedisError subclass, not a builtin subclass, so the 'except TimeoutError' guarding asyncio.wait_for never matched: timed-out commands fell through to the generic handler, the child process was never terminated (leak), and the caller got a misleading 'unable to execute' error instead of a timeout. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
23 lines
906 B
Python
23 lines
906 B
Python
"""
|
|
Regression test: exec_bash_command must actually catch the timeout raised
|
|
by asyncio.wait_for.
|
|
|
|
`from redis.asyncio import ... TimeoutError` used to shadow the builtin, so
|
|
`except TimeoutError` never matched asyncio's builtin TimeoutError. Timed-out
|
|
commands fell through to the generic handler, the child process was never
|
|
terminated, and the caller got a misleading "unable to execute" error.
|
|
"""
|
|
|
|
from app.api.utils import exec_bash_command
|
|
from app.external.result_type.src.result.result import Err
|
|
|
|
|
|
async def test_exec_bash_command_reports_timeout():
|
|
# `bash -c 'sleep 5'` with a 0.5s budget must time out
|
|
res = await exec_bash_command("-c 'sleep 5'", timeout=0.5)
|
|
|
|
assert isinstance(res, Err), "a timed-out command must return an Err"
|
|
message = res.err_value.format_verbose().lower()
|
|
assert "timed out" in message, (
|
|
f"expected a timeout error, got: {message}"
|
|
)
|