mboudraa
03/05/2019, 1:37 PM@Test
fun `should receive updated data when querying all challenges`() {
val initChallenges = mutableListOf(Challenge(...),Challenge(...))
val newSurveyChallenge = SurveyChallenge(...)
val expectedChallenges = listOf(
initChallenges,
initChallenges += newSurveyChallenge
)
initChallenges.forEach(challengeDao::addOrUpdate)
runBlocking {
val channel = repository.availableChallenges(coroutineContext)
val actualChallengesLists = async(IO) {
channel.fold(mutableListOf<List<Challenge>>()) { list, challenges -> list.apply { add(challenges) } }
}
delay(300)
challengeDao.addOrUpdate(newSurveyChallenge)
delay(300)
channel.cancel()
assertThat(actualChallengesLists.await()).containsExactlyElementsIn(expectedChallenges).inOrder()
}
without those delay
, my test fail because the database doesnt have the time to notify anything. But having a delay looks like a code smell to me.
Is there a better way to test this behavior?
For the record I use sqldelight
and robolectric
to test thatgroostav
03/11/2019, 6:51 PMwithTimeoutOrNUll
to try and ensure completion.
https://gist.github.com/Groostav/a5695bdbe2e4df22824d0cad7d32e8fd