Skip to content

Commit ccafffa

Browse files
authored
Merge pull request #187 from nomisRev/stressTest
Stress testing
2 parents 3b90b60 + fceef81 commit ccafffa

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

.github/workflows/pr.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
jobs:
1010
check:
1111
runs-on: ubuntu-latest
12-
timeout-minutes: 30
12+
timeout-minutes: 120
1313

1414
steps:
1515
- uses: actions/checkout@v4
@@ -23,7 +23,7 @@ jobs:
2323

2424
- uses: gradle/gradle-build-action@v2
2525
with:
26-
arguments: build --scan --full-stacktrace
26+
arguments: build --scan --full-stacktrace -PstressTest=100
2727

2828
- name: Bundle the build report
2929
if: failure()

build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ tasks {
8080

8181
withType<Test>().configureEach {
8282
useJUnitPlatform()
83+
maxParallelForks = (2 * Runtime.getRuntime().availableProcessors())
84+
if (project.hasProperty("stressTest")) {
85+
systemProperty("io.github.nomisrev.kafka.TEST_ITERATIONS", project.properties["stressTest"] ?: 100)
86+
}
8387
testLogging {
8488
exceptionFormat = FULL
8589
events = setOf(SKIPPED, FAILED, STANDARD_ERROR)

src/test/kotlin/io/github/nomisrev/kafka/KafkaSpec.kt

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ import java.util.concurrent.TimeUnit
5050
import kotlin.test.assertEquals
5151
import kotlin.time.Duration.Companion.seconds
5252

53+
private val testIterations: Int =
54+
System.getProperties().getProperty("io.github.nomisrev.kafka.TEST_ITERATIONS")?.toIntOrNull() ?: 1
5355

5456
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
5557
abstract class KafkaSpec {
@@ -63,7 +65,7 @@ abstract class KafkaSpec {
6365
fun destroy() {
6466
kafka.stop()
6567
}
66-
68+
6769
@BeforeAll
6870
@JvmStatic
6971
fun setup() {
@@ -86,10 +88,10 @@ abstract class KafkaSpec {
8688
withEnv("KAFKA_ALLOW_EVERYONE_IF_NO_ACL_FOUND", "true")
8789
withReuse(true)
8890
}
89-
91+
9092
fun KafkaReceiver(): KafkaReceiver<String, String> =
9193
KafkaReceiver(receiverSetting())
92-
94+
9395
fun receiverSetting(): ReceiverSettings<String, String> =
9496
ReceiverSettings(
9597
bootstrapServers = kafka.bootstrapServers,
@@ -169,15 +171,17 @@ abstract class KafkaSpec {
169171
partitions: Int = 4,
170172
replicationFactor: Short = 1,
171173
test: suspend TopicTestScope.(NewTopic) -> Unit
172-
): Unit = runTest {
173-
val topic = NewTopic(nextTopicName(), partitions, replicationFactor).configs(topicConfig)
174-
admin {
175-
createTopic(topic)
176-
try {
177-
TopicTestScope(topic, this@runTest).test(topic)
178-
} finally {
179-
topic.shouldBeEmpty()
180-
deleteTopic(topic.name())
174+
): Unit = repeat(testIterations) {
175+
runTest {
176+
val topic = NewTopic(nextTopicName(), partitions, replicationFactor).configs(topicConfig)
177+
admin {
178+
createTopic(topic)
179+
try {
180+
TopicTestScope(topic, this@runTest).test(topic)
181+
} finally {
182+
topic.shouldBeEmpty()
183+
deleteTopic(topic.name())
184+
}
181185
}
182186
}
183187
}
@@ -298,6 +302,7 @@ abstract class KafkaSpec {
298302
object : Producer<String, String> {
299303
override fun clientInstanceId(p0: Duration?): Uuid =
300304
producer.clientInstanceId(p0)
305+
301306
override fun close() {}
302307

303308
override fun close(timeout: Duration?) {}

0 commit comments

Comments
 (0)