ursus
08/22/2025, 1:04 PMturbine gurus could chime in
private val _state = MutableStateFlow<ChatState>(ChatState.Idle)
override val state: Flow<ChatState> get() = _state
scope.launch {
combine(
conversationDao.conversation.doOnNext { println("-- CONVERSATION=$it") },
connector.connectionState.doOnNext { println("-- CONN_STATE=$it") },
::stateMapper
)
.collect {
println("--- PRODUCED=$it")
_state.value = it
}
}
I have combine which produces as a result and pipes it into stateflow _state. That state flow is then asserted at test time with turbine (ommited)
Issue is that for some reason this is not deterministic. Default value of connectionState is Disconnected and then obviously Connecting etc
What I'm seeing is that sometimes I see Connecting getting emitted before the product of combining with Disconnected gets set to the _state
Othertimes it's not and I see 2 `--- PRODUCED`as expected.
Is this a StateFlow issue? A combine issue? A Turbine issue? A TestDispatcher issue?
Should I maybe not assert all the intermediary emits and just the last one using?ursus
08/22/2025, 1:27 PM_state.value = it part maybe?curioustechizen
08/22/2025, 1:30 PMursus
08/22/2025, 1:32 PMcombine directly override val state = combine ...)
but what to do in turbine tests?
At runtime I don' really case if such transient product exists or not
Can I maybe assert just the latest value in turbine? I notice turbine.expectMostRecentItem() but doesnt really behave how I'd expect it to -- is it not alias for draining the queue?curioustechizen
08/22/2025, 1:34 PMadvanceUntilIdle() before that expectMostRecentItem()ursus
08/22/2025, 2:15 PMursus
08/22/2025, 3:42 PMawaitItem { ... predicate } to skip the uninteresting intermediate emits?