Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions rock/sandbox/sandbox_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,10 @@ async def get_status(self, sandbox_id, include_all_states: bool = False) -> Sand

if is_alive and state == State.PENDING:
sm = await self._get_current_statemachine(sandbox_id)
await sm.send(
"alive", sandbox_id=sandbox_id, meta_store=self._meta_store, sandbox_info=operator_sandbox_info
)
if sm.current_state.value == State.PENDING:
await sm.send(
"alive", sandbox_id=sandbox_id, meta_store=self._meta_store, sandbox_info=operator_sandbox_info
)

if operator_sandbox_info.get("state") in (State.PENDING, State.RUNNING):
await self._refresh_timeout(sandbox_id)
Expand Down
19 changes: 18 additions & 1 deletion tests/unit/sandbox/test_get_status_include_all_states.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
- start_time/stop_time/create_time populated in every response
"""

from unittest.mock import AsyncMock, patch
from unittest.mock import AsyncMock, MagicMock, patch

import pytest

Expand Down Expand Up @@ -93,3 +93,20 @@ async def test_running_state_skips_state_machine_init(self, sandbox_manager, moc

# State machine should NOT be initialized when no PENDING→RUNNING transition needed
sandbox_manager._get_current_statemachine.assert_not_called()

@pytest.mark.asyncio
async def test_running_operator_status_skips_alive_when_current_state_already_running(
self, sandbox_manager, mock_operator
):
"""Avoid double-sending alive when another status refresh already advanced the state machine."""
mock_operator.get_status = AsyncMock(return_value=_make_sandbox_info(state=State.RUNNING))
mock_sm = MagicMock()
mock_sm.current_state.value = State.RUNNING
mock_sm.send = AsyncMock()
sandbox_manager._get_current_statemachine = AsyncMock(return_value=mock_sm)

result = await sandbox_manager.get_status("sandbox-1")

assert result.is_alive is True
sandbox_manager._get_current_statemachine.assert_awaited_once_with("sandbox-1")
mock_sm.send.assert_not_awaited()
Loading