I am testing a component, that depends on a cache ...
# coroutines
c
I am testing a component, that depends on a cache implementation. The cache implementation is not part of the SUT, and it is expected that it outlives the SUT. Currently, I'm using this:
Copy code
@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:
Copy code
@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