From 75f01a39b15d3502c166b06ad00c0aa57c67d4b4 Mon Sep 17 00:00:00 2001 From: Tarek Belkahia Date: Tue, 27 Aug 2024 02:36:06 +0100 Subject: [PATCH] Prompt user for device creation. --- .../java/maestro/cli/command/TestCommand.kt | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/maestro-cli/src/main/java/maestro/cli/command/TestCommand.kt b/maestro-cli/src/main/java/maestro/cli/command/TestCommand.kt index f1e74a4383..e72a08e36d 100644 --- a/maestro-cli/src/main/java/maestro/cli/command/TestCommand.kt +++ b/maestro-cli/src/main/java/maestro/cli/command/TestCommand.kt @@ -188,10 +188,32 @@ class TestCommand : Callable { val connectedDevices = DeviceService.listConnectedDevices() initialActiveDevices.addAll(connectedDevices.map { it.instanceId }.toSet()) - val effectiveShards = shards.coerceAtMost(plan.flowsToRun.size) + var effectiveShards = shards.coerceAtMost(plan.flowsToRun.size) + + // Collect device configurations for missing shards, if any + val availableDevices = if (deviceIds.isNotEmpty()) deviceIds.size else initialActiveDevices.size + val missingDevices = effectiveShards - availableDevices + if (missingDevices > 0) { + val message = """ + Found $availableDevices active devices. + Need to create or start $missingDevices more for $effectiveShards shards. Continue? y/n + """.trimIndent() + PrintUtils.message(message) + val str = readlnOrNull()?.lowercase() + val granted = str?.isBlank() == true || str == "y" || str == "yes" + if (!granted) { + PrintUtils.message("Continuing with only $availableDevices shards.") + effectiveShards = availableDevices + } + } + val missingDevicesConfigs = (availableDevices until effectiveShards).mapNotNull { shardIndex -> + PrintUtils.message("Creating device for shard ${shardIndex + 1}:") + PickDeviceView.requestDeviceOptions() + }.toMutableList() + val chunkPlans = plan.flowsToRun .withIndex() - .groupBy { it.index % shards } + .groupBy { it.index % effectiveShards } .map { (shardIndex, files) -> ExecutionPlan( files.map { it.value }, @@ -202,15 +224,6 @@ class TestCommand : Callable { ) } - // Collect device configurations for missing shards, if any - val availableDevices = if (deviceIds.isNotEmpty()) deviceIds.size else initialActiveDevices.size - val missingDevices = effectiveShards - availableDevices - val missingDevicesConfigs = (0 until missingDevices).map { shardIndex -> - PrintUtils.message("------------------ Shard ${shardIndex + 1} ------------------") - // Collect device configurations here, one per shard - PickDeviceView.requestDeviceOptions() - }.toMutableList() - val barrier = CountDownLatch(effectiveShards) logger.info("Running $effectiveShards shards on $availableDevices available devices and ${missingDevicesConfigs.size} created devices.")