Add tests for the startup-grace chain through _run_once and the refusal re-stamp

Open
#46 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
52/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
fastapi, postgresql, python
Domain
backend, testing

Research direction

Read server/orcaster_server/housekeeping.py around _run_once and _expire_assigned, then review the existing DB helpers in server/tests/test_housekeeping.py and refusal tests in server/tests/test_poll_task_secrets.py. First determine how the other housekeeping passes interact with the test database. Done means real Postgres tests cover both grace outcomes and the restart, refused poll, re-stamp chain, with the required keyword-only argument updated at every caller.

Written by the indexing model from the issue text.

Description

enhancement help wanted P3 server

Problem

The startup grace keeps the pre-assigned execution of a refused worker alive after a server restart. Two links of this protection have no test that checks the real behavior end to end. A later refactor can break the protection and leave the suite green.

  • _run_once passes the flag to the expiry step: _expire_assigned(engine, in_grace=in_grace) (server/orcaster_server/housekeeping.py:556).
  • _expire_assigned has a default value, in_grace: bool = False (server/orcaster_server/housekeeping.py:445). A call without the argument is valid and silently means "no grace".
  • The DB tests for the grace call _expire_assigned directly (server/tests/test_housekeeping.py:359). They never go through _run_once.
  • Every test that calls _run_once passes engine=None and mocks the passes (for example server/tests/test_housekeeping.py:935, :966). The assertions on _expire_assigned (:941, :971) check the wiring only. No test runs the real SQL through _run_once.
  • The protection needs two steps. First, the grace pass keeps the execution although the refusal mark is old. Second, the refused poll of the returning worker re-stamps the mark (_SQL_POLL_MARK_SECRETS_REFUSED, server/orcaster_server/api/poll.py:984), so the first pass after the grace sees a fresh mark. Each step has its own test. No test chains the two. If the re-stamp stopped working after a restart, no test would fail.
  • After a restart the in-memory state is empty (_refusal_mark_written, _refusal_memory, server/orcaster_server/api/poll.py:1018-1019). A chained test must clear both to model a restart.

Proposed change

  1. Add a DB test that calls _run_once(engine, settings, in_grace=True) against real Postgres. Use a worker with a refusal mark aged 10 minutes and an overdue assigned execution of a task that declares task_env. Assert the status stays assigned. Run the same setup with in_grace=False and assert expired. The helper _expire_with_refused_worker (server/tests/test_housekeeping.py:312) is a base.
  2. Add one chained test in server/tests/test_poll_task_secrets.py:
    • age the mark to 10 minutes and make the execution overdue;
    • run a pass with in_grace=True and assert assigned;
    • clear poll._refusal_mark_written and poll._refusal_memory (a restart) and poll as the refused worker;
    • assert the mark is fresh (younger than 120 s);
    • run a pass with in_grace=False and assert assigned.
  3. Make in_grace a required keyword-only argument of _expire_assigned, and update the callers in the tests (server/tests/test_housekeeping.py:279, server/tests/test_poll_task_secrets.py:1534 and the others). A missing argument then raises TypeError.

Acceptance criteria

  • A DB test runs _run_once(engine, settings, in_grace=True) with a stale mark and asserts the execution is assigned.
  • A DB test runs _run_once(engine, settings, in_grace=False) with the same setup and asserts it is expired.
  • A chained test covers: grace pass keeps the execution, a refused poll re-stamps the mark, a pass after the grace still keeps it.
  • If in_grace=in_grace is removed from the call at server/orcaster_server/housekeeping.py:556, at least one DB-level test fails.
  • in_grace is a required keyword-only argument of _expire_assigned and all callers are updated.
  • Production behavior does not change: only tests and an internal function signature.
  • Lint, format check and the two test files pass.
  • CHANGELOG entry under Unreleased, if the maintainers record test-only changes there.

Open questions

  • _run_once also runs other passes (offline marking, lease reclaim, sticky pool, artifact reconcile, over-commit check). Are they harmless against the test database, or should the new test patch them so only the expiry step uses real SQL?
Dominant language
Python
Stars
0
Forks
0
Avg merge
1d 1h
Merged PRs (30d)
10

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from AInvirion/orcaster

All issues in AInvirion/orcaster

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.