|
8 | 8 |
|
9 | 9 | import pytest |
10 | 10 |
|
| 11 | +from rock import InternalServerRockError |
11 | 12 | from rock.actions.sandbox.response import State |
12 | 13 | from rock.admin.proto.response import SandboxStartResponse |
13 | 14 | from rock.common.constants import StopReason |
14 | 15 | from rock.config import AutoTransitionConfig, SandboxLifecycleConfig |
15 | 16 | from rock.sandbox.sandbox_manager import SandboxManager |
| 17 | +from rock.sandbox.sandbox_statemachine import SandboxLifecycleHelper |
16 | 18 | from rock.sdk.common.exceptions import BadRequestRockError |
17 | 19 |
|
18 | 20 |
|
@@ -428,22 +430,31 @@ async def assert_pending_exists(*args, **kwargs): |
428 | 430 | assert mock_meta_store.update.await_count == 2 |
429 | 431 |
|
430 | 432 | @pytest.mark.asyncio |
431 | | - async def test_submit_failure_keeps_pending_record_with_spec_timeout_and_effective_policy( |
| 433 | + async def test_submit_failure_marks_pending_record_for_immediate_deletion( |
432 | 434 | self, mgr_start, mock_meta_store, mock_operator, mock_docker_config |
433 | 435 | ): |
434 | | - mock_docker_config.auto_delete_seconds = 7200 |
| 436 | + mock_docker_config.auto_archive_seconds = 600 |
435 | 437 | mock_operator.submit.side_effect = RuntimeError("ray submit failed") |
436 | 438 |
|
437 | | - with pytest.raises(RuntimeError, match="ray submit failed"): |
| 439 | + with pytest.raises( |
| 440 | + InternalServerRockError, |
| 441 | + match="Sandbox sb-1 submission failed and has been marked for immediate deletion: ray submit failed", |
| 442 | + ): |
438 | 443 | await mgr_start.start_async(MagicMock(image="python:3.11")) |
439 | 444 |
|
440 | 445 | mock_meta_store.create.assert_awaited_once() |
441 | 446 | assert mock_meta_store.create.await_args.kwargs["timeout_info"] |
442 | | - assert mgr_start.created_spec["auto_delete_seconds"] == 7200 |
443 | | - mock_meta_store.update.assert_awaited_once() |
444 | | - pending_info = mock_meta_store.update.await_args.args[1] |
| 447 | + assert mgr_start.created_spec["auto_archive_seconds"] == 600 |
| 448 | + assert mock_meta_store.update.await_count == 2 |
| 449 | + pending_info = mock_meta_store.update.await_args_list[-1].args[1] |
445 | 450 | assert pending_info["state"] == State.PENDING |
446 | | - assert pending_info["auto_delete_seconds"] == 3600 |
| 451 | + assert pending_info["auto_delete_seconds"] == 0 |
| 452 | + assert pending_info["auto_archive_seconds"] is None |
| 453 | + assert SandboxLifecycleHelper.resolve_auto_archive_seconds(pending_info) is None |
| 454 | + assert SandboxLifecycleHelper.resolve_auto_delete_seconds(pending_info) == 0 |
| 455 | + mock_meta_store.update_timeout.assert_awaited_once() |
| 456 | + timeout_info = mock_meta_store.update_timeout.await_args.args[1] |
| 457 | + assert timeout_info["auto_clear_time"] == "0" |
447 | 458 |
|
448 | 459 | @pytest.mark.asyncio |
449 | 460 | async def test_uses_cluster_auto_delete_when_user_policy_is_unspecified( |
|
0 commit comments