Skip to content

Commit

Permalink
Revert "feat: add a more generic retry interceptor to XCTestDriverCli…
Browse files Browse the repository at this point in the history
…ent" (mobile-dev-inc#1247)

Revert "feat: add a more generic retry interceptor to XCTestDriverClient (mobile-dev-inc#1239)"

This reverts commit c50082f.
  • Loading branch information
igorsmotto authored Jul 15, 2023
1 parent 52661d7 commit b4ac78a
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions maestro-ios-driver/src/main/kotlin/xcuitest/XCTestDriverClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class XCTestDriverClient(
private val okHttpClient = OkHttpClient.Builder()
.connectTimeout(10, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.addRetryInterceptor()
.addRetryOnErrorInterceptor()
.addReturnOkOnShutdownInterceptor()
.build()

Expand Down Expand Up @@ -200,25 +200,16 @@ class XCTestDriverClient(
return okHttpClient.newCall(requestBuilder.build()).execute()
}

private fun OkHttpClient.Builder.addRetryInterceptor() = addInterceptor(Interceptor { chain ->
var exception: IOException? = null
repeat(3) {
try {
val response = chain.proceed(chain.request())
if (response.isSuccessful) {
return@Interceptor response
}
} catch (e: IOException) {
installer.start()?.let {
client = it
}
exception = e
}
Thread.sleep(200L)
private fun OkHttpClient.Builder.addRetryOnErrorInterceptor() = addInterceptor(Interceptor {
val request = it.request()
try {
it.proceed(request)
} catch (connectException: IOException) {
installer.start()?.let { newClient ->
client = newClient
it.proceed(request)
} ?: throw XCTestDriverUnreachable("Failed to reach out XCUITest Server in RetryOnError")
}

exception?.let { throw it }
?: throw XCTestDriverUnreachable("Failed to reach out XCUITest Server after 3 attempts")
})

private fun OkHttpClient.Builder.addReturnOkOnShutdownInterceptor() = addNetworkInterceptor(Interceptor {
Expand Down

0 comments on commit b4ac78a

Please sign in to comment.