refactor: coroutine dispatchers and modernize testing infrastructure#4901
Merged
jamesarich merged 7 commits intomainfrom Mar 24, 2026
Merged
refactor: coroutine dispatchers and modernize testing infrastructure#4901jamesarich merged 7 commits intomainfrom
jamesarich merged 7 commits intomainfrom
Conversation
… stubs - Migrate hardcoded `Dispatchers` to an injected `CoroutineDispatchers` abstraction across `MQTTRepository`, `ScannerViewModel`, `DebugViewModel`, and `MeshServiceOrchestrator` to improve testability. - Update integration and unit tests to utilize `UnconfinedTestDispatcher` through the injected dispatcher provider. - Introduce `Noop` stubs for firmware management (`FirmwareUpdateManager`, `FirmwareUsbManager`, `FirmwareFileHandler`) in the desktop module. - Consolidate `CoroutineDispatchers` dependency injection configuration into `CoreDiModule`. - Add missing feature module dependencies (Firmware, Intro, Map) to the desktop Koin configuration and build script.
- Introduce `FakeMeshLogRepository` and `FakeMeshLogPrefs` in the `core:testing` module to facilitate state-based testing. - Restore and refactor `MeshServiceOrchestratorTest`, `MeshConnectionManagerImplTest`, and `DebugViewModelTest`, migrating them to Mokkery and utilizing fakes. - Enhance `FakeRadioController` to track the last set device address for easier verification in tests. - Update `ScannerViewModelTest` to use the improved fake radio controller and clean up dispatcher initialization. - Add the `core:testing` dependency to the `core:data` module.
- Introduce `FakeMeshLogRepository` and `FakeMeshLogPrefs` in the `core:testing` module to facilitate state-based testing. - Restore and refactor `MeshServiceOrchestratorTest`, `MeshConnectionManagerImplTest`, and `DebugViewModelTest`, migrating them to Mokkery and utilizing fakes. - Enhance `FakeRadioController` to track the last set device address for easier verification in tests. - Update `ScannerViewModelTest` to use the improved fake radio controller and clean up dispatcher initialization. - Add the `core:testing` dependency to the `core:data` module.
- Introduce `FakeServiceRepository` to provide a consistent test double for service actions, connection states, and mesh packet flows. - Update `SharedContactViewModelTest`, `ConnectionsViewModelTest`, and `ScannerViewModelTest` to use `FakeNodeRepository` and `FakeServiceRepository` instead of manual mocks. - Rename `FakePrefs.kt` to `FakeMeshLogPrefs.kt` and refactor `FakeMeshLogRepository` to improve internal naming consistency and address lint warnings. - Add `core:testing` as a dependency for `core:ui` tests and expose `kermit` via the testing module. - Suppress minor lint warnings in stub and fake implementations for empty blocks and function counts.
…implementation This commit refactors how connection status notifications are generated by moving the string formatting logic from the common `MeshConnectionManagerImpl` to the platform-specific `MeshServiceNotificationsImpl` on Android. This decouples the core logic from UI resource strings and centralizes notification construction. Specific changes include: - **`MeshConnectionManagerImpl`**: Simplified `updateStatusNotification` to pass the raw `ConnectionState` object instead of a pre-formatted string. Removed associated resource imports. - **`MeshServiceNotifications` interface**: Updated `updateServiceStateNotification` signature to accept `ConnectionState` instead of a nullable string. - **`MeshServiceNotificationsImpl` (Android)**: Implemented the string mapping logic for `ConnectionState` using localized resources (`meshtastic_app_name`, `connected`, `disconnected`, etc.). - **`MeshConnectionManagerImplTest`**: Updated mocks to handle the new connection state flow and notification calls. - **Maintenance**: Added `LargeClass` suppression to `MeshServiceNotificationsImpl` and updated imports. Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
…tate` This commit refactors the `updateServiceStateNotification` method signature within the `MeshServiceNotifications` interface and its implementations. The `summaryString: String?` parameter has been replaced with a more structured `state: ConnectionState` parameter to provide better context for notification updates across platforms. Specific changes include: - Updated `DesktopMeshServiceNotifications` to accept `org.meshtastic.core.model.ConnectionState`. - Updated `Fakes.kt` in the test suite to reflect the new method signature. - Updated `NoopStubs.kt` in the desktop module to align with the interface change. Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces several improvements to dependency injection and coroutine management, particularly focusing on standardizing the use of custom coroutine dispatchers across the codebase. It also updates and modernizes various test classes to use the latest mocking libraries and patterns, ensuring more robust and maintainable tests.
Dependency injection and coroutine dispatchers:
CoreDiModuleto the Koin module includes inAppKoinModuleto ensure core dependencies are available throughout the app.CoroutineDispatchersfromAppKoinModule, as this is now handled by the new module.MQTTRepositoryImplandMeshServiceOrchestratorto accept and use an injectedCoroutineDispatchersinstance instead of directly referencingDispatchers.Default, promoting consistency and testability. [1] [2] [3] [4] [5] [6]Test modernization and improvements:
MeshConnectionManagerImplTestandMeshServiceOrchestratorTestclasses by switching to themokkerymocking library, using autofill mocks, and updating test lifecycle annotations. This results in cleaner, more maintainable, and more reliable tests. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]core.testingproject as a dependency for common tests, ensuring access to shared test utilities.