Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Structural output refresh last run #2139

Merged
merged 1 commit into from
Aug 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ object Dependencies {
const val SYSTEM_RULES = "com.github.stefanbirkner:system-rules:${Versions.SYSTEM_RULES}"
const val TRUTH = "com.google.truth:truth:${Versions.TRUTH}"
const val MOCKK = "io.mockk:mockk:${Versions.MOCKK}"
const val KOTLIN_COROUTINES_TEST = "org.jetbrains.kotlinx:kotlinx-coroutines-test:${Versions.KOTLIN_COROUTINES}"
//endregion

const val COMMON_TEXT = "org.apache.commons:commons-text:${Versions.COMMON_TEXT}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ open class CheckVersionUpdatedTask : DefaultTask() {
@TaskAction
fun action() {
project.execAndGetStdout("git", "fetch", "--no-tags")
val changedFiles = project.execAndGetStdout("git", "diff", "origin/master", "HEAD", "--name-only").split("\n") +
project.execAndGetStdout("git", "diff", "origin/master", "--name-only").split("\n")
val changedFiles = (project.execAndGetStdout("git", "diff", "origin/master", "HEAD", "--name-only").split("\n") +
project.execAndGetStdout("git", "diff", "origin/master", "--name-only").split("\n"))
.toSet()
.filterNot { file -> ignoredFiles.any { ignoredFile -> file.endsWith(ignoredFile) } }


val isVersionChanged = changedFiles.any { it.startsWith(project.name) }.not() ||
(changedFiles.contains("${project.name}/build.gradle.kts") && project.isVersionChangedInBuildGradle())

Expand Down Expand Up @@ -44,4 +48,6 @@ open class CheckVersionUpdatedTask : DefaultTask() {
return (commitedResultsStream + localResultsStream)
.any { it.startsWith("-version = ") || it.startsWith("+version = ") }
}

private val ignoredFiles = listOf("gradle-wrapper.properties", "main/resources/version.txt")
}
2 changes: 0 additions & 2 deletions flank_wrapper/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@

# Ignore Gradle build output directory
build

src/main/resources/version.txt
2 changes: 1 addition & 1 deletion flank_wrapper/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ shadowJar.apply {
}
}
// <breaking change>.<feature added>.<fix/minor change>
version = "1.2.4"
version = "1.2.5"
group = "com.github.flank"

repositories {
Expand Down
2 changes: 1 addition & 1 deletion flank_wrapper/src/main/resources/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.2.3
1.2.4
5 changes: 5 additions & 0 deletions test_runner/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ dependencies {
testImplementation(Dependencies.SYSTEM_RULES)
testImplementation(Dependencies.TRUTH)
testImplementation(Dependencies.MOCKK)
testImplementation(Dependencies.KOTLIN_COROUTINES_TEST)
}

buildscript {
Expand All @@ -231,6 +232,10 @@ buildscript {

tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
kotlinOptions.freeCompilerArgs += listOf(
"-Xopt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
"-Xopt-in=kotlinx.coroutines.FlowPreview",
)
}

// https://github.com/gradle/kotlin-dsl/blob/master/samples/task-dependencies/build.gradle.kts#L41
Expand Down
21 changes: 5 additions & 16 deletions test_runner/src/main/kotlin/ftl/client/google/AndroidCatalog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ import com.google.testing.model.AndroidDevice
import com.google.testing.model.AndroidDeviceCatalog
import com.google.testing.model.AndroidModel
import com.google.testing.model.Orientation
import flank.common.logLn
import ftl.api.fetchAndroidOsVersion
import ftl.environment.android.getDescription
import ftl.environment.getLocaleDescription
import ftl.http.executeWithRetry
import ftl.presentation.cli.firebase.test.android.versions.toCliTable
import ftl.presentation.cli.firebase.test.reportmanager.ReportManagerState
import ftl.presentation.publish

/**
* Contains lists of possible Android device and version ids, as well as checks
Expand All @@ -34,19 +31,9 @@ object AndroidCatalog {

fun getModels(projectId: String): List<AndroidModel> = deviceCatalog(projectId).models.orEmpty()

fun supportedVersionsAsTable(projectId: String) = fetchAndroidOsVersion(projectId).toCliTable()

fun describeSoftwareVersion(projectId: String, versionId: String) =
fetchAndroidOsVersion(projectId).getDescription(versionId)

private fun getVersionsList(projectId: String) = deviceCatalog(projectId).versions

fun supportedOrientations(projectId: String): List<Orientation> =
deviceCatalog(projectId).runtimeConfiguration.orientations

private fun getLocaleDescription(projectId: String, locale: String) =
getLocales(projectId).getLocaleDescription(locale)

internal fun getLocales(projectId: String) = deviceCatalog(projectId).runtimeConfiguration.locales

fun androidModelIds(projectId: String) =
Expand All @@ -64,7 +51,9 @@ object AndroidCatalog {
val form = deviceCatalog(projectId).models
.find { it.id.equals(modelId, ignoreCase = true) }?.form
?: DeviceType.PHYSICAL.name.also {
logLn("Unable to find device type for $modelId. PHYSICAL used as fallback in cost calculations")
ReportManagerState.Log(
"Unable to find device type for $modelId. PHYSICAL used as fallback in cost calculations"
).publish()
}

return form.equals(DeviceType.VIRTUAL.name, ignoreCase = true) || form.equals(
Expand Down
1 change: 1 addition & 0 deletions test_runner/src/main/kotlin/ftl/client/google/GcStorage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ object GcStorage {
path: String,
name: String
) {
// TODO #2136 handle messages with state
runWithProgress(
startMessage = "Uploading [$name] to ${GCS_STORAGE_LINK + join(bucket, path).replace(name, "")}..",
action = { storage.create(BlobInfo.newBuilder(bucket, path).build(), this) },
Expand Down
25 changes: 19 additions & 6 deletions test_runner/src/main/kotlin/ftl/domain/RefreshLastRun.kt
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
}
7 changes: 4 additions & 3 deletions test_runner/src/main/kotlin/ftl/domain/RunTestAndroid.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import ftl.config.defaultAndroidConfig
import ftl.config.loadAndroidConfig
import ftl.config.plus
import ftl.mock.MockServer
import ftl.presentation.Output
import ftl.presentation.runBlockingWithObservingRunState
import ftl.reports.addStepTime
import ftl.reports.output.configure
import ftl.reports.output.log
Expand All @@ -24,10 +26,9 @@ import ftl.util.TEST_TYPE
import ftl.util.loadFile
import ftl.util.printVersionInfo
import ftl.util.setCrashReportTag
import kotlinx.coroutines.runBlocking
import java.nio.file.Paths

interface RunTestAndroid {
interface RunTestAndroid : Output {
val configPath: String
val config: AndroidConfig
val dryRun: Boolean
Expand Down Expand Up @@ -59,7 +60,7 @@ operator fun RunTestAndroid.invoke() {
)
reportConfiguration()
}.validate().also { args ->
runBlocking {
runBlockingWithObservingRunState {
if (dumpShards)
args.dumpShards()
else {
Expand Down
7 changes: 4 additions & 3 deletions test_runner/src/main/kotlin/ftl/domain/RunTestIos.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import ftl.config.defaultIosConfig
import ftl.config.loadIosConfig
import ftl.config.plus
import ftl.mock.MockServer
import ftl.presentation.Output
import ftl.presentation.runBlockingWithObservingRunState
import ftl.reports.addStepTime
import ftl.reports.output.configure
import ftl.reports.output.log
Expand All @@ -24,10 +26,9 @@ import ftl.util.TEST_TYPE
import ftl.util.loadFile
import ftl.util.printVersionInfo
import ftl.util.setCrashReportTag
import kotlinx.coroutines.runBlocking
import java.nio.file.Paths

interface RunIosTest {
interface RunIosTest : Output {
val configPath: String
val config: IosConfig
val dryRun: Boolean
Expand Down Expand Up @@ -63,7 +64,7 @@ operator fun RunIosTest.invoke() {
if (dumpShards.not()) logLn(this)
}.validate().run {
if (dumpShards) dumpShards()
else runBlocking {
else runBlockingWithObservingRunState {
addStepTime("Preparation", prepareStopWatch.check())
newTestRun()
}
Expand Down
28 changes: 28 additions & 0 deletions test_runner/src/main/kotlin/ftl/presentation/RunState.kt
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)
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package ftl.presentation.cli

import ftl.presentation.cli.firebase.CancelCommand
import ftl.presentation.cli.firebase.RefreshCommand
import ftl.presentation.cli.firebase.TestCommand
import ftl.presentation.cli.firebase.test.refresh.RefreshCommand
import ftl.util.PrintHelpCommand
import picocli.CommandLine.Command

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package ftl.presentation.cli

import ftl.log.setDebugLogging
import ftl.presentation.cli.firebase.CancelCommand
import ftl.presentation.cli.firebase.RefreshCommand
import ftl.presentation.cli.firebase.test.AndroidCommand
import ftl.presentation.cli.firebase.test.IPBlocksCommand
import ftl.presentation.cli.firebase.test.IosCommand
import ftl.presentation.cli.firebase.test.NetworkProfilesCommand
import ftl.presentation.cli.firebase.test.ProvidedSoftwareCommand
import ftl.presentation.cli.firebase.test.refresh.RefreshCommand
import ftl.util.PrintHelpCommand
import ftl.util.printVersionInfo
import picocli.CommandLine
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import ftl.config.createConfiguration
import ftl.domain.RunTestAndroid
import ftl.domain.invoke
import ftl.presentation.cli.firebase.test.CommonRunCommand
import ftl.presentation.cli.firebase.test.reportmanager.ReportManagerState
import ftl.presentation.cli.firebase.test.reportmanager.handleReportManagerState
import ftl.presentation.outputLogger
import ftl.presentation.throwUnknownType
import ftl.run.ANDROID_SHARD_FILE
import picocli.CommandLine
import picocli.CommandLine.Command
Expand Down Expand Up @@ -52,4 +56,12 @@ class AndroidRunCommand :
}

override fun run() = invoke()

override val out = outputLogger {
// TODO add more types in #1870
when (this) {
is ReportManagerState -> handleReportManagerState(this)
else -> throwUnknownType()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import ftl.config.ios.IosGcloudConfig
import ftl.domain.RunIosTest
import ftl.domain.invoke
import ftl.presentation.cli.firebase.test.CommonRunCommand
import ftl.presentation.cli.firebase.test.reportmanager.ReportManagerState
import ftl.presentation.cli.firebase.test.reportmanager.handleReportManagerState
import ftl.presentation.outputLogger
import ftl.presentation.throwUnknownType
import ftl.run.IOS_SHARD_FILE
import picocli.CommandLine
import picocli.CommandLine.Command
Expand Down Expand Up @@ -52,4 +56,12 @@ class IosRunCommand :
}

override fun run() = invoke()

override val out = outputLogger {
// TODO add more types in #1871
when (this) {
is ReportManagerState -> handleReportManagerState(this)
else -> throwUnknownType()
}
}
}
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"
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package ftl.presentation.cli.firebase
package ftl.presentation.cli.firebase.test.refresh

import ftl.domain.RefreshLastRun
import ftl.domain.RefreshLastRunState
import ftl.domain.invoke
import ftl.presentation.cli.firebase.test.reportmanager.ReportManagerState
import ftl.presentation.cli.firebase.test.reportmanager.handleReportManagerState
import ftl.presentation.outputLogger
import ftl.presentation.throwUnknownType
import ftl.util.PrintHelpCommand
import kotlinx.coroutines.runBlocking
import picocli.CommandLine.Command

@Command(
Expand All @@ -26,5 +30,14 @@ class RefreshCommand :
PrintHelpCommand(),
RefreshLastRun {

override fun run() = runBlocking { invoke() }
override fun run() = invoke()

override val out = outputLogger {
when (this) {
is RefreshLastRunState -> handleRefreshLastRunState(this)
is ReportManagerState -> handleReportManagerState(this)
// TODO #2136 handle uploading file here
else -> throwUnknownType()
}
}
}
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()
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import ftl.config.FtlConstants.indent
import ftl.json.MatrixMap
import ftl.json.asPrintableTable
import ftl.json.isFailed
import ftl.presentation.cli.firebase.test.reportmanager.ReportManagerState
import ftl.presentation.publish
import ftl.reports.output.log
import ftl.reports.output.outputReport
import ftl.reports.util.IReport
Expand All @@ -36,7 +38,7 @@ object MatrixResultsReport : IReport {

override fun run(matrices: MatrixMap, result: JUnitTest.Result?, printToStdout: Boolean, args: IArgs) {
val output = generate(matrices)
if (printToStdout) log(output)
if (printToStdout) ReportManagerState.Log(output).publish()
write(matrices, output, args)
ReportManager.uploadReportResult(output, args, fileName())
}
Expand Down
Loading