From 5fcec04d7d52e0134a934605082a92829e7e6981 Mon Sep 17 00:00:00 2001 From: Amanjeet Singh Date: Fri, 25 Aug 2023 15:22:01 +0530 Subject: [PATCH] Add source of start xctest installer (#1385) --- .../src/test/java/maestro/ios/MockXCTestInstaller.kt | 3 ++- .../src/main/kotlin/xcuitest/XCTestDriverClient.kt | 3 ++- .../src/main/kotlin/xcuitest/api/NetworkErrorHandler.kt | 5 +++-- .../main/kotlin/xcuitest/installer/LocalXCTestInstaller.kt | 4 +++- .../src/main/kotlin/xcuitest/installer/XCTestInstaller.kt | 7 ++++++- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/maestro-client/src/test/java/maestro/ios/MockXCTestInstaller.kt b/maestro-client/src/test/java/maestro/ios/MockXCTestInstaller.kt index f2e0d27657..adbfbc0c17 100644 --- a/maestro-client/src/test/java/maestro/ios/MockXCTestInstaller.kt +++ b/maestro-client/src/test/java/maestro/ios/MockXCTestInstaller.kt @@ -2,6 +2,7 @@ package maestro.ios import com.google.common.truth.Truth.assertThat import xcuitest.XCTestClient +import xcuitest.installer.Source import xcuitest.installer.XCTestInstaller class MockXCTestInstaller( @@ -10,7 +11,7 @@ class MockXCTestInstaller( private var attempts = 0 - override fun start(): XCTestClient? { + override fun start(source: Source): XCTestClient? { attempts++ for (i in 0..simulator.installationRetryCount) { assertThat(simulator.runningApps()).doesNotContain("dev.mobile.maestro-driver-iosUITests.xctrunner") diff --git a/maestro-ios-driver/src/main/kotlin/xcuitest/XCTestDriverClient.kt b/maestro-ios-driver/src/main/kotlin/xcuitest/XCTestDriverClient.kt index 084e26a856..bbfc60008c 100644 --- a/maestro-ios-driver/src/main/kotlin/xcuitest/XCTestDriverClient.kt +++ b/maestro-ios-driver/src/main/kotlin/xcuitest/XCTestDriverClient.kt @@ -15,6 +15,7 @@ import java.io.IOException import java.net.ConnectException import xcuitest.api.NetworkErrorHandler import xcuitest.api.NetworkErrorHandler.Companion.RETRY_RESPONSE_CODE +import xcuitest.installer.Source import java.net.SocketTimeoutException import java.net.UnknownHostException import java.util.concurrent.TimeUnit @@ -46,7 +47,7 @@ class XCTestDriverClient( installer.uninstall() logger.info("[Done] Uninstalling xctest ui runner app") logger.info("[Start] Installing xctest ui runner app") - client = installer.start() + client = installer.start(Source.DRIVER_OPEN) ?: throw XCTestDriverUnreachable("Failed to reach XCUITest Server in restart") logger.info("[Done] Installing xctest ui runner app") } diff --git a/maestro-ios-driver/src/main/kotlin/xcuitest/api/NetworkErrorHandler.kt b/maestro-ios-driver/src/main/kotlin/xcuitest/api/NetworkErrorHandler.kt index 43edbef572..f3cafe37b9 100644 --- a/maestro-ios-driver/src/main/kotlin/xcuitest/api/NetworkErrorHandler.kt +++ b/maestro-ios-driver/src/main/kotlin/xcuitest/api/NetworkErrorHandler.kt @@ -8,6 +8,7 @@ import okhttp3.ResponseBody.Companion.toResponseBody import util.PrintUtils import xcuitest.XCTestClient import xcuitest.api.NetworkException.Companion.toUserNetworkException +import xcuitest.installer.Source import xcuitest.installer.XCTestInstaller import kotlin.math.log @@ -67,7 +68,7 @@ class NetworkErrorHandler( reInitializeInstaller: (XCTestClient) -> Unit ): Response { return if (retry < MAX_RETRY) { - xcTestInstaller.start()?.let { + xcTestInstaller.start(Source.RETRY)?.let { reInitializeInstaller(it) } response.close() @@ -96,7 +97,7 @@ class NetworkErrorHandler( ): Response { logger.info("Got Network exception in application layer: $networkException") return if (networkException.shouldRetryDriverInstallation() && retry < MAX_RETRY) { - xcTestInstaller.start()?.let { + xcTestInstaller.start(Source.RETRY)?.let { reInitializeInstaller(it) } retry++ diff --git a/maestro-ios-driver/src/main/kotlin/xcuitest/installer/LocalXCTestInstaller.kt b/maestro-ios-driver/src/main/kotlin/xcuitest/installer/LocalXCTestInstaller.kt index c99cd9d5e8..f8087750ac 100644 --- a/maestro-ios-driver/src/main/kotlin/xcuitest/installer/LocalXCTestInstaller.kt +++ b/maestro-ios-driver/src/main/kotlin/xcuitest/installer/LocalXCTestInstaller.kt @@ -60,7 +60,7 @@ class LocalXCTestInstaller( logger.info("[Done] Stop XCUITest runner") } - override fun start(): XCTestClient? { + override fun start(source: Source): XCTestClient? { if (useXcodeTestRunner) { repeat(20) { if (ensureOpen()) { @@ -74,6 +74,8 @@ class LocalXCTestInstaller( stop() + logger.info("Starting xctest runner with source $source") + repeat(3) { i -> logger.info("[Start] Install XCUITest runner on $deviceId") startXCTestRunner() diff --git a/maestro-ios-driver/src/main/kotlin/xcuitest/installer/XCTestInstaller.kt b/maestro-ios-driver/src/main/kotlin/xcuitest/installer/XCTestInstaller.kt index b77a2a1c8b..6e00824b79 100644 --- a/maestro-ios-driver/src/main/kotlin/xcuitest/installer/XCTestInstaller.kt +++ b/maestro-ios-driver/src/main/kotlin/xcuitest/installer/XCTestInstaller.kt @@ -3,9 +3,14 @@ package xcuitest.installer import xcuitest.XCTestClient interface XCTestInstaller: AutoCloseable { - fun start(): XCTestClient? + fun start(source: Source): XCTestClient? fun uninstall() fun isChannelAlive(): Boolean } + +enum class Source { + RETRY, + DRIVER_OPEN +}