in kotlinx-coroutines-core/jvm/src/DefaultExecutor.kt [165:177]
fun shutdownForTests(timeout: Long) {
val deadline = System.currentTimeMillis() + timeout
if (!isShutdownRequested) debugStatus = SHUTDOWN_REQ
// loop while there is anything to do immediately or deadline passes
while (debugStatus != SHUTDOWN_ACK && _thread != null) {
_thread?.let { unpark(it) } // wake up thread if present
val remaining = deadline - System.currentTimeMillis()
if (remaining <= 0) break
(this as Object).wait(timeout)
}
// restore fresh status
debugStatus = FRESH
}