Repository: ktorio/ktor
File: ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/HttpRequestRetryTest.kt (Kotlin)

Code before:
                addHandler {
                    if (counter < maxRetriesCount) {
                        counter++
                        respondError(HttpStatusCode.InternalServerError)
                    } else {
                        respondOk()
                    }
                }
            }

            install(HttpRequestRetry) {
                retryOnServerErrors(maxRetriesCount)
                delayMillis { 0L }
            }
            install(HttpSend) {
                maxSendCount = 1
            }
        }

        test { client ->
            assertEquals(HttpStatusCode.OK, client.get("/").status)
            assertEquals(maxRetriesCount, counter)
        }
    }

    @Test
    fun testRetryWithMaxValueDoesNotFailAllRequests() = testWithEngine(MockEngine) {
        val maxRetriesCount = Int.MAX_VALUE
        config {
            engine { addHandler { respondOk() } }

            install(HttpRequestRetry) {
                retryOnServerErrors(maxRetriesCount)
                delayMillis { 0L }
            }
            install(HttpSend) {
                maxSendCount = 1
            }
        }

        /**
         * This is testing for a bug specific to using Int.MAX_VALUE as the
         * maxRetriesCount value.
         * No need to actually test retry behavior, as the bug happens
         * immediately, without any retries.
         */
        test { client ->
            assertEquals(HttpStatusCode.OK, client.get("/").status)
        }
    }
}

Review comment (bug):
Minor: This test might become slow again if the overflow bug ever reappears. We can rewrite it a little bit, so it will immediately surface the overflow problem instead of hanging:
```kotlin
@Test
    fun testRetryWithMaxValueDoesNotFailAllRequests() = testWithEngine(MockEngine) {
        val maxRetriesCount = Int.MAX_VALUE
        config {
            engine { addHandler { respondOk() } }

            install(HttpRequestRetry) {
                retryOnExceptionIf(maxRetriesCount) { _, _ ->
                    // request shouldn't fail and shouldn't retry
                    false
                }
            }
        }

        /**
         * This is testing for a bug specific to using Int.MAX_VALUE as the maxRetriesCount value.
         * No need to actually test retry behavior, as the bug happens immediately, without any retries.
         */
        test { client ->
            assertEquals(HttpStatusCode.OK, client.get("/").status)
        }
    }
```

Code after:
                addHandler {
                    if (counter < maxRetriesCount) {
                        counter++
                        respondError(HttpStatusCode.InternalServerError)
                    } else {
                        respondOk()
                    }
                }
            }

            install(HttpRequestRetry) {
                retryOnServerErrors(maxRetriesCount)
                delayMillis { 0L }
            }
            install(HttpSend) {
                maxSendCount = 1
            }
        }

        test { client ->
            assertEquals(HttpStatusCode.OK, client.get("/").status)
            assertEquals(maxRetriesCount, counter)
        }
    }

    @Test
    fun testRetryWithMaxValueDoesNotFailAllRequests() = testWithEngine(MockEngine) {
        val maxRetriesCount = Int.MAX_VALUE
        config {
            engine { addHandler { respondOk() } }

            install(HttpRequestRetry) {
                retryOnExceptionIf(maxRetriesCount) { _, _ ->
                    // request shouldn't fail and shouldn't retry
                    false
                }
            }
        }

        /**
         * This is testing for a bug specific to using Int.MAX_VALUE as the
         * maxRetriesCount value.
         * No need to actually test retry behavior, as the bug happens
         * immediately, without any retries.
         */
        test { client ->
            assertEquals(HttpStatusCode.OK, client.get("/").status)
        }
    }
}