Fix tests

This commit is contained in:
Jorge Martín
2025-12-16 16:53:24 +01:00
committed by Jorge Martin Espinosa
parent b201b40639
commit 5c6fee08fd
3 changed files with 54 additions and 30 deletions

View File

@@ -14,6 +14,7 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.job
import kotlinx.coroutines.plus
import kotlinx.coroutines.test.TestScope
/**
* Create a child scope of the current scope.
@@ -28,6 +29,11 @@ fun CoroutineScope.childScope(
dispatcher: CoroutineDispatcher,
name: String,
): CoroutineScope = run {
val supervisorJob = SupervisorJob(parent = coroutineContext.job)
this + dispatcher + supervisorJob + CoroutineName(name)
if (this is TestScope) {
// Special case for tests: we can't start a coroutine with a different SupervisorJob
this
} else {
val supervisorJob = SupervisorJob(parent = coroutineContext.job)
this + dispatcher + supervisorJob + CoroutineName(name)
}
}