Skip to content
Closed
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
46 changes: 34 additions & 12 deletions tests/integration/core/sandbox/test_sandbox_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
projection drops the field, so it reads as empty too).
"""

import asyncio

import pytest
import pytest_asyncio

from blaxel.core import SandboxInstance
from tests.helpers import default_image, default_labels, default_region, unique_name
Expand All @@ -17,9 +20,26 @@
class TestSandboxErrors:
"""Test reading the infrastructure errors recorded on a sandbox."""

async def test_reads_empty_error_history_on_healthy_sandbox(self):
"""A sandbox that never hit an infrastructure failure reports no error."""
created_sandboxes: list[str] = []

@pytest_asyncio.fixture(autouse=True, scope="class", loop_scope="class")
async def cleanup(self, request):
request.cls.created_sandboxes = []
yield
await asyncio.gather(
*[self._safe_delete_sandbox(n) for n in request.cls.created_sandboxes],
return_exceptions=True,
)

async def _safe_delete_sandbox(self, name: str) -> None:
try:
await SandboxInstance.delete(name)
except Exception:
pass

async def _create_sandbox(self) -> str:
name = unique_name("errors")
self.created_sandboxes.append(name)
await SandboxInstance.create(
{
"name": name,
Expand All @@ -28,20 +48,22 @@ async def test_reads_empty_error_history_on_healthy_sandbox(self):
"labels": default_labels,
}
)
return name

try:
sandbox = await SandboxInstance.get(name)

# The shape of an entry (code, fatal, instance, message, time) is
# not exercisable here: covering it would mean provoking a real
# infrastructure failure on the compute plane.
assert isinstance(sandbox.errors, list)
assert sandbox.errors == []
finally:
await SandboxInstance.delete(name)
async def test_reads_empty_error_history_on_healthy_sandbox(self):
"""A sandbox that never hit an infrastructure failure reports no error."""
sandbox = await SandboxInstance.get(await self._create_sandbox())

# The shape of an entry (code, fatal, instance, message, time) is not
# exercisable here: covering it would mean provoking a real
# infrastructure failure on the compute plane.
assert isinstance(sandbox.errors, list)
assert sandbox.errors == []

async def test_listing_does_not_carry_the_error_history(self):
"""Listings project the field out, so they must not be read for it."""
await self._create_sandbox()

page = await SandboxInstance.list(limit=1)

assert len(page.data) > 0
Expand Down
Loading