Skip to content

Commit 244c5bf

Browse files
committed
grpc-native: Test fix
Signed-off-by: Johannes Zottele <[email protected]>
1 parent f583112 commit 244c5bf

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

grpc/grpc-core/src/commonTest/kotlin/kotlinx/rpc/grpc/test/CoreClientTest.kt

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package kotlinx.rpc.grpc.test
55

66
import kotlinx.coroutines.CompletableDeferred
77
import kotlinx.coroutines.delay
8-
import kotlinx.coroutines.launch
98
import kotlinx.coroutines.runBlocking
109
import kotlinx.coroutines.withTimeout
1110
import kotlinx.rpc.grpc.GrpcServer
@@ -62,8 +61,12 @@ class GrpcCoreClientTest {
6261
this.timeout = timeout
6362
}
6463

65-
private fun shutdownAndWait(channel: ManagedChannel) {
66-
channel.shutdown()
64+
private fun shutdownAndWait(channel: ManagedChannel, now: Boolean = false) {
65+
if (now) {
66+
channel.shutdownNow()
67+
} else {
68+
channel.shutdown()
69+
}
6770
runBlocking { channel.awaitTermination() }
6871
}
6972

@@ -190,10 +193,10 @@ class GrpcCoreClientTest {
190193
@Test
191194
fun halfCloseBeforeSendingMessage_errorWithoutCrashing() {
192195
val channel = createChannel()
193-
val call = channel.newHelloCall()
194-
val statusDeferred = CompletableDeferred<Status>()
196+
// val call = channel.newHelloCall()
197+
val call = channel.newHelloCall(fullName = "helloworld.Greeter/SayHello")
195198
val listener = createClientCallListener<HelloReply>(
196-
onClose = { status, _ -> statusDeferred.complete(status) }
199+
onClose = { status, _ -> println("Status: ${status.statusCode}, Message: ${status.getDescription()}") }
197200
)
198201
assertFailsWith<IllegalStateException> {
199202
try {
@@ -277,24 +280,15 @@ class GreeterServiceImpl : GreeterService {
277280
builder = { registerService<GreeterService> { GreeterServiceImpl() } }
278281
)
279282

280-
launch {
281-
println("Terminating in 10 seconds")
282-
delay(10000)
283-
server.shutdown()
284-
server.awaitTermination()
285-
}
286-
287-
launch {
283+
try {
288284
server.start()
289285
println("Server started")
290286
server.awaitTermination()
287+
} finally {
288+
server.shutdown()
289+
server.awaitTermination()
291290
}
292291
}
293-
294-
// runBlocking {
295-
// println("Waiting, so GC is collecting stuff")
296-
// delay(20000)
297-
// }
298292
}
299293

300294
}

grpc/grpc-core/src/nativeMain/kotlin/kotlinx/rpc/grpc/internal/NativeServerCall.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ internal class NativeServerCall<Request, Response>(
181181
arena.clear()
182182
}) {
183183
// if the call was successful, but no message was received, we reached the end-of-stream.
184+
// and thus the client half-closed.
184185
val buf = recvPtr.value
185186
if (buf == null) {
186187
callbackMutex.withLock {

0 commit comments

Comments
 (0)