Add concurrent scan operation tests (18 tests, all passing)

 COMPLETE: 18/18 tests passing

Test Coverage:
- Concurrent scan prevention: Second scan blocked, multiple attempts handled, lock released after completion
- Scan cancellation: Cancel active scan, cancel when none active, cancelled scans in history, new scan after cancellation
- Database race conditions: AsyncIO lock prevents races, scan state consistency with concurrent reads, thread-safe history updates
- Scan state consistency: is_scanning flag consistency, current_scan object consistency, status API consistency, concurrent status checks
- Scheduler prevention: Scheduler skips rescan if already running, properly sets scan_in_progress flag
- AnimeService: Ignores concurrent rescan requests

All concurrent operation scenarios validated with proper lock management and state consistency.
This commit is contained in:
2026-02-01 11:25:11 +01:00
parent 7f21d3236f
commit 700415af57
2 changed files with 591 additions and 6 deletions

View File

@@ -542,12 +542,21 @@ All TIER 2 high priority core UX features have been completed:
#### Edge Case Tests
- [ ] **Create tests/unit/test_concurrent_scans.py** - Concurrent scan operation tests
- Test multiple simultaneous scan requests handled gracefully
- Test scan cancellation/interruption handling
- Test database race condition prevention during scans
- Test scan state consistency with concurrent requests
- Target: 100% of concurrent operation scenarios covered
- [x] **Create tests/unit/test_concurrent_scans.py** - Concurrent scan operation tests ✅ COMPLETE
- Note: 18/18 tests passing - comprehensive concurrent scan handling coverage
- Coverage: Concurrent scan prevention (5 tests), scan cancellation (4 tests), database race conditions (3 tests), scan state consistency (4 tests), scheduler prevention (2 tests)
- Test ✅ Second scan blocked while first running
- Test ✅ Multiple scan attempts properly handled
- Test ✅ Scan lock released after completion/error
- Test ✅ Cancel active scan
- Test ✅ New scan after cancellation
- Test ✅ AsyncIO lock prevents race conditions
- Test ✅ Scan state consistency with concurrent reads
- Test ✅ Thread-safe history updates
- Test ✅ is_scanning flag consistency
- Test ✅ Scheduler skips if scan already running
- Test ✅ AnimeService ignores concurrent requests
- Target achieved: ✅ COMPLETE - all concurrent operation scenarios covered
- [ ] **Create tests/unit/test_download_retry.py** - Download retry logic tests
- Test automatic retry after download failure