Files
agentic-mobile-control/packages/cloud-platform/tests/test_scheduler.py
T

53 lines
1.6 KiB
Python

"""Tests for the cloud TaskScheduler, focused on skipping MCP-busy devices."""
from __future__ import annotations
import tempfile
from pathlib import Path
import pytest
from cloud.config import CloudConfig
from cloud.pool import DevicePool
from cloud.scheduler import TaskConstraints, TaskScheduler
from cloud.store import CloudStore
from core.models import Device
@pytest.fixture
def pool() -> DevicePool:
with tempfile.TemporaryDirectory() as tmp:
store = CloudStore(Path(tmp) / "cloud.sqlite3")
try:
yield DevicePool(store=store, config=CloudConfig())
finally:
store.close()
def _device(device_id: str, *, status: str = "idle") -> Device:
return Device(
id=device_id,
driver_type="wda",
status=status, # type: ignore[arg-type]
capability_tags=[],
)
def test_mcp_busy_device_is_skipped_by_scheduler(pool: DevicePool) -> None:
"""A device with mcp_busy=True is not selected for assignment.
Two devices exist: dev-busy (idle status, mcp_busy=True) and dev-idle
(idle status, mcp_busy=False). One task is submitted with no
constraints, so both are candidates before the mcp_busy filter.
The scheduler must pick dev-idle.
"""
pool.sync_host_devices(
"host-1",
[_device("dev-busy"), _device("dev-idle")],
mcp_busy_device_ids=["dev-busy"],
)
scheduler = TaskScheduler(pool=pool, store=pool.store, config=CloudConfig())
scheduler.submit(goal="test", constraints=TaskConstraints())
assignments = scheduler.assign()
assert len(assignments) == 1
assert assignments[0].device_id == "dev-idle"