Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow remote xctest connections w/ a flag #2179

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions maestro-ios-driver/src/main/kotlin/util/CommandLineUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ object CommandLineUtils {
private val logger = LoggerFactory.getLogger(CommandLineUtils::class.java)

@Suppress("SpreadOperator")
fun runCommand(parts: List<String>, waitForCompletion: Boolean = true, outputFile: File? = null, params: Map<String, String> = emptyMap()): Process {
fun runCommand(parts: List<String>, waitForCompletion: Boolean = true, outputFile: File? = null, envVars: Map<String, String> = emptyMap()): Process {
logger.info("Running command line operation: $parts")

val processBuilder = if (outputFile != null) {
Expand All @@ -27,7 +27,7 @@ object CommandLineUtils {
.redirectError(nullFile)
}

processBuilder.environment().putAll(params)
processBuilder.environment().putAll(envVars)
val process = processBuilder.start()

if (waitForCompletion) {
Expand Down
5 changes: 2 additions & 3 deletions maestro-ios-driver/src/main/kotlin/util/XCRunnerCLIUtils.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package util

import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import maestro.utils.MaestroTimer
import net.harawata.appdirs.AppDirsFactory
import java.io.File
import java.nio.file.Files
Expand Down Expand Up @@ -121,7 +120,7 @@ object XCRunnerCLIUtils {
return runningApps(deviceId)[bundleId]
}

fun runXcTestWithoutBuild(deviceId: String, xcTestRunFilePath: String, port: Int, enableXCTestOutputFileLogging: Boolean = false): Process {
fun runXcTestWithoutBuild(deviceId: String, xcTestRunFilePath: String, port: Int, enableXCTestOutputFileLogging: Boolean = false, acceptRemoteConnections: Boolean = false): Process {
val date = dateFormatter.format(LocalDateTime.now())
val outputFile = if (enableXCTestOutputFileLogging) {
File(logDirectory, "xctest_runner_$date.log")
Expand All @@ -142,7 +141,7 @@ object XCRunnerCLIUtils {
),
waitForCompletion = false,
outputFile = outputFile,
params = mapOf("TEST_RUNNER_PORT" to port.toString())
envVars = mapOf("TEST_RUNNER_PORT" to port.toString(), "ACCEPT_REMOTE_CONNECTIONS" to acceptRemoteConnections.toString())
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class LocalXCTestInstaller(
connectTimeout = 1.seconds,
readTimeout = 100.seconds,
),
private val acceptRemoteConnections: Boolean = false,
) : XCTestInstaller {

private val logger = LoggerFactory.getLogger(LocalXCTestInstaller::class.java)
Expand Down Expand Up @@ -202,6 +203,7 @@ class LocalXCTestInstaller(
xcTestRunFilePath = xctestRunFile.absolutePath,
port = defaultPort,
enableXCTestOutputFileLogging = enableXCTestOutputFileLogging,
acceptRemoteConnections = acceptRemoteConnections,
)
logger.info("[Done] Running XcUITest with `xcodebuild test-without-building`")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
<string>YES</string>
<key>SQLITE_ENABLE_THREAD_ASSERTIONS</key>
<string>1</string>
<key>TERM</key>
<string>dumb</string>
</dict>
<key>IsUITestBundle</key>
<true/>
Expand Down
Binary file modified maestro-ios-driver/src/main/resources/maestro-driver-ios.zip
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@ enum Route: String, CaseIterable {

struct XCTestHTTPServer {
func start() async throws {
let port = ProcessInfo.processInfo.environment["PORT"]?.toUInt16()
let server = HTTPServer(address: .loopback(port: port ?? 22087), timeout: 100)
let port = ProcessInfo.processInfo.environment["PORT"]?.toUInt16() ?? 22087

let acceptRemoteConnections = ProcessInfo.processInfo.environment["ACCEPT_REMOTE_CONNECTIONS"] == "true"

let server = acceptRemoteConnections ? HTTPServer(port: port) : HTTPServer(address: .loopback(port: port), timeout: 100)

for route in Route.allCases {
let handler = await RouteHandlerFactory.createRouteHandler(route: route)
await server.appendRoute(route.toHTTPRoute(), to: handler)
}

try await server.start()
}
}
Loading