-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Structural output refresh last run
- Loading branch information
Piotr Adamczyk
authored and
mergify-bot
committed
Aug 16, 2021
1 parent
b3e157b
commit c563871
Showing
24 changed files
with
207 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,26 @@ | ||
package ftl.domain | ||
|
||
import ftl.args.AndroidArgs | ||
import ftl.presentation.Output | ||
import ftl.presentation.RunState | ||
import ftl.presentation.runBlockingWithObservingRunState | ||
import ftl.run.refreshLastRun | ||
|
||
interface RefreshLastRun | ||
interface RefreshLastRun : Output | ||
|
||
suspend operator fun RefreshLastRun.invoke() { | ||
refreshLastRun( | ||
currentArgs = AndroidArgs.default(), | ||
testShardChunks = emptyList() | ||
) | ||
operator fun RefreshLastRun.invoke() { | ||
runBlockingWithObservingRunState { | ||
refreshLastRun( | ||
currentArgs = AndroidArgs.default(), | ||
testShardChunks = emptyList() | ||
) | ||
} | ||
} | ||
|
||
sealed interface RefreshLastRunState : RunState { | ||
data class LoadingRun(val lastRun: String) : RefreshLastRunState | ||
object RefreshMatricesStarted : RefreshLastRunState | ||
data class RefreshMatrices(val matrixCount: Int) : RefreshLastRunState | ||
data class RefreshMatrix(val matrixState: String, val matrixId: String) : RefreshLastRunState | ||
object UpdatingMatrixFile : RefreshLastRunState | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package ftl.presentation | ||
|
||
import com.google.common.annotations.VisibleForTesting | ||
import kotlinx.coroutines.flow.MutableSharedFlow | ||
import kotlinx.coroutines.flow.collect | ||
import kotlinx.coroutines.launch | ||
import kotlinx.coroutines.runBlocking | ||
|
||
interface RunState | ||
|
||
@VisibleForTesting | ||
internal val runSharedFlow by lazy { | ||
MutableSharedFlow<RunState>(extraBufferCapacity = 1) | ||
} | ||
|
||
internal fun Output.runBlockingWithObservingRunState(block: suspend () -> Unit) { | ||
runBlocking { | ||
val runStateCollectJob = launch { | ||
runSharedFlow.collect { runState -> runState.out() } | ||
} | ||
block() | ||
runStateCollectJob.cancel() | ||
} | ||
} | ||
|
||
internal fun RunState.publish() { | ||
runSharedFlow.tryEmit(this) | ||
} |
2 changes: 1 addition & 1 deletion
2
test_runner/src/main/kotlin/ftl/presentation/cli/FirebaseCommand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...unner/src/main/kotlin/ftl/presentation/cli/firebase/test/refresh/HandleRefreshRunState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package ftl.presentation.cli.firebase.test.refresh | ||
|
||
import ftl.config.FtlConstants | ||
import ftl.domain.RefreshLastRunState | ||
|
||
internal fun handleRefreshLastRunState(state: RefreshLastRunState): String = when (state) { | ||
is RefreshLastRunState.LoadingRun -> "Loading run ${state.lastRun}" | ||
is RefreshLastRunState.RefreshMatrices -> "${FtlConstants.indent}Refreshing ${state.matrixCount}x matrices" | ||
RefreshLastRunState.RefreshMatricesStarted -> "RefreshMatrices" | ||
is RefreshLastRunState.RefreshMatrix -> "${FtlConstants.indent} ${state.matrixState} ${state.matrixId}" | ||
RefreshLastRunState.UpdatingMatrixFile -> "${FtlConstants.indent}Updating matrix file" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
.../main/kotlin/ftl/presentation/cli/firebase/test/reportmanager/HandleReportManagerState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package ftl.presentation.cli.firebase.test.reportmanager | ||
|
||
import flank.common.newLine | ||
import flank.common.withNewLineAtTheEnd | ||
import ftl.presentation.RunState | ||
import ftl.reports.util.ReportManager | ||
import kotlin.math.roundToInt | ||
|
||
sealed interface ReportManagerState : RunState { | ||
data class Log(val message: String) : ReportManagerState | ||
data class Warning(val message: String) : ReportManagerState | ||
data class ShardTimes(val shards: List<ReportManager.ShardEfficiency>) : ReportManagerState | ||
} | ||
|
||
internal fun handleReportManagerState(state: ReportManagerState): String = when (state) { | ||
is ReportManagerState.Log -> state.message | ||
is ReportManagerState.Warning -> "WARNING: ${state.message}" | ||
is ReportManagerState.ShardTimes -> "Actual shard times:$newLine" + state.shards.joinToString(newLine) { | ||
" ${it.shard}: Expected: ${it.expectedTime.roundToInt()}s, Actual: ${it.finalTime.roundToInt()}s, Diff: ${it.timeDiff.roundToInt()}s" | ||
}.withNewLineAtTheEnd() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.