fix sandbox create rollback gap
This commit is contained in:
parent
b4a2a9ceea
commit
9b6c7908ad
3 changed files with 94 additions and 3 deletions
|
|
@ -669,6 +669,39 @@ def test_create_sandbox_error_records_observability(monkeypatch) -> None:
|
|||
assert excinfo.value in span.errors
|
||||
|
||||
|
||||
def test_create_sandbox_save_failure_stops_untracked_container(monkeypatch) -> None:
|
||||
now = datetime(2026, 4, 2, 12, 0, tzinfo=UTC)
|
||||
repository = FailingSaveRepository(RuntimeError('save_failed'))
|
||||
repository.fail_next_save()
|
||||
metrics = RecordingMetrics()
|
||||
runtime = FakeRuntime()
|
||||
usecase = CreateSandbox(
|
||||
repository=repository,
|
||||
locker=FakeLocker(),
|
||||
runtime=runtime,
|
||||
clock=FakeClock(now),
|
||||
logger=FakeLogger(),
|
||||
metrics=metrics,
|
||||
tracer=NoopTracer(),
|
||||
ttl=timedelta(minutes=5),
|
||||
)
|
||||
monkeypatch.setattr('usecase.sandbox._new_session_id', lambda: SESSION_NEW_ID)
|
||||
|
||||
with pytest.raises(RuntimeError, match='save_failed'):
|
||||
usecase.execute(CreateSandboxCommand(chat_id=CHAT_ID))
|
||||
|
||||
assert len(runtime.create_calls) == 1
|
||||
assert runtime.stop_calls == [f'container-{SESSION_NEW_ID}']
|
||||
assert repository.get_active_by_chat_id(CHAT_ID) is None
|
||||
assert _active_count_values(metrics)
|
||||
assert _active_count_values(metrics)[-1] == 0
|
||||
_assert_increment_metric_present(
|
||||
metrics,
|
||||
'sandbox.create.total',
|
||||
attrs={'result': 'error'},
|
||||
)
|
||||
|
||||
|
||||
def test_create_sandbox_replace_stop_failure_preserves_separate_identities(
|
||||
monkeypatch,
|
||||
) -> None:
|
||||
|
|
@ -755,9 +788,11 @@ def test_create_sandbox_replace_save_failure_records_stage_safe_trace_ids(
|
|||
with pytest.raises(RuntimeError, match='save_failed') as excinfo:
|
||||
usecase.execute(CreateSandboxCommand(chat_id=CHAT_ID))
|
||||
|
||||
assert runtime.stop_calls == ['container-old']
|
||||
assert runtime.stop_calls == ['container-old', f'container-{SESSION_NEW_ID}']
|
||||
assert len(runtime.create_calls) == 1
|
||||
assert repository.get_active_by_chat_id(CHAT_ID) is None
|
||||
assert _active_count_values(metrics)
|
||||
assert _active_count_values(metrics)[-1] == 0
|
||||
_assert_increment_metric_present(
|
||||
metrics,
|
||||
'sandbox.create.total',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue