momrak
02/25/2020, 7:02 AMfun handleDelete(extIds: List<String>) {
val ids = someClient1.getInternalIds(extIds) // get deleteable IDs
try {
runBlocking(<http://Dispatchers.IO|Dispatchers.IO>) { // use IO dispatcher as someClient2 makes a call to some remote service.
ids.forEach{ launch { someClient2.deleteId(it) } }
}
} catch (e: Exception) {
handleException(e)
}
}
and I want to test it. My team uses Mockito and not Mockk, if that makes any difference.
Maybe the test does not make sense, but as I am not very familiar with coroutines I want to test that these are run correctly in paralell and that they exit the runBlocking block after they're all done. So I was thinking of mocking the responses from someClient2
so that say i have extIds = listof("123", "456")
and the calls take respectively 500ms and 750ms, I want to check that in total this function does not use much more time than ~750ms and not (500+750)=1250ms.
Is this possible using Mockito? And is it actually a useful test? š¤octylFractal
02/25/2020, 7:04 AMmomrak
02/25/2020, 7:06 AMResponseWithDelay
or smth class, but that delay does not play nice with the timings in runBlockingTest
it seems likeoctylFractal
02/25/2020, 7:09 AMassertTimeout
or similarmomrak
02/25/2020, 7:16 AMextract function refactoring
and extract whats inside the launch into a suspending fcn, but yeah, then it is still only one function, and the paralell execution I want to test needs also the forEach
to work, so that might not be a good idea anyway.
Cool, I'll check that out now!