Skip to content

Commit bbb7d46

Browse files
committed
Updated tests to include proper coroutines debug management
1 parent 9a7022b commit bbb7d46

File tree

35 files changed

+148
-106
lines changed

35 files changed

+148
-106
lines changed

krpc/krpc-core/build.gradle.kts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
import org.gradle.kotlin.dsl.withType
66
import org.jetbrains.kotlin.gradle.targets.jvm.tasks.KotlinJvmTest
77

8-
/*
9-
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
10-
*/
11-
128
plugins {
139
alias(libs.plugins.conventions.kmp)
1410
alias(libs.plugins.serialization)
@@ -34,6 +30,8 @@ kotlin {
3430

3531
commonTest {
3632
dependencies {
33+
implementation(projects.tests.testUtils)
34+
3735
implementation(libs.kotlin.test)
3836
implementation(libs.coroutines.test)
3937
implementation(libs.serialization.json)

krpc/krpc-core/src/commonTest/kotlin/kotlinx/rpc/krpc/KrpcConnectorTest.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import kotlinx.rpc.krpc.internal.KrpcPlugin
2828
import kotlinx.rpc.krpc.internal.KrpcPluginKey
2929
import kotlinx.rpc.krpc.internal.KrpcProtocolMessage
3030
import kotlinx.rpc.krpc.internal.deserialize
31+
import kotlinx.rpc.test.runTestWithCoroutinesProbes
3132
import kotlinx.serialization.json.Json
3233
import kotlin.coroutines.CoroutineContext
3334
import kotlin.js.JsName
@@ -331,9 +332,7 @@ abstract class KrpcConnectorBaseTest {
331332
callTimeout: Duration = 1.seconds,
332333
perCallBufferSize: Int = 100,
333334
body: suspend TestScope.(clientConnector: KrpcConnector, serverConnector: KrpcConnector) -> Unit,
334-
) = kotlinx.coroutines.test.runTest(timeout = testTimeout) {
335-
debugCoroutines()
336-
335+
) = runTestWithCoroutinesProbes(timeout = testTimeout) {
337336
val connectorConfig = KrpcConfig.Connector(waitTimeout, callTimeout, perCallBufferSize)
338337

339338
val transport = LocalTransport(coroutineContext)

krpc/krpc-core/src/commonTest/kotlin/kotlinx/rpc/krpc/KrpcReceiveBufferTest.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import kotlinx.rpc.krpc.internal.KrpcReceiveBuffer
1212
import kotlinx.rpc.krpc.internal.isClosed
1313
import kotlinx.rpc.krpc.internal.isFailure
1414
import kotlinx.rpc.krpc.internal.isSuccess
15+
import kotlinx.rpc.test.runTestWithCoroutinesProbes
1516
import kotlin.test.Test
1617
import kotlin.test.assertEquals
1718
import kotlin.test.assertTrue
@@ -70,9 +71,7 @@ internal abstract class KrpcReceiveBufferBaseTest {
7071
bufferSize: Int,
7172
timeout: Duration = 10.seconds,
7273
body: suspend TestScope.(KrpcReceiveBuffer) -> Unit,
73-
) = kotlinx.coroutines.test.runTest(timeout = timeout) {
74-
debugCoroutines()
75-
74+
) = runTestWithCoroutinesProbes(timeout = timeout) {
7675
val buffer = KrpcReceiveBuffer(
7776
bufferSize = { bufferSize },
7877
)

krpc/krpc-core/src/commonTest/kotlin/kotlinx/rpc/krpc/KrpcReceiveHandlerTest.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import kotlinx.rpc.krpc.internal.isFailure
3434
import kotlinx.rpc.krpc.internal.isSuccess
3535
import kotlinx.rpc.krpc.internal.onClosed
3636
import kotlinx.rpc.krpc.internal.onFailure
37+
import kotlinx.rpc.test.runTestWithCoroutinesProbes
3738
import kotlin.test.Test
3839
import kotlin.test.assertEquals
3940
import kotlin.test.assertTrue
@@ -232,16 +233,14 @@ internal abstract class KrpcReceiveHandlerBaseTest {
232233
bufferSize: Int,
233234
timeout: Duration = 30.seconds,
234235
body: suspend TestConfig.() -> Unit,
235-
) = kotlinx.coroutines.test.runTest(timeout = timeout) {
236-
debugCoroutines()
237-
236+
) = runTestWithCoroutinesProbes(timeout = timeout) {
238237
val buffer = KrpcReceiveBuffer(
239238
bufferSize = { bufferSize },
240239
)
241240

242241
val channel = Channel<KrpcMessage>(Channel.UNLIMITED)
243242

244-
val senderJob = Job(this@runTest.coroutineContext.job)
243+
val senderJob = Job(this@runTestWithCoroutinesProbes.coroutineContext.job)
245244
val sender = object : KrpcMessageSender {
246245
override suspend fun sendMessage(message: KrpcMessage) {
247246
channel.send(message)

krpc/krpc-core/src/commonTest/kotlin/kotlinx/rpc/krpc/KrpcSendHandlerTest.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import kotlinx.coroutines.test.TestScope
1212
import kotlinx.coroutines.withTimeoutOrNull
1313
import kotlinx.coroutines.yield
1414
import kotlinx.rpc.krpc.internal.KrpcSendHandler
15+
import kotlinx.rpc.test.runTestWithCoroutinesProbes
1516
import kotlin.test.Test
1617
import kotlin.test.assertEquals
1718
import kotlin.test.fail
@@ -112,9 +113,7 @@ internal abstract class KrpcSendHandlerBaseTest {
112113
protected fun runTest(
113114
timeout: Duration = 10.seconds,
114115
body: suspend TestScope.(Channel<KrpcTransportMessage>, KrpcSendHandler) -> Unit,
115-
) = kotlinx.coroutines.test.runTest(timeout = timeout) {
116-
debugCoroutines()
117-
116+
) = runTestWithCoroutinesProbes(timeout = timeout) {
118117
val channel = Channel<KrpcTransportMessage>(
119118
capacity = Channel.UNLIMITED,
120119
)

krpc/krpc-core/src/jvmTest/kotlin/kotlinx/rpc/krpc/debug.jvm.kt

Lines changed: 0 additions & 13 deletions
This file was deleted.

krpc/krpc-ktor/krpc-ktor-core/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ kotlin {
2727
implementation(projects.krpc.krpcKtor.krpcKtorServer)
2828
implementation(projects.krpc.krpcKtor.krpcKtorClient)
2929
implementation(projects.krpc.krpcLogging)
30+
implementation(projects.tests.testUtils)
3031

3132
implementation(libs.kotlin.test)
3233
implementation(libs.ktor.server.netty)

krpc/krpc-ktor/krpc-ktor-core/src/jvmTest/kotlin/kotlinx/rpc/krpc/ktor/KtorTransportTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import io.ktor.server.routing.*
1818
import io.ktor.server.testing.*
1919
import kotlinx.coroutines.*
2020
import kotlinx.coroutines.debug.DebugProbes
21-
import kotlinx.coroutines.test.runTest
2221
import kotlinx.rpc.annotations.Rpc
2322
import kotlinx.rpc.krpc.client.KrpcClient
2423
import kotlinx.rpc.krpc.internal.logging.RpcInternalCommonLogger
@@ -30,6 +29,7 @@ import kotlinx.rpc.krpc.ktor.client.rpcConfig
3029
import kotlinx.rpc.krpc.ktor.server.Krpc
3130
import kotlinx.rpc.krpc.ktor.server.rpc
3231
import kotlinx.rpc.krpc.serialization.json.json
32+
import kotlinx.rpc.test.runTestWithCoroutinesProbes
3333
import kotlinx.rpc.withService
3434
import org.junit.Assert.assertEquals
3535
import java.net.ServerSocket
@@ -135,7 +135,7 @@ class KtorTransportTest {
135135
@OptIn(DelicateCoroutinesApi::class, ExperimentalCoroutinesApi::class)
136136
@Test
137137
@Ignore("Wait for Ktor fix (https://github.com/ktorio/ktor/pull/4927) or apply workaround if rejected")
138-
fun testEndpointsTerminateWhenWsDoes() = runTest(timeout = 15.seconds) {
138+
fun testEndpointsTerminateWhenWsDoes() = runTestWithCoroutinesProbes(timeout = 15.seconds) {
139139
DebugProbes.install()
140140

141141
val logger = setupLogger()

krpc/krpc-test/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ kotlin {
3737
api(projects.krpc.krpcClient)
3838
api(projects.krpc.krpcLogging)
3939

40+
implementation(projects.tests.testUtils)
41+
4042
implementation(projects.krpc.krpcSerialization.krpcSerializationJson)
4143

4244
implementation(libs.serialization.core)

krpc/krpc-test/src/commonMain/kotlin/kotlinx/rpc/krpc/test/KrpcTestServiceBackend.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package kotlinx.rpc.krpc.test
66

77
import kotlinx.coroutines.*
88
import kotlinx.coroutines.flow.*
9+
import kotlinx.rpc.test.runThreadIfPossible
910
import kotlinx.serialization.Serializable
1011
import kotlin.coroutines.resumeWithException
1112
import kotlin.test.assertContentEquals
@@ -267,7 +268,3 @@ class KrpcTestServiceBackend : KrpcTestService {
267268
}
268269
}
269270
}
270-
271-
internal expect fun runThreadIfPossible(runner: () -> Unit)
272-
273-
internal expect fun debugCoroutines()

0 commit comments

Comments
 (0)