Skip to content

Commit e5e0229

Browse files
committed
wip
1 parent ea08f5e commit e5e0229

1 file changed

Lines changed: 28 additions & 6 deletions

File tree

tests/component/session/test_session_lifecycle.py

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
TransitSessionStatusRequest,
2424
)
2525
from ai.backend.common.dto.manager.session.response import (
26+
DestroySessionResponse,
2627
GetSessionInfoResponse,
2728
GetStatusHistoryResponse,
2829
TransitSessionStatusResponse,
@@ -147,9 +148,11 @@ async def test_restart_running_session(
147148
session_seed.session_name,
148149
RestartSessionRequest(),
149150
)
150-
# After restart, session should still be accessible
151+
# After restart, session should still be accessible and running
151152
result = await admin_registry.session.get_info(session_seed.session_name)
152153
assert isinstance(result, GetSessionInfoResponse)
154+
assert result.root["status"] == "RUNNING"
155+
assert result.root["domainName"] == session_seed.domain_name
153156

154157
async def test_restart_terminated_session_fails(
155158
self,
@@ -195,7 +198,8 @@ async def test_transit_single_session_status(
195198
TransitSessionStatusRequest(ids=[session_seed.session_id]),
196199
)
197200
assert isinstance(result, TransitSessionStatusResponse)
198-
assert isinstance(result.session_status_map, dict)
201+
assert session_seed.session_id in result.session_status_map
202+
assert result.session_status_map[session_seed.session_id] == SessionStatus.RUNNING.name
199203

200204
async def test_transit_multiple_sessions(
201205
self,
@@ -226,7 +230,8 @@ async def test_transit_multiple_sessions(
226230
),
227231
)
228232
assert isinstance(result, TransitSessionStatusResponse)
229-
assert isinstance(result.session_status_map, dict)
233+
assert session_seed.session_id in result.session_status_map
234+
assert terminated_session_seed.session_id in result.session_status_map
230235

231236
async def test_user_cannot_transit_others_session(
232237
self,
@@ -265,6 +270,10 @@ async def test_rename_back_and_forth(
265270
result = await admin_registry.session.get_info(new_name)
266271
assert isinstance(result, GetSessionInfoResponse)
267272
assert result.root["status"] == "RUNNING"
273+
assert result.root["domainName"] == session_seed.domain_name
274+
# Old name should no longer resolve
275+
with pytest.raises(NotFoundError):
276+
await admin_registry.session.get_info(original_name)
268277

269278
# Rename back to original name
270279
await admin_registry.session.rename(
@@ -274,6 +283,7 @@ async def test_rename_back_and_forth(
274283
result = await admin_registry.session.get_info(original_name)
275284
assert isinstance(result, GetSessionInfoResponse)
276285
assert result.root["status"] == "RUNNING"
286+
assert result.root["domainName"] == session_seed.domain_name
277287

278288
async def test_rename_to_same_name_is_rejected(
279289
self,
@@ -301,6 +311,10 @@ async def test_user_renames_own_session(
301311
result = await user_registry.session.get_info(new_name)
302312
assert isinstance(result, GetSessionInfoResponse)
303313
assert result.root["status"] == "RUNNING"
314+
assert result.root["domainName"] == user_session_seed.domain_name
315+
# Old name should no longer resolve
316+
with pytest.raises(NotFoundError):
317+
await user_registry.session.get_info(user_session_seed.session_name)
304318

305319

306320
class TestSessionPermissions:
@@ -315,6 +329,7 @@ async def test_admin_gets_own_session_info(
315329
result = await admin_registry.session.get_info(session_seed.session_name)
316330
assert isinstance(result, GetSessionInfoResponse)
317331
assert result.root["status"] == "RUNNING"
332+
assert result.root["domainName"] == session_seed.domain_name
318333

319334
async def test_user_gets_own_session_info(
320335
self,
@@ -325,6 +340,8 @@ async def test_user_gets_own_session_info(
325340
result = await user_registry.session.get_info(user_session_seed.session_name)
326341
assert isinstance(result, GetSessionInfoResponse)
327342
assert result.root["status"] == "RUNNING"
343+
assert result.root["domainName"] == user_session_seed.domain_name
344+
assert result.root["userId"] == str(user_session_seed.user_uuid)
328345

329346
async def test_user_cannot_access_admin_session(
330347
self,
@@ -419,6 +436,7 @@ async def test_user_gets_own_session_status_history(
419436
assert isinstance(result, GetStatusHistoryResponse)
420437
history = result.root
421438
assert isinstance(history, dict)
439+
assert "PENDING" in history
422440
assert "RUNNING" in history
423441

424442
async def test_user_cannot_access_admin_session_status_history(
@@ -446,7 +464,8 @@ async def test_destroy_already_terminated_session_succeeds(
446464
terminated_session_seed.session_name,
447465
DestroySessionRequest(forced=True),
448466
)
449-
assert result is not None
467+
assert isinstance(result, DestroySessionResponse)
468+
assert isinstance(result.root, dict)
450469

451470
async def test_user_destroys_own_session(
452471
self,
@@ -460,5 +479,8 @@ async def test_user_destroys_own_session(
460479
user_session_seed.session_name,
461480
DestroySessionRequest(forced=True),
462481
)
463-
# Verify the session status changed
464-
assert result is not None
482+
assert isinstance(result, DestroySessionResponse)
483+
assert isinstance(result.root, dict)
484+
# Session should no longer be accessible after destroy
485+
with pytest.raises((NotFoundError, BackendAPIError)):
486+
await user_registry.session.get_info(user_session_seed.session_name)

0 commit comments

Comments
 (0)