Skip to content

Thread safety contention tests (3pt) #74

Description

@henry0816191

Problem

ISOProber._stats is protected by _stats_lock and mutated from async coroutines. Scheduler._health_lock protects cross-thread reads of _health_snapshot. Neither lock has a contention test verifying correctness under concurrent access. Under Python 3.13+ free-threaded builds, data races would be exposed if the lock discipline is incomplete. Additionally, run_cycle() does a _reset_stats() followed by many _bump_stat() calls — there is no test asserting consistent snapshots between operations.

Acceptance Criteria

  • Test that concurrent _bump_stat() calls produce correct totals
  • Test that snapshot_stats() concurrent with _reset_stats() returns a consistent state
  • Test that health_snapshot() from a non-event-loop thread returns consistent data
  • All tests pass under standard CPython

Implementation Notes

  • New test file: tests/test_thread_safety.py
  • ISOProber tests: spawn N threads calling _bump_stat("miss"), assert count == N
  • Scheduler tests: concurrent health_snapshot() + _publish_health_snapshot() assertions

References

  • src/paperscout/sources.py (_stats_lock, _bump_stat, _reset_stats)
  • src/paperscout/monitor.py (_health_lock, _publish_health_snapshot)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions