Fixed
Status Update
Comments
lc...@gmail.com <lc...@gmail.com> #2
Yigit, do you have time to fix it?
reemission of the same liveData is racy
reemission of the same liveData is racy
an...@seventhbeam.com <an...@seventhbeam.com> #3
yea i'll take it.
il...@google.com <il...@google.com> #4
Thanks for the detailed analysis. This may not be an issue anymore since we've started using Main.immediate there but I' not sure; I'll try to create a test case.
au...@gmail.com <au...@gmail.com> #5
just emitting same live data reproduces the issue.
@Test
fun raceTest() {
val subLiveData = MutableLiveData(1)
val subject = liveData(testScope.coroutineContext) {
emitSource(subLiveData)
emitSource(subLiveData) //crashes
}
subject.addObserver().apply {
testScope.advanceUntilIdle()
}
}
@Test
fun raceTest() {
val subLiveData = MutableLiveData(1)
val subject = liveData(testScope.coroutineContext) {
emitSource(subLiveData)
emitSource(subLiveData) //crashes
}
subject.addObserver().apply {
testScope.advanceUntilIdle()
}
}
il...@google.com <il...@google.com> #6
With 2.2.0-alpha04 (that use Main.immediate), the issue seems to be still there (I tested it by calling emitSource() twice, like your test case)
Description
Version used: "2.2.0-alpha01"
Devices/Android versions reproduced on: API 27
When following this tutorial to test my fragment
However, due to limitations in the Android VM that we cannot mock final classes or final methods, the same test failed in instrumented test. (Sample project is attached)
Although we can break these limitation with using Mockk or dexmaker-mockito-inline and running test in API >= 28 devices, how to run instrumented test in older versions devices is still a problem.
Currently, instead of mocking the NavController and running tests in FragmentScenario, I just use an ActivityScenario with NavHostFragment and programmatically create NavGraph for testing.
Any better solutions here?
If this is a bug in the library, we would appreciate if you could attach:
- Sample project to trigger the issue.
- A screenrecord or screenshots showing the issue (if UI related).