Skip to content

Commit

Permalink
Reduced the whole default gRPC timeout to 1 minute
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita-Smirnov-Exactpro committed Oct 30, 2023
1 parent 0b54a21 commit ccdafb9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 28 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -53,7 +53,5 @@ data class GrpcRetryConfiguration(

override fun getMaxAttempts(): Int = maxAttempts

override fun retryInterruptedTransaction(): Boolean {
return retryInterruptedTransaction
}
override fun retryInterruptedTransaction(): Boolean = retryInterruptedTransaction
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -408,7 +408,7 @@ internal open class DefaultGrpcRouterTest {
val streamObserver = mock<StreamObserver<Response>> { }
createClientAsync().singleRequestSingleResponse(Request.newBuilder().setSeq(1).build(), streamObserver)

Thread.sleep(RETRY_TIMEOUT * 2)
Thread.sleep(RETRY_TIMEOUT / 2)

createServer().execAndClose {
val captor = argumentCaptor<Response> { }
Expand Down Expand Up @@ -511,24 +511,13 @@ internal open class DefaultGrpcRouterTest {
val streamObserver = mock<StreamObserver<Response>> { }
val handlerBaton = Baton("handler")

// val clientServerBaton = Baton("client-server")
// val future = executor.submit<Response> {
// 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")
Thread.sleep(RETRY_TIMEOUT / 2)
}

verifyNoMoreInteractions(streamObserver)
// assertFalse(future.isDone)

DefaultGrpcRouter().use { grpcRouter ->
createServer(grpcRouter = grpcRouter).execAndClose {
Expand Down Expand Up @@ -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()
Expand All @@ -685,7 +674,7 @@ internal open class DefaultGrpcRouterTest {
}
}

protected fun assertException(
private fun assertException(
exception: Throwable,
exceptionMetadata: ExceptionMetadata,
path: List<String?> = emptyList()
Expand Down Expand Up @@ -719,10 +708,10 @@ internal open class DefaultGrpcRouterTest {
} ?: assertNull(exception.cause, "Cause for exception: $exception, path: ${path.printAsStackTrace()}")
}

protected fun List<String?>.printAsStackTrace() = asSequence()
private fun List<String?>.printAsStackTrace() = asSequence()
.joinToString(separator = "\n -> ", prefix = "\n -> ")

protected fun ExecutorService.shutdownGracefully() {
private fun ExecutorService.shutdownGracefully() {
shutdown()
if (!awaitTermination(1, TimeUnit.SECONDS)) {
shutdownNow()
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit ccdafb9

Please sign in to comment.