Skip to content

Add internal state invariant tests and reorganize test directories#310

Merged
chrisguidry merged 3 commits intomainfrom
internal-state-invariants
Jan 27, 2026
Merged

Add internal state invariant tests and reorganize test directories#310
chrisguidry merged 3 commits intomainfrom
internal-state-invariants

Conversation

@chrisguidry
Copy link
Owner

Adds tests that verify Worker and StrikeList internal data structures are
properly cleaned up after task completion and context exit. These tests
would have caught the memory leak fixed in #309 where _tasks_by_key
entries accumulated because we were using task.get_name() instead of
execution.key for cleanup.

Worker invariant tests check:

  • _tasks_by_key is empty after run_until_finished()
  • _tasks_by_key doesn't grow across multiple batches
  • _execution_counts is cleared after run_at_most()
  • Internal attributes are deleted after __aexit__
  • Cleanup works with failing tasks and varied task types
  • SharedContext ContextVars are properly reset

StrikeList invariant tests check:

  • _conditions only contains default after removing temp conditions
  • No empty dicts remain in task_strikes/parameter_strikes after restore

Also reorganizes tests into subdirectories:

  • tests/worker/ for worker-related tests
  • tests/instrumentation/ for metrics and tracing tests
  • Renames test_synced_strikelist.py to test_strikelist.py

Adds --import-mode=importlib to pytest config to support same-named
test files in different directories.

🤖 Generated with Claude Code

Adds tests that verify Worker and StrikeList internal data structures are
properly cleaned up after task completion and context exit. These tests
would have caught the memory leak fixed in #309 where `_tasks_by_key`
entries accumulated because we were using `task.get_name()` instead of
`execution.key` for cleanup.

Worker invariant tests check:
- `_tasks_by_key` is empty after `run_until_finished()`
- `_tasks_by_key` doesn't grow across multiple batches
- `_execution_counts` is cleared after `run_at_most()`
- Internal attributes are deleted after `__aexit__`
- Cleanup works with failing tasks and varied task types
- SharedContext ContextVars are properly reset

StrikeList invariant tests check:
- `_conditions` only contains default after removing temp conditions
- No empty dicts remain in `task_strikes`/`parameter_strikes` after restore

Also reorganizes tests into subdirectories:
- `tests/worker/` for worker-related tests
- `tests/instrumentation/` for metrics and tracing tests
- Renames `test_synced_strikelist.py` to `test_strikelist.py`

Adds `--import-mode=importlib` to pytest config to support same-named
test files in different directories.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@github-actions
Copy link

github-actions bot commented Jan 27, 2026

📚 Documentation has been built for this PR!

You can download the documentation directly here:
https://github.com/chrisguidry/docket/actions/runs/21400249004/artifacts/5272929154

@codecov-commenter
Copy link

codecov-commenter commented Jan 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.63%. Comparing base (c5a2b6d) to head (5598a87).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #310      +/-   ##
==========================================
+ Coverage   98.61%   98.63%   +0.02%     
==========================================
  Files          99      100       +1     
  Lines        9906    10066     +160     
  Branches      483      491       +8     
==========================================
+ Hits         9769     9929     +160     
  Misses        121      121              
  Partials       16       16              
Flag Coverage Δ
python-3.10 98.63% <100.00%> (+0.02%) ⬆️
python-3.11 97.26% <93.16%> (-0.07%) ⬇️
python-3.12 98.63% <100.00%> (+0.02%) ⬆️
python-3.13 98.63% <100.00%> (+0.02%) ⬆️
python-3.14 98.63% <100.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
tests/instrumentation/test_counters.py 100.00% <ø> (ø)
tests/instrumentation/test_export.py 100.00% <ø> (ø)
tests/instrumentation/test_tracing.py 100.00% <ø> (ø)
tests/test_strikelist.py 100.00% <100.00%> (ø)
tests/worker/test_bootstrap.py 100.00% <ø> (ø)
tests/worker/test_core.py 100.00% <ø> (ø)
tests/worker/test_invariants.py 100.00% <100.00%> (ø)
tests/worker/test_lifecycle.py 100.00% <ø> (ø)
tests/worker/test_scheduling.py 100.00% <ø> (ø)
tests/worker/test_ttl_zero.py 100.00% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

chrisguidry and others added 2 commits January 27, 2026 09:01
The `logging.LoggerAdapter[logging.Logger]` type hint needs PEP 563
deferred evaluation to work on Python 3.10.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Simplify the SharedContext reset test and use a typed lambda for the
temporary condition test to avoid uncovered branches.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@chrisguidry chrisguidry merged commit aecd46a into main Jan 27, 2026
40 checks passed
@chrisguidry chrisguidry deleted the internal-state-invariants branch January 27, 2026 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants