Skip to content

Remove the use of Dispachers.Default in AppLockViewModel#6784

Merged
jpelgrom merged 1 commit intomainfrom
fix/flaky_test_app_lock_viewmodel
Apr 28, 2026
Merged

Remove the use of Dispachers.Default in AppLockViewModel#6784
jpelgrom merged 1 commit intomainfrom
fix/flaky_test_app_lock_viewmodel

Conversation

@TimoPtr
Copy link
Copy Markdown
Member

@TimoPtr TimoPtr commented Apr 27, 2026

Summary

We were using the default dispatcher in the AppLockViewModel but it is not needed since the method called are Main safe already.
Because of the usage of the default dispatcher the unit test of setAppActive is flaky https://github.com/home-assistant/android/actions/runs/24982874143/job/73151266819?pr=6776

[9](https://github.com/home-assistant/android/actions/runs/24982817100/job/73149459136?pr=6777#step:4:590)
> Task :app:testFullDebugUnitTest

AppLockViewModelTest > SetAppActive > Given a null server ID when setting app active then uses SERVER_ID_ACTIVE() FAILED
    java.lang.AssertionError at AppLockViewModelTest.kt:58

858 tests completed, 1 failed

Copilot AI review requested due to automatic review settings April 27, 2026 08:46
@TimoPtr TimoPtr requested a review from jpelgrom April 27, 2026 08:46
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes the explicit use of Dispatchers.Default from AppLockViewModel.setAppActive, allowing the coroutine to use the viewModelScope context (Main dispatcher in production, test dispatcher in unit tests). This aligns the implementation with the fact that the invoked suspend work is already main-safe and eliminates flakiness caused by running on an uncontrolled dispatcher in tests.

Changes:

  • Remove the kotlinx.coroutines.Dispatchers import from AppLockViewModel
  • Launch setAppActive work in viewModelScope without forcing Dispatchers.Default

@jpelgrom jpelgrom enabled auto-merge (squash) April 28, 2026 19:37
@jpelgrom jpelgrom merged commit d01cdc9 into main Apr 28, 2026
45 of 46 checks passed
@jpelgrom jpelgrom deleted the fix/flaky_test_app_lock_viewmodel branch April 28, 2026 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants