You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## Summary
Expand firmware service test coverage to validate file cleanup
operations and device service client delegation.
Tests now support parallel execution using mutex lock pattern
(refactored from initial implementation).
## Tests Added (6 new, 7 total)
### clear_data_folder (3 tests)
- ✅ Removes all files in data directory
- ✅ Succeeds with empty directory
- ✅ Preserves subdirectories (only files removed)
### load_update (2 tests)
- ✅ Forwards request to device service with correct path
- ✅ Returns error on device service failure
### run_update (2 tests)
- ✅ Forwards request to device service
- ✅ Returns error on device service failure
## Implementation Details
- Uses `mockall` to mock `DeviceServiceClient` for async operations
- Tests validate delegation logic without testing device service
internals
- Uses `serde_json` to construct `RunUpdate` (private fields)
- Tests ensure directory exists before operations
- **Parallel test support:** Uses static `DATA_FOLDER_LOCK` mutex
following the `PASSWORD_FILE_LOCK` pattern for test isolation
## Refactoring for Parallel Execution
Initially, `clear_data_folder` tests had a race condition due to shared
temp directory from `AppConfig`. This has been resolved by:
1. Adding static `DATA_FOLDER_LOCK` mutex (following password.rs
pattern)
2. Adding `lock_for_test()` method to `FirmwareService`
3. Updating tests to acquire lock before accessing shared data directory
4. Tests now run safely in parallel without `--test-threads=1` flag
## Known Limitations
**File Upload Not Tested:** `handle_uploaded_firmware` is not tested as
it requires mocking `actix_multipart::form::tempfile::TempFile`, which
is complex.
## Test Results
```bash
# All tests pass in parallel
cargo test --features mock firmware::tests
```
Signed-off-by: Jan Zachmann <[email protected]>
0 commit comments