Skip to content

Conversation

@JanZachmann
Copy link
Contributor

@JanZachmann JanZachmann commented Dec 19, 2025

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

# All tests pass in parallel
cargo test --features mock firmware::tests

All 7 tests pass ✅

Impact

  • Total backend tests: 54 → 60 (+6)
  • Coverage: Firmware file operations & device service delegation
  • Phase: 1.3 of backend test plan

Checklist

  • All tests pass in parallel
  • Code formatted with cargo fmt
  • Clippy passes
  • BACKEND_TEST_CONCEPT.md updated
  • Refactored for parallel test execution

Signed-off-by: Jan Zachmann 50990105+JanZachmann@users.noreply.github.com

Signed-off-by: Jan Zachmann <50990105+JanZachmann@users.noreply.github.com>
Signed-off-by: Jan Zachmann <50990105+JanZachmann@users.noreply.github.com>
Signed-off-by: Jan Zachmann <50990105+JanZachmann@users.noreply.github.com>
- Implemented auth.spec.ts, device.spec.ts, network.spec.ts
- Added centrifugo fixture helper
- Fixed Centrifugo subscription in App.vue
- Improved test scripts for argument forwarding
- Configured playwright to ignore HTTPS errors
- Added jsonwebtoken for test token generation

Signed-off-by: Jan Zachmann <50990105+JanZachmann@users.noreply.github.com>
Add comprehensive unit tests for NetworkConfigService covering:
- Request validation (DHCP, static IP, netmask boundaries)
- INI file generation for systemd-networkd
- Rollback response structure
- camelCase serialization/deserialization
- enable_rollback field handling

Tests use tempfile for filesystem operations and replicate
production INI generation logic in isolation.

Note: Rollback file I/O tests not included due to hardcoded
paths (/network/, /tmp/). Would require path injection refactor.

14 tests added, bringing total backend tests from 40 to 54.

Signed-off-by: Jan Zachmann <50990105+JanZachmann@users.noreply.github.com>
Expand firmware service test coverage to validate file operations
and device service delegation:
- clear_data_folder removes files, preserves subdirectories
- load_update forwards requests to device service client
- run_update forwards requests with validation flag

Tests use mockall to mock DeviceServiceClient for async operations.

Note: clear_data_folder tests share temp directory and may race
in parallel. Run with --test-threads=1 if flaky.

7 tests total (6 new), bringing backend tests from 54 to 60.

Signed-off-by: Jan Zachmann <50990105+JanZachmann@users.noreply.github.com>
Add static mutex lock pattern to FirmwareService tests following the
established PASSWORD_FILE_LOCK pattern from password service. This
allows clear_data_folder tests to run safely in parallel without race
conditions on the shared data directory.

Changes:
- Add DATA_FOLDER_LOCK static mutex for test isolation
- Add lock_for_test() method for acquiring test lock
- Update three clear_data_folder tests to acquire lock
- Remove warning about requiring --test-threads=1

Tests now pass reliably in parallel without any special flags.

Signed-off-by: Jan Zachmann <50990105+JanZachmann@users.noreply.github.com>
Document the refactoring of firmware service tests to support parallel
execution using the mutex lock pattern. Tests now run safely without
requiring --test-threads=1 flag.

Signed-off-by: Jan Zachmann <50990105+JanZachmann@users.noreply.github.com>
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