Skip to content

Commit b10554d

Browse files
committed
fix the bug
1 parent b2d6960 commit b10554d

5 files changed

Lines changed: 51 additions & 23 deletions

File tree

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

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -151,34 +151,36 @@ class TestCommand : Callable<Int> {
151151
}
152152

153153
override fun call(): Int {
154+
TestDebugReporter.install(
155+
debugOutputPathAsString = debugOutput,
156+
flattenDebugOutput = flattenDebugOutput,
157+
printToConsole = parent?.verbose == true,
158+
)
159+
154160
if (parent?.platform != null) {
155161
throw CliError("--platform option was deprecated. You can remove it to run your test.")
156162
}
157163

158164
val executionPlan = try {
159165
WorkspaceExecutionPlanner.plan(
160-
flowFile.toPath().toAbsolutePath(),
161-
includeTags,
162-
excludeTags
166+
input = flowFile.toPath().toAbsolutePath(),
167+
includeTags = includeTags,
168+
excludeTags = excludeTags,
163169
)
164170
} catch (e: ValidationError) {
165171
throw CliError(e.message)
166172
}
167173

168174
env = env.withInjectedShellEnvVars()
169175

170-
TestDebugReporter.install(
171-
debugOutputPathAsString = debugOutput,
172-
flattenDebugOutput = flattenDebugOutput,
173-
printToConsole = parent?.verbose == true,
174-
)
175176
val debugOutputPath = TestDebugReporter.getDebugOutputPath()
176177

177178
return handleSessions(debugOutputPath, executionPlan)
178179
}
179180

180181
private fun handleSessions(debugOutputPath: Path, plan: ExecutionPlan): Int = runBlocking(Dispatchers.IO) {
181182
val sharded = shards > 1
183+
val onlySequenceFlows = plan.sequence.flows.isNotEmpty() && plan.flowsToRun.isEmpty() // An edge case
182184

183185
runCatching {
184186
val deviceIds = (if (isWebFlow())
@@ -195,23 +197,32 @@ class TestCommand : Callable<Int> {
195197
it.instanceId
196198
}.toMutableSet())
197199

198-
if (shards > 1 && plan.sequence?.flows?.isNotEmpty() == true) {
200+
if (sharded && plan.sequence.flows.isNotEmpty()) {
199201
error("Cannot run sharded tests with sequential execution")
200202
}
201203

202-
val effectiveShards = shards.coerceAtMost(plan.flowsToRun.size)
203-
val chunkPlans = plan.flowsToRun
204-
.withIndex()
205-
.groupBy { it.index % shards }
206-
.map { (shardIndex, files) ->
207-
ExecutionPlan(
208-
files.map { it.value },
209-
plan.sequence.also {
210-
if (it?.flows?.isNotEmpty() == true && sharded)
211-
error("Cannot run sharded tests with sequential execution.")
212-
}
213-
)
214-
}
204+
if (sharded) {
205+
PrintUtils.info("Requested to run ${plan.flowsToRun.size} flows in $shards shard(s)")
206+
}
207+
208+
val effectiveShards = if (onlySequenceFlows) 1 else shards.coerceAtMost(plan.flowsToRun.size)
209+
val chunkPlans: List<ExecutionPlan> = if (onlySequenceFlows) {
210+
// Handle an edge case
211+
// We only want to run sequential flows in this case.
212+
listOf(plan)
213+
} else {
214+
plan.flowsToRun
215+
.withIndex()
216+
.groupBy { it.index % shards }
217+
.map { (shardIndex, files) ->
218+
ExecutionPlan(
219+
flowsToRun = files.map { it.value },
220+
sequence = plan.sequence,
221+
)
222+
}
223+
}
224+
225+
PrintUtils.info("Will run ${if (onlySequenceFlows) plan.sequence.flows.size else plan.flowsToRun.size} flows in $effectiveShards shard(s)")
215226

216227
// Collect device configurations for missing shards, if any
217228
val missing = effectiveShards - if (deviceIds.isNotEmpty()) deviceIds.size else initialActiveDevices.size

maestro-cli/src/main/java/maestro/cli/report/TestDebugReporter.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ object TestDebugReporter {
134134
logger.info("---------------------")
135135
}
136136

137+
/**
138+
* Calls to this method should be done as soon as possible, to make all
139+
* loggers use our custom configuration rather than the defaults.
140+
*/
137141
fun install(debugOutputPathAsString: String?, flattenDebugOutput: Boolean = false, printToConsole: Boolean) {
138142
this.debugOutputPathAsString = debugOutputPathAsString
139143
this.flattenDebugOutput = flattenDebugOutput

maestro-cli/src/main/java/maestro/cli/runner/TestSuiteInteractor.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ import kotlin.time.Duration.Companion.seconds
3333
* Similar to [TestRunner], but:
3434
* * can run many flows at once
3535
* * does not support continuous mode
36+
*
37+
* Does not care about sharding. It only has to know the index of the shard it's running it, for logging purposes.
3638
*/
3739
class TestSuiteInteractor(
3840
private val maestro: Maestro,

maestro-cli/src/main/java/maestro/cli/util/PrintUtils.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ import kotlin.system.exitProcess
66

77
object PrintUtils {
88

9+
fun info(message: String, bold: Boolean = false, newline: Boolean = true) {
10+
val function: (Any) -> Unit = if (newline) ::println else ::print
11+
function(
12+
Ansi.ansi()
13+
.bold(apply = bold)
14+
.render(message)
15+
.boldOff()
16+
)
17+
}
18+
919
fun message(message: String) {
1020
println(Ansi.ansi().render("@|cyan \n$message|@"))
1121
}

maestro-orchestra/src/main/java/maestro/orchestra/workspace/WorkspaceExecutionPlanner.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ object WorkspaceExecutionPlanner {
3939
validateFlowFile(input)
4040
return ExecutionPlan(
4141
flowsToRun = listOf(input),
42+
sequence = FlowSequence(emptyList()),
4243
)
4344
}
4445

@@ -177,6 +178,6 @@ object WorkspaceExecutionPlanner {
177178

178179
data class ExecutionPlan(
179180
val flowsToRun: List<Path>,
180-
val sequence: FlowSequence? = null,
181+
val sequence: FlowSequence,
181182
)
182183
}

0 commit comments

Comments
 (0)