Skip to content

Commit a329bb0

Browse files
tokoubartekpacia
authored andcommitted
Add broadcast option to test command
1 parent 1bd6734 commit a329bb0

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

maestro-cli/src/main/java/maestro/cli/command/TestCommand.kt

+18-7
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ class TestCommand : Callable<Int> {
8686
)
8787
private var shards: Int = 1
8888

89+
@Option(
90+
names = ["-b", "--broadcast"],
91+
description = ["Broadcasts all the tests across all running devices"]
92+
)
93+
private var broadcast: Boolean = false
94+
8995
@Option(names = ["-c", "--continuous"])
9096
private var continuous: Boolean = false
9197

@@ -178,7 +184,6 @@ class TestCommand : Callable<Int> {
178184
}
179185

180186
private fun handleSessions(debugOutputPath: Path, plan: ExecutionPlan): Int = runBlocking(Dispatchers.IO) {
181-
val sharded = shards > 1
182187

183188
runCatching {
184189
val deviceIds = (if (isWebFlow())
@@ -194,10 +199,16 @@ class TestCommand : Callable<Int> {
194199
initialActiveDevices.addAll(DeviceService.listConnectedDevices().map {
195200
it.instanceId
196201
}.toMutableSet())
197-
val effectiveShards = shards.coerceAtMost(plan.flowsToRun.size)
198-
val chunkPlans = plan.flowsToRun
202+
203+
val availableDevices = if (deviceIds.isNotEmpty()) deviceIds.size else initialActiveDevices.size
204+
val effectiveShards = if (broadcast) availableDevices else shards.coerceAtMost(plan.flowsToRun.size)
205+
val sharded = effectiveShards > 1
206+
207+
val chunkPlans =
208+
if (broadcast) (0 until availableDevices).map { ExecutionPlan(plan.flowsToRun, plan.sequence) }
209+
else plan.flowsToRun
199210
.withIndex()
200-
.groupBy { it.index % shards }
211+
.groupBy { it.index % effectiveShards }
201212
.map { (shardIndex, files) ->
202213
ExecutionPlan(
203214
files.map { it.value },
@@ -209,12 +220,12 @@ class TestCommand : Callable<Int> {
209220
}
210221

211222
// Collect device configurations for missing shards, if any
212-
val missing = effectiveShards - if (deviceIds.isNotEmpty()) deviceIds.size else initialActiveDevices.size
213-
val allDeviceConfigs = (0 until missing).map { shardIndex ->
223+
val missing = effectiveShards - availableDevices
224+
val allDeviceConfigs = if (!broadcast) (0 until missing).map { shardIndex ->
214225
PrintUtils.message("------------------ Shard ${shardIndex + 1} ------------------")
215226
// Collect device configurations here, one per shard
216227
PickDeviceView.requestDeviceOptions()
217-
}.toMutableList()
228+
}.toMutableList() else mutableListOf()
218229

219230
val barrier = CountDownLatch(effectiveShards)
220231

0 commit comments

Comments
 (0)