fix server tests
This commit is contained in:
parent
a53a59c82f
commit
57d3589769
1 changed files with 31 additions and 47 deletions
|
@ -205,27 +205,20 @@ def step_start_server(context):
|
||||||
async def step_wait_for_the_server_to_be_started(context, expecting_status: Literal['healthy', 'ready', 'idle', 'busy'] | str):
|
async def step_wait_for_the_server_to_be_started(context, expecting_status: Literal['healthy', 'ready', 'idle', 'busy'] | str):
|
||||||
match expecting_status:
|
match expecting_status:
|
||||||
case 'healthy':
|
case 'healthy':
|
||||||
await wait_for_health_status(context, context.base_url, 200, 'ok',
|
await wait_for_slots_status(context, context.base_url, 200,
|
||||||
timeout=30)
|
timeout=30)
|
||||||
|
|
||||||
case 'ready' | 'idle':
|
case 'ready' | 'idle':
|
||||||
await wait_for_health_status(context, context.base_url, 200, 'ok',
|
await wait_for_slots_status(context, context.base_url, 200,
|
||||||
timeout=30,
|
timeout=30,
|
||||||
params={'fail_on_no_slot': 0, 'include_slots': 0},
|
params={'fail_on_no_slot': 1},
|
||||||
slots_idle=context.n_slots,
|
slots_idle=context.n_slots,
|
||||||
slots_processing=0,
|
slots_processing=0)
|
||||||
expected_slots=[{'id': slot_id, 'state': 0}
|
|
||||||
for slot_id in
|
|
||||||
range(context.n_slots if context.n_slots else 1)])
|
|
||||||
case 'busy':
|
case 'busy':
|
||||||
await wait_for_health_status(context, context.base_url, 503,
|
await wait_for_slots_status(context, context.base_url, 503,
|
||||||
'no slot available',
|
params={'fail_on_no_slot': 1},
|
||||||
params={'fail_on_no_slot': 0, 'include_slots': 0},
|
slots_idle=0,
|
||||||
slots_idle=0,
|
slots_processing=context.n_slots)
|
||||||
slots_processing=context.n_slots,
|
|
||||||
expected_slots=[{'id': slot_id, 'state': 1}
|
|
||||||
for slot_id in
|
|
||||||
range(context.n_slots if context.n_slots else 1)])
|
|
||||||
case _:
|
case _:
|
||||||
assert False, "unknown status"
|
assert False, "unknown status"
|
||||||
|
|
||||||
|
@ -1187,17 +1180,15 @@ async def gather_tasks_results(context):
|
||||||
return n_completions
|
return n_completions
|
||||||
|
|
||||||
|
|
||||||
async def wait_for_health_status(context,
|
async def wait_for_slots_status(context,
|
||||||
base_url,
|
base_url,
|
||||||
expected_http_status_code,
|
expected_http_status_code,
|
||||||
expected_health_status,
|
timeout=3,
|
||||||
timeout=3,
|
params=None,
|
||||||
params=None,
|
slots_idle=None,
|
||||||
slots_idle=None,
|
slots_processing=None):
|
||||||
slots_processing=None,
|
|
||||||
expected_slots=None):
|
|
||||||
if context.debug:
|
if context.debug:
|
||||||
print(f"Starting checking for health for expected_health_status={expected_health_status}")
|
print(f"Starting checking for health for expected_http_status_code={expected_http_status_code}")
|
||||||
interval = 0.5
|
interval = 0.5
|
||||||
counter = 0
|
counter = 0
|
||||||
if 'GITHUB_ACTIONS' in os.environ:
|
if 'GITHUB_ACTIONS' in os.environ:
|
||||||
|
@ -1205,26 +1196,19 @@ async def wait_for_health_status(context,
|
||||||
|
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
while True:
|
while True:
|
||||||
async with await session.get(f'{base_url}/health', params=params) as health_response:
|
async with await session.get(f'{base_url}/slots', params=params) as slots_response:
|
||||||
status_code = health_response.status
|
status_code = slots_response.status
|
||||||
health = await health_response.json()
|
slots = await slots_response.json()
|
||||||
if context.debug:
|
if context.debug:
|
||||||
print(f"HEALTH - response for expected health status='{expected_health_status}' on "
|
print(f"slots responses {slots}\n")
|
||||||
f"'{base_url}/health'?{params} is {health}\n")
|
if status_code == 503 and status_code == expected_http_status_code:
|
||||||
if (status_code == expected_http_status_code
|
return
|
||||||
and health['status'] == expected_health_status
|
if status_code == 200 and status_code == expected_http_status_code:
|
||||||
and (slots_idle is None or health['slots_idle'] == slots_idle)
|
n_slots_idle = sum(1 if slot["state"] == 0 else 0 for slot in slots)
|
||||||
and (slots_processing is None or health['slots_processing'] == slots_processing)):
|
n_slots_processing = sum(1 if slot["state"] != 0 else 0 for slot in slots)
|
||||||
if expected_slots is not None:
|
if ((slots_idle is None or slots_idle == n_slots_idle)
|
||||||
assert_slots_status(health['slots'], expected_slots)
|
and (slots_processing is None or slots_processing == n_slots_processing)):
|
||||||
return
|
return
|
||||||
if (status_code == expected_http_status_code
|
|
||||||
and health['status'] == expected_health_status
|
|
||||||
and (slots_idle is None or health['slots_idle'] == slots_idle)
|
|
||||||
and (slots_processing is None or health['slots_processing'] == slots_processing)):
|
|
||||||
if expected_slots is not None:
|
|
||||||
assert_slots_status(health['slots'], expected_slots)
|
|
||||||
return
|
|
||||||
await asyncio.sleep(interval)
|
await asyncio.sleep(interval)
|
||||||
|
|
||||||
counter += interval
|
counter += interval
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue