Skip to content

[Bug]: Flaky Tests in SetupViewModelTest and LoginViewModelTest #25

@theMr17

Description

@theMr17

Describe the bug

Several tests in SetupViewModelTest and LoginViewModelTest intermittently fail due to missed or overwritten emissions from state flows. These tests often hang or timeout with UncompletedCoroutinesError, especially when intermediate states (like LOADING, SAVING_TOKEN, etc.) are not collected in time during the test execution.

This makes the tests flaky and unreliable despite correct logic in the ViewModel implementation.

Examples:

  • testGetAuthToken_successfulFlow_setsStateToSuccessEventually (SetupViewModelTest)
  • testAuthStatus_tokenIsValid_setsStateToLoggedInEventually (LoginViewModelTest)

Steps to Reproduce

  1. Run the instrumented tests using ./gradlew connectedDebugAndroidTest
  2. Observe that certain tests randomly hang or fail
  3. Rerun without changing the code — sometimes they pass, sometimes not

Expected Behavior

All state emission-based tests should deterministically pass when the underlying logic is correct. State transitions like LOADING → LOGGED_IN or FETCHING_TOKEN → SUCCESS should be reliably captured by the test collectors.

Screenshots or Videos (if applicable)

No response

Device/Emulator Information

No response

Android Version

No response

Log Output (if applicable)

com.notifier.app.auth.presentation.login.LoginViewModelTest > testAuthStatus_tokenIsValid_setsStateToLoggedInEventually[emulator-5554 - 13] FAILED 
kotlinx.coroutines.test.UncompletedCoroutinesError: After waiting for 1m, the test body did not run to completion
at kotlinx.coroutines.test.TestBuildersKt__TestBuildersKt$runTest$2$1$2.invokeSuspend$lambda$0(TestBuilders.kt:353)

com.notifier.app.auth.presentation.setup.SetupViewModelTest > testGetAuthToken_networkError_setsStateToFailedEventually_emitsNetworkErrorEvent[emulator-5554 - 13] FAILED 
kotlinx.coroutines.test.UncompletedCoroutinesError: After waiting for 1m, the test body did not run to completion

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions