Skip to content

Commit d81653d

Browse files
committed
Stress testing
1 parent 900bc8f commit d81653d

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

.github/workflows/pr.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ import java.util.concurrent.TimeUnit
4949
import kotlin.test.assertEquals
5050
import kotlin.time.Duration.Companion.seconds
5151

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

5355
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
5456
abstract class KafkaSpec {
@@ -62,7 +64,7 @@ abstract class KafkaSpec {
6264
fun destroy() {
6365
kafka.stop()
6466
}
65-
67+
6668
@BeforeAll
6769
@JvmStatic
6870
fun setup() {
@@ -85,10 +87,10 @@ abstract class KafkaSpec {
8587
withEnv("KAFKA_ALLOW_EVERYONE_IF_NO_ACL_FOUND", "true")
8688
withReuse(true)
8789
}
88-
90+
8991
fun KafkaReceiver(): KafkaReceiver<String, String> =
9092
KafkaReceiver(receiverSetting())
91-
93+
9294
fun receiverSetting(): ReceiverSettings<String, String> =
9395
ReceiverSettings(
9496
bootstrapServers = kafka.bootstrapServers,
@@ -168,15 +170,17 @@ abstract class KafkaSpec {
168170
partitions: Int = 4,
169171
replicationFactor: Short = 1,
170172
test: suspend TopicTestScope.(NewTopic) -> Unit
171-
): Unit = runTest {
172-
val topic = NewTopic(nextTopicName(), partitions, replicationFactor).configs(topicConfig)
173-
admin {
174-
createTopic(topic)
175-
try {
176-
TopicTestScope(topic, this@runTest).test(topic)
177-
} finally {
178-
topic.shouldBeEmpty()
179-
deleteTopic(topic.name())
173+
): Unit = repeat(testIterations) {
174+
runTest {
175+
val topic = NewTopic(nextTopicName(), partitions, replicationFactor).configs(topicConfig)
176+
admin {
177+
createTopic(topic)
178+
try {
179+
TopicTestScope(topic, this@runTest).test(topic)
180+
} finally {
181+
topic.shouldBeEmpty()
182+
deleteTopic(topic.name())
183+
}
180184
}
181185
}
182186
}
@@ -295,6 +299,9 @@ abstract class KafkaSpec {
295299
{
296300
val producer = KafkaProducer(it.properties(), it.keySerializer, it.valueSerializer)
297301
object : Producer<String, String> {
302+
override fun clientInstanceId(p0: Duration?): Uuid =
303+
producer.clientInstanceId(p0)
304+
298305
override fun close() {}
299306

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

0 commit comments

Comments
 (0)