Skip to content

Commit 077ed48

Browse files
committed
propagate transport coroutine context
1 parent 6023d4e commit 077ed48

File tree

4 files changed

+7
-10
lines changed

4 files changed

+7
-10
lines changed

krpc/krpc-test/src/commonTest/kotlin/kotlinx/rpc/krpc/test/CoroutineContextPropagationTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class CoroutineContextPropagationTest {
3939
@Test
4040
fun test() = runTest {
4141
var actualContext: CoroutineElement? = null
42-
val transport = LocalTransport(transportContext = CoroutineElement("transport"))
42+
val transport = LocalTransport(CoroutineElement("transport"))
4343
val server = KrpcTestServer(rpcServerConfig, transport.server)
4444
val client = KrpcTestClient(rpcClientConfig, transport.client)
4545
withContext(CoroutineElement("server")) {

krpc/krpc-test/src/commonTest/kotlin/kotlinx/rpc/krpc/test/LocalTransport.kt

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,9 @@ import kotlin.time.Clock
1717
import kotlin.time.ExperimentalTime
1818

1919
class LocalTransport(
20-
parentScope: CoroutineScope? = null,
21-
transportContext: CoroutineContext? = null,
20+
parentContext: CoroutineContext? = null,
2221
) : CoroutineScope {
23-
override val coroutineContext = parentScope
24-
?.run { SupervisorJob(coroutineContext.job) }
25-
?: SupervisorJob()
22+
override val coroutineContext = SupervisorJob(parentContext?.job)
2623

2724
private val clientIncoming = Channel<KrpcTransportMessage>()
2825
private val serverIncoming = Channel<KrpcTransportMessage>()
@@ -32,7 +29,7 @@ class LocalTransport(
3229

3330
val client: KrpcTransport = object : KrpcTransport {
3431
override val coroutineContext: CoroutineContext = Job(this@LocalTransport.coroutineContext.job).let {
35-
if(transportContext != null) transportContext + it
32+
if(parentContext != null) parentContext + it
3633
else it
3734
}
3835

@@ -49,7 +46,7 @@ class LocalTransport(
4946

5047
val server: KrpcTransport = object : KrpcTransport {
5148
override val coroutineContext: CoroutineContext = Job(this@LocalTransport.coroutineContext.job).let {
52-
if(transportContext != null) transportContext + it
49+
if(parentContext != null) parentContext + it
5350
else it
5451
}
5552

krpc/krpc-test/src/commonTest/kotlin/kotlinx/rpc/krpc/test/cancellation/CancellationToolkit.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class CancellationToolkit(scope: CoroutineScope) : CoroutineScope by scope {
5050
}
5151
}
5252

53-
val transport = LocalTransport(this)
53+
val transport = LocalTransport(this.coroutineContext.job)
5454

5555
val client by lazy {
5656
KrpcTestClient(rpcClientConfig {

krpc/krpc-test/src/jvmTest/kotlin/kotlinx/rpc/krpc/test/api/WireSamplingTestScope.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ class WireSamplingTestScope(private val sampleName: String, scope: TestScope) :
229229
}
230230

231231
private class WireToolkit(scope: CoroutineScope, format: SamplingFormat, val logger: RpcInternalCommonLogger? = null) {
232-
val transport = LocalTransport(scope)
232+
val transport = LocalTransport(scope.coroutineContext.job)
233233

234234
val client by lazy {
235235
KrpcTestClient(rpcClientConfig {

0 commit comments

Comments
 (0)