CLOVIS
01/04/2023, 8:48 PM@Test
fun test() = runTest {
val cache = FakeCacheImplementation(currentCoroutineContext())
// actually do the test
}
However, the cache outlives the test, runTest
never completes (always times out) because the cache's coroutine is always running. What is the recommended solution to deal with these kinds of dependencies? I found that adding currentCoroutineContext().cancelChildren()
at the end of the test does work, but I'm not sure it's good practice.
Ideally, I'd like something like:
@Test
fun test() = runTest {
val cache = withContext(BackgroundWorkIDontCareAbout) {
FakeCacheImplementation(currentCoroutineContext())
}
// actually do the test
} // waits for all jobs except those marked with BackgroundWorkIDontCareAbout, which are just cancelled immediately
Edit. It already exists