Skip to content

Commit

Permalink
Add cleanupDeviceScript to extension configuration that will launch…
Browse files Browse the repository at this point in the history
… in case of not enough space on device
  • Loading branch information
Ivan Dyatlov committed Jul 1, 2024
1 parent 99fa03f commit 84230f5
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 34 deletions.
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ object Versions {
val coroutines = "1.7.3"
val ktor = "2.0.3"

val ddmlib = "31.0.2"
val ddmlib = "31.4.2"
val dexTestParser = "2.3.4"
val kotlinLogging = "1.4.9"
val slf4jAPI = "1.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ private fun createAndroidConfiguration(
}
}
?: SerialStrategy.AUTOMATIC
val cleanupDeviceScript = extension.cleanupDeviceScript

return AndroidConfiguration(
sdkDirectory,
Expand All @@ -109,6 +110,7 @@ private fun createAndroidConfiguration(
adbInitTimeout,
installOptions,
preferableRecorderType,
serialStrategy
serialStrategy,
cleanupDeviceScript
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ open class MarathonExtension {
//Android specific for now
var autoGrantPermission: Boolean? = null
var instrumentationArgs: MutableMap<String, String> = mutableMapOf()
var cleanupDeviceScript: String? = null

//Kotlin way
fun cache(block: CachePluginConfiguration.() -> Unit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ data class AndroidConfiguration(
val adbInitTimeoutMillis: Int = defaultInitTimeoutMillis,
val installOptions: String = DEFAULT_INSTALL_OPTIONS,
val preferableRecorderType: DeviceFeature? = null,
val serialStrategy: SerialStrategy = SerialStrategy.AUTOMATIC
val serialStrategy: SerialStrategy = SerialStrategy.AUTOMATIC,
val cleanupDeviceScript: String? = null
) : VendorConfiguration, KoinComponent {

private val koinModules = listOf(androidModule) + implementationModules
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.malinskiy.marathon.android.di
import com.malinskiy.marathon.android.AndroidComponentCacheKeyProvider
import com.malinskiy.marathon.android.AndroidComponentInfoExtractor
import com.malinskiy.marathon.android.AndroidTestParser
import com.malinskiy.marathon.android.ApkFileHasher
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
Expand All @@ -12,13 +11,14 @@ import com.malinskiy.marathon.cache.test.key.ComponentCacheKeyProvider
import com.malinskiy.marathon.execution.ComponentInfoExtractor
import com.malinskiy.marathon.execution.TestParser
import com.malinskiy.marathon.io.CachedFileHasher
import com.malinskiy.marathon.io.Md5FileHasher
import com.malinskiy.marathon.report.logs.LogsProvider
import org.koin.dsl.module

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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ class AndroidAppInstaller(
}
} catch (e: InstallException) {
logger.error(e) { "Error while installing $appPackage, ${appApk.absolutePath} on ${device.serialNumber}" }
if (e.stackTrace.toString().contains("not enough space")) {
logger.error { "Not enough space" }
androidConfiguration.cleanupDeviceScript?.let {
logger.info { "Launch shell script `$it`" }
device.safeExecuteShellCommand(it).let { logger.info { it } }
}
}
throw RuntimeException("Error while installing $appPackage on ${device.serialNumber}", e)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.android.ddmlib.ShellCommandUnresponsiveException
import com.android.ddmlib.TimeoutException
import com.android.ddmlib.testrunner.ITestRunListener
import com.android.ddmlib.testrunner.RemoteAndroidTestRunner
import com.android.ddmlib.testrunner.RemoteAndroidTestRunner.StatusReporterMode
import com.android.ddmlib.testrunner.TestIdentifier
import com.malinskiy.marathon.android.AndroidComponentInfo
import com.malinskiy.marathon.android.AndroidConfiguration
Expand Down Expand Up @@ -104,7 +105,12 @@ class AndroidDeviceTestRunner(private val device: DdmlibAndroidDevice) {
testBatch: TestBatch
): RemoteAndroidTestRunner {

val runner = RemoteAndroidTestRunner(info.instrumentationPackage, info.testRunnerClass, device.ddmsDevice)
val runner = RemoteAndroidTestRunner(
info.instrumentationPackage,
info.testRunnerClass,
device.ddmsDevice,
StatusReporterMode.PROTO_STD
)

val tests = testBatch.tests.map {
val pkg = when {
Expand Down

0 comments on commit 84230f5

Please sign in to comment.