Skip to content

Commit

Permalink
test: allow test retries
Browse files Browse the repository at this point in the history
  • Loading branch information
ptitjes committed Aug 6, 2024
1 parent 284c31c commit 6ed177d
Showing 1 changed file with 24 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@

package org.zeromq.tests.utils

import io.kotest.assertions.*
import io.kotest.core.names.*
import io.kotest.core.spec.style.scopes.*
import io.kotest.core.test.*
import io.kotest.core.test.config.*
import kotlinx.coroutines.*
import org.zeromq.*
import kotlin.time.*
import kotlin.time.Duration.Companion.seconds
import kotlin.time.Duration.Companion.minutes

typealias SingleContextTest = suspend ContainerScope.(Context, Protocol) -> Unit
typealias DualContextTest = suspend ContainerScope.(Context, Context, Protocol) -> Unit
Expand All @@ -39,7 +40,7 @@ class SingleContextTestBuilder(
}
}

private val DEFAULT_TEST_TIMEOUT = 5.seconds
private val DEFAULT_TEST_TIMEOUT = 5.minutes

private fun RootScope.runSingleContextTest(
name: String,
Expand All @@ -55,18 +56,23 @@ private fun RootScope.runSingleContextTest(
}

val testTimeout = timeout ?: DEFAULT_TEST_TIMEOUT
val globalConfig = TestConfig(timeout = testTimeout * 2)
val globalConfig = TestConfig(
timeout = testTimeout * testData.size,
invocationTimeout = testTimeout,
)

testData.forEach { data ->
val (engine, protocol) = data
val testName = TestName("$name (${engine.name}, $protocol)")
val testConfig = globalConfig.copy(enabled = enableTest(data))

addTest(testName, false, testConfig, TestType.Dynamic) {
val context = Context(engine)
context.use {
withTimeout(testTimeout) {
test(context, protocol)
retry(10, 5.minutes) {
val context = Context(engine)
context.use {
withTimeout(testTimeout) {
test(context, protocol)
}
}
}
}
Expand Down Expand Up @@ -107,19 +113,24 @@ private fun RootScope.runDualContextTest(
}

val testTimeout = timeout ?: DEFAULT_TEST_TIMEOUT
val globalConfig = TestConfig(timeout = testTimeout * 2)
val globalConfig = TestConfig(
timeout = testTimeout * testData.size,
invocationTimeout = testTimeout,
)

testData.forEach { data ->
val (engine1, engine2, protocol) = data
val testName = TestName("$name (${engine1.name}-${engine2.name}, $protocol)")
val testConfig = globalConfig.copy(enabled = enableTest(data))

addTest(testName, false, testConfig, TestType.Dynamic) {
val context1 = Context(engine1)
val context2 = if (protocol == Protocol.INPROC) context1 else Context(engine2)
use(context1, context2) {
withTimeout(testTimeout) {
test(context1, context2, protocol)
retry(10, 5.minutes) {
val context1 = Context(engine1)
val context2 = if (protocol == Protocol.INPROC) context1 else Context(engine2)
use(context1, context2) {
withTimeout(testTimeout) {
test(context1, context2, protocol)
}
}
}
}
Expand Down

0 comments on commit 6ed177d

Please sign in to comment.