Skip to content

Fix test mutex poisoning issues#2

Open
skypher wants to merge 1 commit intomainfrom
fix/failing-tests
Open

Fix test mutex poisoning issues#2
skypher wants to merge 1 commit intomainfrom
fix/failing-tests

Conversation

@skypher
Copy link
Copy Markdown
Owner

@skypher skypher commented Nov 15, 2025

Summary

Fixes cascading test failures caused by mutex poisoning when tests panic while holding locks.

Problem

When a test panicked while holding a test mutex, the mutex became "poisoned" and all subsequent tests calling .lock().unwrap() would fail with PoisonError, causing cascading test failures even though the test logic was correct.

Solution

  • Added lock_test_mutex() helper functions to all modules with test mutexes
  • Helpers use .unwrap_or_else(|e| e.into_inner()) to automatically recover poisoned mutexes
  • Replaced all 23 occurrences of .lock().unwrap() with the poison-safe helper

Results

Before:

  • Parallel run: ~188-189 tests passing, 18-19 failing
  • Sequential run: 207 passing, 0 failing

After:

  • Parallel run: ~192 tests passing, 15 failing (3-4 fewer failures)
  • Sequential run: 207 passing, 0 failing

Impact:

  • ✅ Eliminated mutex poisoning cascades
  • ✅ More reliable test suite
  • ✅ All tests pass sequentially

Remaining Issues

The remaining 15 parallel test failures are due to other isolation issues:

  • Tests modifying PATH environment variable
  • Tests creating conflicting temporary files
  • Tests sharing disk cache

These require per-test refactoring and are tracked separately.

Files Changed

21 files updated across all modules with test mutexes:

  • src/index/mod.rs + 7 test files
  • src/logic/mod.rs + 3 test files
  • src/state/mod.rs + test file
  • src/sources/mod.rs + 3 test files
  • src/theme/mod.rs + 3 test files

Adds poison-recovery helpers to prevent cascading test failures when a
test panics while holding a mutex lock.

Changes:
- Add lock_test_mutex() helper functions to all modules with test mutexes
- Replace all test_mutex().lock().unwrap() calls with lock_test_mutex()
- Automatically recover poisoned mutexes using unwrap_or_else

Impact:
- Reduced parallel test failures significantly
- All 207 tests pass when run sequentially (--test-threads=1)
- Remaining parallel failures are due to other isolation issues (PATH,
  temp files) that require per-test refactoring

Modules updated:
- src/index/mod.rs
- src/logic/mod.rs
- src/state/mod.rs
- src/sources/mod.rs
- src/theme/mod.rs
- All test files using test mutexes
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.

1 participant