test: probe loop coverage — _run_instance_probe_loop transition logic #13

Closed
opened 2026-04-02 18:11:49 -07:00 by pyr0ball · 0 comments
Owner

Gap

_run_instance_probe_loop was shipped in v0.2.0 with no unit tests. The function contains three distinct code paths that need coverage:

  1. healthy pathGET /health returns 200 → state transitions starting → running
  2. timeout path — no healthy response within _PROBE_TIMEOUT_S → state transitions starting → stopped
  3. non-starting instancestart_times entry is cleaned up when state is no longer starting

Acceptance criteria

  • test_probe_transitions_starting_to_running — mock /health → 200; assert upsert_instance called with state="running"
  • test_probe_transitions_starting_to_stopped_on_timeout — mock time past _PROBE_TIMEOUT_S; assert upsert_instance called with state="stopped"
  • test_probe_cleans_up_start_times_for_non_starting — instance in running state; assert key removed from start_times dict
  • Tests use asyncio / pytest-asyncio; mock urllib.request.urlopen and time.time
  • All 3 new tests pass alongside the existing 145
## Gap `_run_instance_probe_loop` was shipped in v0.2.0 with no unit tests. The function contains three distinct code paths that need coverage: 1. **healthy path** — `GET /health` returns 200 → state transitions `starting → running` 2. **timeout path** — no healthy response within `_PROBE_TIMEOUT_S` → state transitions `starting → stopped` 3. **non-starting instance** — `start_times` entry is cleaned up when state is no longer `starting` ## Acceptance criteria - [ ] `test_probe_transitions_starting_to_running` — mock `/health` → 200; assert `upsert_instance` called with `state="running"` - [ ] `test_probe_transitions_starting_to_stopped_on_timeout` — mock time past `_PROBE_TIMEOUT_S`; assert `upsert_instance` called with `state="stopped"` - [ ] `test_probe_cleans_up_start_times_for_non_starting` — instance in `running` state; assert key removed from `start_times` dict - [ ] Tests use `asyncio` / `pytest-asyncio`; mock `urllib.request.urlopen` and `time.time` - [ ] All 3 new tests pass alongside the existing 145
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: Circuit-Forge/circuitforge-core#13
No description provided.