Skip to content

Commit

Permalink
Cleanup Configuration model (#66)
Browse files Browse the repository at this point in the history
* Remove paths to APKs from Configuration model
* Remove name from Configuration model
* Remove baseOutputDir
  • Loading branch information
technoir42 authored Jul 22, 2024
1 parent 4b0f5af commit 7f70e0e
Show file tree
Hide file tree
Showing 24 changed files with 33 additions and 171 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.malinskiy.marathon.execution.TestStatus
import com.malinskiy.marathon.test.StubDevice
import com.malinskiy.marathon.test.Test
import com.malinskiy.marathon.test.TestComponentInfo
import com.malinskiy.marathon.test.runAsync
import com.malinskiy.marathon.test.setupMarathon
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
Expand Down
32 changes: 0 additions & 32 deletions core/src/main/kotlin/com/malinskiy/marathon/Marathon.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ import com.malinskiy.marathon.cache.test.TestCacheLoader
import com.malinskiy.marathon.cache.test.TestCacheSaver
import com.malinskiy.marathon.config.LogicalConfigurationValidator
import com.malinskiy.marathon.device.DeviceProvider
import com.malinskiy.marathon.exceptions.NoDevicesException
import com.malinskiy.marathon.exceptions.ReportGenerationException
import com.malinskiy.marathon.execution.ComponentInfo
import com.malinskiy.marathon.execution.ComponentInfoExtractor
import com.malinskiy.marathon.execution.Configuration
import com.malinskiy.marathon.execution.Scheduler
import com.malinskiy.marathon.execution.StrictRunChecker
Expand All @@ -35,7 +33,6 @@ private val log = MarathonLogging.logger {}

class Marathon(
val configuration: Configuration,
private val componentInfoExtractor: ComponentInfoExtractor,
private val deviceProvider: DeviceProvider,
private val tracker: TrackerInternal,
private val analytics: Analytics,
Expand Down Expand Up @@ -66,35 +63,6 @@ class Marathon(
logConfigurator.configure(vendorConfiguration)
}

fun run() = runBlocking {
try {
val isSuccess = runAsync()
when {
configuration.ignoreFailures -> true
else -> isSuccess
}
} catch (th: Throwable) {
log.error(th.toString())

when (th) {
is NoDevicesException -> {
log.warn { "No devices found" }
false
}
else -> false
}
}
}

suspend fun runAsync(): Boolean {
start()

val componentInfo = componentInfoExtractor.extract(configuration)
scheduleTests(componentInfo)

return stopAndWaitForCompletion()
}

override suspend fun start() {
configureLogging(configuration.vendorConfiguration)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ internal class TrackerFactory(
RawJsonReporter(fileManager, gson),
TestJsonReporter(fileManager, gson),
AllureReporter(configuration, File(configuration.outputDir, "allure-results"), testResultDescriptionFactory),
HtmlSummaryReporter(gson, configuration.outputDir, configuration, testResultDescriptionFactory),
HtmlSummaryReporter(gson, configuration.outputDir, testResultDescriptionFactory),
StdoutReporter(timer),
configuration.listener?.let { ListenerReporter(it) }
),
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/kotlin/com/malinskiy/marathon/di/Modules.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ fun coreModule(timer: Timer?) = module {
single<Timer> { timer ?: SystemTimer(get()) }
single<ProgressReporter> { ProgressReporter(get()) }
single<StrictRunChecker> { ConfigurationStrictRunChecker(get()) }
single<Marathon> { Marathon(get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get()) }
single<Marathon> { Marathon(get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get()) }
}

fun KoinApplication.marathonConfiguration(configuration: Configuration): KoinApplication {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ private const val DEFAULT_NO_DEVICES_TIMEOUT_MILLIS: Long = 300_000
private const val DEFAULT_OUTPUT_TIMEOUT_MILLIS: Long = 60_000

data class Configuration constructor(
val name: String,
val outputDir: File,

val customAnalyticsTracker: Tracker?,
Expand Down Expand Up @@ -57,7 +56,6 @@ data class Configuration constructor(
) {

constructor(
name: String,
outputDir: File,

customAnalyticsTracker: Tracker?,
Expand Down Expand Up @@ -93,7 +91,6 @@ data class Configuration constructor(
) :

this(
name = name,
outputDir = outputDir,
customAnalyticsTracker = customAnalyticsTracker,
poolingStrategy = poolingStrategy ?: OmniPoolingStrategy(),
Expand Down Expand Up @@ -125,7 +122,6 @@ data class Configuration constructor(

fun toMap() =
mapOf<String, String>(
"name" to name,
"outputDir" to outputDir.absolutePath,
"pooling" to poolingStrategy.toString(),
"sharding" to shardingStrategy.toString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import com.malinskiy.marathon.device.DeviceFeature
import com.malinskiy.marathon.device.DeviceInfo
import com.malinskiy.marathon.execution.Attachment
import com.malinskiy.marathon.execution.AttachmentType
import com.malinskiy.marathon.execution.Configuration
import com.malinskiy.marathon.execution.TestResult
import com.malinskiy.marathon.execution.TestStatus
import com.malinskiy.marathon.extension.relativePathTo
Expand All @@ -34,7 +33,6 @@ import kotlin.math.roundToLong
class HtmlSummaryReporter(
private val gson: Gson,
private val rootOutput: File,
private val configuration: Configuration,
private val testSummaryFormatter: TestSummaryFormatter
) : Reporter {

Expand Down Expand Up @@ -233,7 +231,6 @@ class HtmlSummaryReporter(


private fun Summary.toHtmlIndex() = HtmlIndex(
title = configuration.name,
totalFailed = pools.sumOf { it.failed.size },
totalIgnored = pools.sumOf { it.ignored.size },
totalPassed = pools.sumOf { it.passed.size },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.malinskiy.marathon.test.StubDevice
import com.malinskiy.marathon.test.Test
import com.malinskiy.marathon.test.TestComponentInfo
import com.malinskiy.marathon.test.assert.shouldBeEqualToAsJson
import com.malinskiy.marathon.test.runAsync
import com.malinskiy.marathon.test.setupMarathon
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.delay
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.malinskiy.marathon.test.StubDevice
import com.malinskiy.marathon.test.Test
import com.malinskiy.marathon.test.TestComponentInfo
import com.malinskiy.marathon.test.assert.shouldBeEqualToAsJson
import com.malinskiy.marathon.test.runAsync
import com.malinskiy.marathon.test.setupMarathon
import com.malinskiy.marathon.time.Timer
import kotlinx.coroutines.ExperimentalCoroutinesApi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.malinskiy.marathon.execution.strategy.impl.sharding.CountShardingStra
import com.malinskiy.marathon.test.StubDevice
import com.malinskiy.marathon.test.Test
import com.malinskiy.marathon.test.TestComponentInfo
import com.malinskiy.marathon.test.runAsync
import com.malinskiy.marathon.test.setupMarathon
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.delay
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.malinskiy.marathon.test.StubDevice
import com.malinskiy.marathon.test.Test
import com.malinskiy.marathon.test.TestComponentInfo
import com.malinskiy.marathon.test.assert.shouldBeEqualToAsJson
import com.malinskiy.marathon.test.runAsync
import com.malinskiy.marathon.test.setupMarathon
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.delay
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.malinskiy.marathon.test.StubDevice
import com.malinskiy.marathon.test.Test
import com.malinskiy.marathon.test.TestComponentInfo
import com.malinskiy.marathon.test.assert.shouldBeEqualToAsJson
import com.malinskiy.marathon.test.runAsync
import com.malinskiy.marathon.test.setupMarathon
import com.malinskiy.marathon.time.Timer
import kotlinx.coroutines.ExperimentalCoroutinesApi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,10 @@ import java.io.File

internal fun createCommonConfiguration(
project: Project,
marathonConfig: MarathonExtension,
sdkDirectory: File
): Configuration {
val output = getOutputDirectory(project, marathonConfig)
val fakeApk = File(".")
val fakeName = "marathon-common"

return createConfiguration(
extensionConfig = marathonConfig,
applicationApk = null,
instrumentationApk = fakeApk,
sdkDirectory = sdkDirectory,
name = fakeName,
output = output
)
}

private fun createConfiguration(
extensionConfig: MarathonExtension,
applicationApk: File?,
instrumentationApk: File,
sdkDirectory: File,
name: String,
output: File
sdkDirectory: File
): Configuration = Configuration(
name = name,
outputDir = output,
outputDir = project.layout.buildDirectory.dir("reports/marathon").get().asFile,
customAnalyticsTracker = extensionConfig.customAnalyticsTracker,
poolingStrategy = extensionConfig.poolingStrategy?.toStrategy(),
shardingStrategy = extensionConfig.shardingStrategy?.toStrategy(),
Expand All @@ -66,19 +43,10 @@ private fun createConfiguration(
testOutputTimeoutMillis = extensionConfig.testOutputTimeoutMillis,
noDevicesTimeoutMillis = extensionConfig.noDevicesTimeoutMillis,
debug = extensionConfig.debug,
vendorConfiguration = createAndroidConfiguration(extensionConfig, applicationApk, instrumentationApk, sdkDirectory)
vendorConfiguration = createAndroidConfiguration(extension = extensionConfig, sdkDirectory = sdkDirectory)
)

private fun getOutputDirectory(project: Project, extensionConfig: MarathonExtension): File =
extensionConfig.baseOutputDir?.let { File(it) }
?: project.layout.buildDirectory.dir("reports/marathon").get().asFile

private fun createAndroidConfiguration(
extension: MarathonExtension,
applicationApk: File?,
instrumentationApk: File,
sdkDirectory: File
): AndroidConfiguration {
private fun createAndroidConfiguration(extension: MarathonExtension, sdkDirectory: File): AndroidConfiguration {
val autoGrantPermission = extension.autoGrantPermission ?: DEFAULT_AUTO_GRANT_PERMISSION
val instrumentationArgs = extension.instrumentationArgs
val applicationPmClear = extension.applicationPmClear ?: DEFAULT_APPLICATION_PM_CLEAR
Expand All @@ -101,8 +69,6 @@ private fun createAndroidConfiguration(

return AndroidConfiguration(
sdkDirectory,
applicationApk,
instrumentationApk,
listOf(ddmlibModule),
autoGrantPermission,
instrumentationArgs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ open class MarathonExtension {
var strictRunFilterConfiguration: StrictRunFilterPluginConfiguration? = null
var listener: MarathonListener? = null

var baseOutputDir: String? = null

var cache: CachePluginConfiguration? = null
var ignoreFailures: Boolean? = null
var isCodeCoverageEnabled: Boolean? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.malinskiy.marathon.report
import com.google.gson.annotations.SerializedName

data class HtmlIndex(
@SerializedName("title") val title: String,
@SerializedName("total_failed") val totalFailed: Int,
@SerializedName("total_flaky") val totalFlaky: Int,
@SerializedName("total_ignored") val totalIgnored: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ const val DEFAULT_USED_STORAGE_THRESHOLD_PERCENTS = 85

data class AndroidConfiguration(
val androidSdk: File,
val applicationOutput: File?,
val testApplicationOutput: File,
val implementationModules: List<Module>,
val autoGrantPermission: Boolean = DEFAULT_AUTO_GRANT_PERMISSION,
val instrumentationArgs: Map<String, String> = emptyMap(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
package com.malinskiy.marathon.android.di

import com.malinskiy.marathon.android.AndroidComponentCacheKeyProvider
import com.malinskiy.marathon.android.AndroidComponentInfoExtractor
import com.malinskiy.marathon.android.AndroidLogConfigurator
import com.malinskiy.marathon.android.AndroidTestParser
import com.malinskiy.marathon.android.executor.logcat.LogcatCollector
import com.malinskiy.marathon.android.executor.logcat.LogcatListener
import com.malinskiy.marathon.android.executor.logcat.parse.LogcatEventsAdapter
import com.malinskiy.marathon.android.executor.logcat.parse.LogcatEventsListener
import com.malinskiy.marathon.cache.test.key.ComponentCacheKeyProvider
import com.malinskiy.marathon.execution.ComponentInfoExtractor
import com.malinskiy.marathon.execution.TestParser
import com.malinskiy.marathon.log.MarathonLogConfigurator
import com.malinskiy.marathon.report.logs.LogsProvider
import org.koin.dsl.module

val androidModule = module {
single<TestParser?> { AndroidTestParser() }
single<ComponentInfoExtractor?> { AndroidComponentInfoExtractor() }
single<ComponentCacheKeyProvider?> { AndroidComponentCacheKeyProvider(get()) }
single<LogcatCollector?> { LogcatCollector() }
single<LogcatEventsListener?> { get<LogcatCollector>() }
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.malinskiy.marathon.android

import com.malinskiy.marathon.execution.Configuration
import com.malinskiy.marathon.test.MetaProperty
import com.malinskiy.marathon.test.Test
import kotlinx.coroutines.runBlocking
Expand All @@ -17,42 +16,13 @@ class AndroidTestParserSpek : Spek(

group("android test apk") {
val apkFile = File(javaClass.classLoader.getResource("android_test_1.apk").file)
val configuration = Configuration(
val componentInfo = AndroidComponentInfo(
name = "",
outputDir = File(""),
customAnalyticsTracker = null,
poolingStrategy = null,
shardingStrategy = null,
sortingStrategy = null,
batchingStrategy = null,
flakinessStrategy = null,
retryStrategy = null,
filteringConfiguration = null,
strictRunFilterConfiguration = null,
cache = null,
ignoreFailures = null,
isCodeCoverageEnabled = null,
fallbackToScreenshots = null,
strictMode = null,
listener = null,
uncompletedTestRetryQuota = null,
testClassRegexes = null,
includeSerialRegexes = null,
excludeSerialRegexes = null,
ignoreFailureRegexes = null,
failFastFailureRegexes = null,
testBatchTimeoutMillis = null,
testOutputTimeoutMillis = null,
noDevicesTimeoutMillis = null,
debug = null,
vendorConfiguration = AndroidConfiguration(
implementationModules = emptyList(),
androidSdk = File(""),
applicationOutput = File(""),
testApplicationOutput = apkFile
)
applicationId = null,
testApplicationId = "com.example.test",
applicationOutput = null,
testApplicationOutput = apkFile
)
val componentInfo = AndroidComponentInfoExtractor().extract(configuration)

it("should return proper list of test methods") {
val extractedTests = runBlocking { parser.extract(componentInfo) }
Expand All @@ -71,4 +41,3 @@ class AndroidTestParserSpek : Spek(
}
}
})

Loading

0 comments on commit 7f70e0e

Please sign in to comment.