fun runStressTest()

in hot-reload-core/src/testFixtures/kotlin/org/jetbrains/compose/reload/core/testFixtures/stressTest.kt [73:104]


fun runStressTest(
    repetitions: Int = 24,
    parallelism: Int = 2,
    timeout: Duration = 10.minutes,
    silenceTimeout: Duration = 30.seconds,
    test: suspend StressTestScope.() -> Unit
) {
    runBlocking(Dispatchers.IO + Job() + CoroutineName("runStressTest")) {
        /* Fan out the invocations using a channel */
        val invocationChannel = Channel<Int>(Channel.UNLIMITED)
        repeat(repetitions) { index -> invocationChannel.send(index) }
        invocationChannel.close()

        val executedInvocations = AtomicInteger(0)

        /* Setup tests overall timeout */
        withTimeout(timeout) {
            coroutineScope {
                /* Launch coroutines */
                repeat(parallelism) { coroutineId ->
                    launch(CoroutineName("runStressTest(coroutineId=$coroutineId)")) {
                        for (invocationIndex in invocationChannel) {
                            executeStressTestInvocation(coroutineId, invocationIndex, silenceTimeout, test)
                            val executedInvocations = executedInvocations.incrementAndGet()
                            logger.info("runStressTest: $executedInvocations/$repetitions")
                        }
                    }
                }
            }
        }
    }
}