From ccdafb9328324e3e4a41155e235f153f90c9eb73 Mon Sep 17 00:00:00 2001 From: "nikita.smirnov" Date: Mon, 30 Oct 2023 10:39:03 +0400 Subject: [PATCH] Reduced the whole default gRPC timeout to 1 minute --- README.md | 2 +- .../configuration/GrpcRetryConfiguration.kt | 8 ++--- .../grpc/router/impl/DefaultGrpcRouterTest.kt | 33 +++++++------------ 3 files changed, 15 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index c04d9420d..f51cff8c9 100644 --- a/README.md +++ b/README.md @@ -505,7 +505,7 @@ dependencies { #### Fix: + gRPC `retryConfiguration` has been moved from grpc.json to grpc_router.json -+ the whole default gRPC retry interval is about 1 hour ++ the whole default gRPC retry interval is about 1 minute #### Updated: + grpc-service-generator: `3.5.0` diff --git a/src/main/kotlin/com/exactpro/th2/common/schema/grpc/configuration/GrpcRetryConfiguration.kt b/src/main/kotlin/com/exactpro/th2/common/schema/grpc/configuration/GrpcRetryConfiguration.kt index 95d93fdef..49bd1349a 100644 --- a/src/main/kotlin/com/exactpro/th2/common/schema/grpc/configuration/GrpcRetryConfiguration.kt +++ b/src/main/kotlin/com/exactpro/th2/common/schema/grpc/configuration/GrpcRetryConfiguration.kt @@ -18,9 +18,9 @@ import com.exactpro.th2.common.schema.configuration.Configuration import com.exactpro.th2.service.RetryPolicy data class GrpcRetryConfiguration( - private var maxAttempts: Int = 60, + private var maxAttempts: Int = 15, var minMethodRetriesTimeout: Long = 100, - var maxMethodRetriesTimeout: Long = 120_000, + var maxMethodRetriesTimeout: Long = 7000, var retryInterruptedTransaction: Boolean = false, ) : Configuration(), RetryPolicy { @@ -53,7 +53,5 @@ data class GrpcRetryConfiguration( override fun getMaxAttempts(): Int = maxAttempts - override fun retryInterruptedTransaction(): Boolean { - return retryInterruptedTransaction - } + override fun retryInterruptedTransaction(): Boolean = retryInterruptedTransaction } \ No newline at end of file diff --git a/src/test/kotlin/com/exactpro/th2/common/schema/grpc/router/impl/DefaultGrpcRouterTest.kt b/src/test/kotlin/com/exactpro/th2/common/schema/grpc/router/impl/DefaultGrpcRouterTest.kt index 70ad415b2..9f4c8eeb9 100644 --- a/src/test/kotlin/com/exactpro/th2/common/schema/grpc/router/impl/DefaultGrpcRouterTest.kt +++ b/src/test/kotlin/com/exactpro/th2/common/schema/grpc/router/impl/DefaultGrpcRouterTest.kt @@ -62,7 +62,7 @@ import kotlin.test.assertNotNull import kotlin.test.assertTrue @IntegrationTest -internal open class DefaultGrpcRouterTest { +internal class DefaultGrpcRouterTest { @IntegrationTest abstract inner class AbstractGrpcRouterTest { private val grpcRouterClient = DefaultGrpcRouter() @@ -169,7 +169,7 @@ internal open class DefaultGrpcRouterTest { } clientServerBaton.get("wait client thread start") - Thread.sleep(RETRY_TIMEOUT * 2) + Thread.sleep(RETRY_TIMEOUT / 2) createServer().execAndClose { val response = future.get(1, TimeUnit.MINUTES) @@ -408,7 +408,7 @@ internal open class DefaultGrpcRouterTest { val streamObserver = mock> { } createClientAsync().singleRequestSingleResponse(Request.newBuilder().setSeq(1).build(), streamObserver) - Thread.sleep(RETRY_TIMEOUT * 2) + Thread.sleep(RETRY_TIMEOUT / 2) createServer().execAndClose { val captor = argumentCaptor { } @@ -511,16 +511,6 @@ internal open class DefaultGrpcRouterTest { val streamObserver = mock> { } val handlerBaton = Baton("handler") -// val clientServerBaton = Baton("client-server") -// val future = executor.submit { -// clientServerBaton.giveAndGet("client thread started", "wait server start") -// createClientSync(retryInterruptedTransaction = true).singleRequestSingleResponse( -// Request.newBuilder().setSeq(1).build() -// ) -// } -// -// val handlerBaton = Baton("handler") - createServer(completeResponse = false, handlerBaton = handlerBaton).execAndClose(true) { createClientAsync(retryInterruptedTransaction = true).singleRequestSingleResponse(Request.newBuilder().setSeq(1).build(), streamObserver) handlerBaton.get("wait response sent") @@ -528,7 +518,6 @@ internal open class DefaultGrpcRouterTest { } verifyNoMoreInteractions(streamObserver) -// assertFalse(future.isDone) DefaultGrpcRouter().use { grpcRouter -> createServer(grpcRouter = grpcRouter).execAndClose { @@ -663,11 +652,11 @@ internal open class DefaultGrpcRouterTest { } companion object { - protected val K_LOGGER = KotlinLogging.logger { } + private val K_LOGGER = KotlinLogging.logger { } - protected const val SERVER_PORT = 8080 - protected const val RETRY_TIMEOUT = 1_000L - protected inline fun Server.execAndClose(force: Boolean = false, func: Server.() -> Unit = { }) { + private const val SERVER_PORT = 8080 + private const val RETRY_TIMEOUT = 1_000L + private inline fun Server.execAndClose(force: Boolean = false, func: Server.() -> Unit = { }) { try { val startTime = Instant.now() func() @@ -685,7 +674,7 @@ internal open class DefaultGrpcRouterTest { } } - protected fun assertException( + private fun assertException( exception: Throwable, exceptionMetadata: ExceptionMetadata, path: List = emptyList() @@ -719,10 +708,10 @@ internal open class DefaultGrpcRouterTest { } ?: assertNull(exception.cause, "Cause for exception: $exception, path: ${path.printAsStackTrace()}") } - protected fun List.printAsStackTrace() = asSequence() + private fun List.printAsStackTrace() = asSequence() .joinToString(separator = "\n -> ", prefix = "\n -> ") - protected fun ExecutorService.shutdownGracefully() { + private fun ExecutorService.shutdownGracefully() { shutdown() if (!awaitTermination(1, TimeUnit.SECONDS)) { shutdownNow() @@ -759,7 +748,7 @@ internal open class DefaultGrpcRouterTest { } } - protected class TestServiceHandler( + private class TestServiceHandler( private val complete: Boolean = true, private val responseBaton: Baton? = null, ) : TestImplBase() {