Skip to content

Commit

Permalink
Revert "last fixes"
Browse files Browse the repository at this point in the history
This reverts commit 8081566.
  • Loading branch information
bartekpacia committed Sep 3, 2024
1 parent 8081566 commit cda89fa
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions maestro-cli/src/main/java/maestro/cli/command/TestCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,7 @@ class TestCommand : Callable<Int> {
}

private fun handleSessions(debugOutputPath: Path, plan: ExecutionPlan): Int = runBlocking(Dispatchers.IO) {
val requestedShards = shardSplit ?: shardAll ?: 1
if (requestedShards > 1 && plan.sequence.flows.isNotEmpty()) {
error("Cannot run sharded tests with sequential execution")
}

val shards = shardSplit ?: shardAll ?: 1
val onlySequenceFlows = plan.sequence.flows.isNotEmpty() && plan.flowsToRun.isEmpty() // An edge case

runCatching {
Expand All @@ -217,10 +213,15 @@ class TestCommand : Callable<Int> {
}.toMutableSet())

val availableDevices = if (deviceIds.isNotEmpty()) deviceIds.size else initialActiveDevices.size
val effectiveShards = if (onlySequenceFlows) 1 else requestedShards.coerceAtMost(plan.flowsToRun.size)
val effectiveShards = if (onlySequenceFlows) 1 else shards.coerceAtMost(plan.flowsToRun.size)
val sharded = effectiveShards > 1

if (requestedShards > plan.flowsToRun.size) {
PrintUtils.warn("Requested $requestedShards shards, but it cannot be higher than the number of flows (${plan.flowsToRun.size}). Will use $effectiveShards shards instead.")
if (shards > plan.flowsToRun.size) {
PrintUtils.warn("Requested $shards shards, but it cannot be higher than the number of flows (${plan.flowsToRun.size}). Will use $effectiveShards shards instead.")
}

if (sharded && plan.sequence.flows.isNotEmpty()) {
error("Cannot run sharded tests with sequential execution")
}

val chunkPlans: List<ExecutionPlan> = if (onlySequenceFlows) {
Expand Down Expand Up @@ -254,7 +255,7 @@ class TestCommand : Callable<Int> {
"Will split $flowCount flows across $effectiveShards shards (${prefix}$flowsPerShard flows per shard)"
}

else -> "Will run $flowCount flows in a single shard"
else -> "Will run $flowCount in a single shard"
}

appendLine(message)
Expand All @@ -277,13 +278,9 @@ class TestCommand : Callable<Int> {

val results = (0 until effectiveShards).map { shardIndex ->
async(Dispatchers.IO) {
val driverHostPort = if (effectiveShards == 1) {
parent?.port ?: 7001
} else {
(7001..7128).shuffled().find { port ->
usedPorts.putIfAbsent(port, true) == null
} ?: error("No available ports found")
}
val driverHostPort = if (!sharded) parent?.port ?: 7001 else (7001..7128).shuffled().find { port ->
usedPorts.putIfAbsent(port, true) == null
} ?: error("No available ports found")

// Acquire lock to execute device creation block
deviceCreationSemaphore.acquire()
Expand Down Expand Up @@ -383,7 +380,7 @@ class TestCommand : Callable<Int> {

suites.mergeSummaries()?.saveReport()

if (effectiveShards > 1) printShardsMessage(passed, total, suites)
if (sharded) printShardsMessage(passed, total, suites)
if (passed == total) 0 else 1
}.onFailure {
PrintUtils.message("❌ Error: ${it.message}")
Expand Down

0 comments on commit cda89fa

Please sign in to comment.