Files
exo/worker/test_worker_state.py
T
Alex Cheema bb7f1ae994 New worker
Co-authored-by: Matt Beton <matthew.beton@gmail.com>
2025-07-18 10:08:56 +01:00

49 lines
1.3 KiB
Python

## Tests for worker state differentials
## When the worker state changes, this should be reflected by a worker intention.
import asyncio
from typing import Callable
from uuid import uuid4
import pytest
from shared.types.common import NodeId
from shared.types.states.worker import NodeStatusState, WorkerState
from shared.types.worker.common import InstanceId, NodeStatus
from shared.types.worker.instances import Instance
from worker.main import Worker
@pytest.mark.asyncio
async def test_worker_runs_and_stops(worker: Worker):
await worker.start()
await asyncio.sleep(0.01)
assert worker._is_running # type: ignore
await worker.stop()
await asyncio.sleep(0.01)
assert not worker._is_running # type: ignore
@pytest.mark.asyncio
async def test_worker_instance_added(worker: Worker, instance: Callable[[NodeId], Instance]):
await worker.start()
await asyncio.sleep(0.01)
worker.state.instances.instances = {InstanceId(uuid4()): instance(worker.node_id)}
print(worker.state.instances.instances)
def test_plan_noop(worker: Worker):
s = WorkerState(
node_status=NodeStatusState(
node_status={
NodeId(uuid4()): NodeStatus.Idle
}
),
)
next_op = worker.plan(s)
assert next_op is None