Skip to content

Commit 1ec13a6

Browse files
committed
grpc: Add client interceptor execution order test
Signed-off-by: Johannes Zottele <[email protected]>
1 parent 121e5e9 commit 1ec13a6

File tree

1 file changed

+41
-4
lines changed

1 file changed

+41
-4
lines changed

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

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,21 +279,58 @@ class ClientInterceptorTest : GrpcProtoTest() {
279279
}
280280
}
281281

282+
@Test
283+
fun `test exact order of interceptor execution`() {
284+
val order = mutableListOf<Int>()
285+
val interceptor1 = interceptor { request ->
286+
order.add(1)
287+
flow {
288+
order.add(2)
289+
val req = request.map { order.add(5); it }
290+
proceed(req).collect {
291+
order.add(8)
292+
emit(it)
293+
}
294+
order.add(10)
295+
}
296+
}
297+
val interceptor2 = interceptor { request ->
298+
order.add(3)
299+
flow {
300+
order.add(4)
301+
val req = request.map { order.add(6); it }
302+
proceed(req).collect {
303+
order.add(7)
304+
emit(it)
305+
}
306+
order.add(9)
307+
}
308+
}
309+
310+
val both = interceptor1 + interceptor2
311+
runGrpcTest(clientInterceptors = both) { unaryCall(it) }
312+
313+
assertEquals(
314+
listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
315+
order
316+
)
317+
}
318+
282319
private suspend fun unaryCall(grpcClient: GrpcClient) {
283320
val service = grpcClient.withService<EchoService>()
284321
val response = service.UnaryEcho(EchoRequest { message = "Hello" })
285322
assertEquals("Hello", response.message)
286323
}
287324

288-
private suspend fun bidiStream(grpcClient: GrpcClient) {
325+
private suspend fun bidiStream(grpcClient: GrpcClient, count: Int = 5) {
289326
val service = grpcClient.withService<EchoService>()
290327
val responses = service.BidirectionalStreamingEcho(flow {
291-
repeat(5) {
328+
repeat(count) {
292329
emit(EchoRequest { message = "Echo-$it" })
293330
}
294331
}).toList()
295-
assertEquals(5, responses.size)
296-
repeat(5) {
332+
assertEquals(count, responses.size)
333+
repeat(count) {
297334
assertEquals("Echo-$it", responses[it].message)
298335
}
299336
}

0 commit comments

Comments
 (0)