Skip to content

Commit 51f2db5

Browse files
committed
wait for call to close before asserting
1 parent 979174d commit 51f2db5

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

kroto-plus-coroutines/src/test/kotlin/com/github/marcoferrer/krotoplus/coroutines/client/ClientCallBidiStreamingTests.kt

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ class ClientCallBidiStreamingTests :
136136
responseChannel.consumeAsFlow().map { it.message }.toList()
137137
}
138138

139+
callState.blockUntilClosed()
140+
139141
assertEquals(3,result.size)
140142
result.forEachIndexed { index, message ->
141143
assertEquals("Req:#$index/Resp:#$index",message)
@@ -180,6 +182,8 @@ class ClientCallBidiStreamingTests :
180182
}
181183
}
182184

185+
callState.blockUntilClosed()
186+
183187
assert(requestChannel.isClosedForSend) { "Request channel should be closed for send" }
184188
assert(responseChannel.isClosedForReceive) { "Response channel should be closed for receive" }
185189
}
@@ -222,6 +226,8 @@ class ClientCallBidiStreamingTests :
222226
}
223227
}
224228

229+
callState.blockUntilCancellation()
230+
225231
verify(exactly = 1) { rpcSpy.call.cancel(any(), any()) }
226232
assert(requestChannel.isClosedForSend) { "Request channel should be closed for send" }
227233
assert(responseChannel.isClosedForReceive) { "Response channel should be closed for receive" }
@@ -272,6 +278,8 @@ class ClientCallBidiStreamingTests :
272278
}
273279
}
274280

281+
callState.blockUntilCancellation()
282+
275283
verify(exactly = 1) { rpcSpy.call.cancel(any(), any()) }
276284
assert(requestChannel.isClosedForSend) { "Request channel should be closed for send" }
277285
assert(responseChannel.isClosedForReceive) { "Response channel should be closed for receive" }
@@ -317,6 +325,8 @@ class ClientCallBidiStreamingTests :
317325
}
318326
}
319327

328+
callState.blockUntilCancellation()
329+
320330
verify(exactly = 1) { rpcSpy.call.cancel(any(), any()) }
321331
assert(requestChannel.isClosedForSend) { "Request channel should be closed for send" }
322332
assert(responseChannel.isClosedForReceive) { "Response channel should be closed for receive" }
@@ -345,18 +355,15 @@ class ClientCallBidiStreamingTests :
345355
requestChannel.close(expectedException)
346356
}
347357

348-
//TODO: Cleanup
349-
// cause = Status.CANCELLED
350-
// .withDescription("Cancelled by client with StreamObserver.onError()")
351-
// .withCause(expectedException)
352-
// .asRuntimeException()
353358
assertFailsWithStatus2(Status.CANCELLED, "CANCELLED: $expectedCancelMessage") {
354359
responseChannel.consumeAsFlow()
355360
.map { it.message }
356361
.collect { result.add(it) }
357362
}
358363
}
359364

365+
callState.blockUntilCancellation()
366+
360367
assert(result.isNotEmpty())
361368
result.forEachIndexed { index, message ->
362369
assertEquals("Req:#$index/Resp:#$index",message)
@@ -386,11 +393,6 @@ class ClientCallBidiStreamingTests :
386393
result.add(responseChannel.receive().message)
387394
requestChannel.close(expectedException)
388395

389-
//TODO clean up
390-
// cause = Status.CANCELLED
391-
// .withDescription("Cancelled by client with StreamObserver.onError()")
392-
// .withCause(expectedException)
393-
// .asRuntimeException()
394396
assertFailsWithStatus2(Status.CANCELLED, "CANCELLED: $expectedCancelMessage") {
395397
responseChannel.consumeAsFlow()
396398
.collect { result.add(it.message) }
@@ -437,6 +439,7 @@ class ClientCallBidiStreamingTests :
437439
responseChannel.cancel()
438440
}
439441

442+
callState.blockUntilCancellation()
440443

441444
verify(exactly = 1) { rpcSpy.call.cancel(MESSAGE_CLIENT_CANCELLED_CALL,matchStatus(Status.CANCELLED)) }
442445
assert(requestChannel.isClosedForSend) { "Request channel should be closed for send" }

kroto-plus-coroutines/src/test/kotlin/com/github/marcoferrer/krotoplus/coroutines/integration/BidiStreamingTests.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,7 @@ class BidiStreamingTests : RpcCallTest<HelloRequest, HelloReply>(GreeterCoroutin
133133

134134
runBlocking { serverJob.join() }
135135

136-
// 1 - Server requests and receives
137-
// 2 - Message is loaded into outbound buffer
138-
// 3 - Suspending invocation awaiting next onReady
139-
coVerify(exactly = 3) { reqChanSpy.send(any()) }
136+
coVerify(exactly = 2) { reqChanSpy.send(any()) }
140137
assert(reqChanSpy.isClosedForSend) { "Request channel should be closed after response channel is closed" }
141138
}
142139

0 commit comments

Comments
 (0)