Skip to content

Commit

Permalink
fix: update maestro test to respect --host and --port arguments (#2235)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leland-Takamine authored Jan 10, 2025
1 parent 42c9c78 commit 0945c4a
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class PrintHierarchyCommand : Runnable {
MaestroSessionManager.newSession(
host = parent?.host,
port = parent?.port,
driverHostPort = parent?.port,
driverHostPort = null,
deviceId = parent?.deviceId,
platform = parent?.platform,
) { session ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class QueryCommand : Runnable {
MaestroSessionManager.newSession(
host = parent?.host,
port = parent?.port,
driverHostPort = parent?.port,
driverHostPort = null,
deviceId = parent?.deviceId,
platform = parent?.platform,
) { session ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class RecordCommand : Callable<Int> {
return MaestroSessionManager.newSession(
host = parent?.host,
port = parent?.port,
driverHostPort = parent?.port,
driverHostPort = null,
deviceId = deviceId,
platform = parent?.platform,
) { session ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class StudioCommand : Callable<Int> {
MaestroSessionManager.newSession(
host = parent?.host,
port = parent?.port,
driverHostPort = parent?.port,
driverHostPort = null,
deviceId = parent?.deviceId,
platform = parent?.platform,
isStudio = true
Expand Down
10 changes: 7 additions & 3 deletions maestro-cli/src/main/java/maestro/cli/command/TestCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import maestro.orchestra.workspace.WorkspaceExecutionPlanner
import maestro.orchestra.workspace.WorkspaceExecutionPlanner.ExecutionPlan
import maestro.utils.isSingleFile
import okio.sink
import org.jetbrains.skiko.hostId
import org.slf4j.LoggerFactory
import picocli.CommandLine
import picocli.CommandLine.Option
Expand Down Expand Up @@ -209,8 +210,11 @@ class TestCommand : Callable<Int> {

val onlySequenceFlows = plan.sequence.flows.isNotEmpty() && plan.flowsToRun.isEmpty() // An edge case

val availableDevices =
DeviceService.listConnectedDevices(includeWeb = isWebFlow()).map { it.instanceId }.toSet()
val availableDevices = DeviceService.listConnectedDevices(
includeWeb = isWebFlow(),
host = parent?.host,
port = parent?.port,
).map { it.instanceId }.toSet()
val deviceIds = getPassedOptionsDeviceIds()
.filter { device ->
if (device !in availableDevices) {
Expand Down Expand Up @@ -330,7 +334,7 @@ class TestCommand : Callable<Int> {
}

private fun selectPort(effectiveShards: Int): Int =
if (effectiveShards == 1) parent?.port ?: 7001
if (effectiveShards == 1) 7001
else (7001..7128).shuffled().find { port ->
usedPorts.putIfAbsent(port, true) == null
} ?: error("No available ports found")
Expand Down
27 changes: 21 additions & 6 deletions maestro-cli/src/main/java/maestro/cli/device/DeviceService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,12 @@ object DeviceService {
}
}

fun listConnectedDevices(includeWeb: Boolean = false): List<Device.Connected> {
return listDevices(includeWeb = includeWeb)
fun listConnectedDevices(
includeWeb: Boolean = false,
host: String? = null,
port: Int? = null,
): List<Device.Connected> {
return listDevices(includeWeb = includeWeb, host, port)
.filterIsInstance<Device.Connected>()
}

Expand All @@ -130,8 +134,8 @@ object DeviceService {
.filterIsInstance<Device.AvailableForLaunch>()
}

private fun listDevices(includeWeb: Boolean): List<Device> {
return listAndroidDevices() +
private fun listDevices(includeWeb: Boolean, host: String? = null, port: Int? = null): List<Device> {
return listAndroidDevices(host, port) +
listIOSDevices() +
if (includeWeb) {
listWebDevices()
Expand All @@ -150,9 +154,20 @@ object DeviceService {
)
}

private fun listAndroidDevices(): List<Device> {
private fun listAndroidDevices(host: String? = null, port: Int? = null): List<Device> {
val host = host ?: "localhost"
if (port != null) {
val dadb = Dadb.create(host, port)
return listOf(
Device.Connected(
instanceId = dadb.toString(),
description = dadb.toString(),
platform = Platform.ANDROID,
)
)
}
val connected = runCatching {
Dadb.list().map {
Dadb.list(host = host).map {
Device.Connected(
instanceId = it.toString(),
description = it.toString(),
Expand Down

0 comments on commit 0945c4a

Please sign in to comment.