Skip to content

Commit

Permalink
Add source of start xctest installer (#1385)
Browse files Browse the repository at this point in the history
  • Loading branch information
amanjeetsingh150 authored Aug 25, 2023
1 parent 61d6d3a commit 5fcec04
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 5fcec04

Please sign in to comment.