Skip to content

kotlinx-coroutines-test:1.6.1 - stateIn and sharedIn (that are not started while subscribed) are not practical to test with runTest #3323

@AlexDochioiu

Description

@AlexDochioiu

Background info: runTest won't finish unless all the coroutines launched inside also finished. This is what I'd expect for most cases but it becomes problematic if I want something along the lines of:

val uiState = myFlow
        .stateIn(viewModelScope, SharingStarted.Eagerly, UiStates.Empty)

The problem is that runTest will hang and time out because of the job started by stateIn/shareIn which is kept active until viewModelScope is canceled.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions