From 1e07abaf01ff5af6e6d4edab68546b9824905fbe Mon Sep 17 00:00:00 2001 From: Evgenii Matsiuk Date: Mon, 11 Dec 2023 17:58:24 +0300 Subject: [PATCH] fix(android_parsing): remote parse without overridden testrun listener if a user forgot to add the correspondent dependency in the project --- .../android/adam/AmInstrumentTestParser.kt | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/vendor/vendor-android/src/main/kotlin/com/malinskiy/marathon/android/adam/AmInstrumentTestParser.kt b/vendor/vendor-android/src/main/kotlin/com/malinskiy/marathon/android/adam/AmInstrumentTestParser.kt index d60ded19a..79f71307f 100644 --- a/vendor/vendor-android/src/main/kotlin/com/malinskiy/marathon/android/adam/AmInstrumentTestParser.kt +++ b/vendor/vendor-android/src/main/kotlin/com/malinskiy/marathon/android/adam/AmInstrumentTestParser.kt @@ -32,6 +32,8 @@ import kotlinx.coroutines.CancellationException import kotlinx.coroutines.NonCancellable.isActive import kotlinx.coroutines.withTimeoutOrNull +private const val LISTENER_ARGUMENT = "listener" + class AmInstrumentTestParser( private val configuration: Configuration, private val testBundleIdentifier: AndroidTestBundleIdentifier, @@ -42,15 +44,22 @@ class AmInstrumentTestParser( override suspend fun extract(device: Device): List { val testBundles = vendorConfiguration.testBundlesCompat() + var blockListenerArgumentOverride = false return withRetry(3, 0) { try { val device = device as? AdamAndroidDevice ?: throw ConfigurationException("Unexpected device type for remote test parsing") - return@withRetry parseTests(device, configuration, vendorConfiguration, testBundles) + return@withRetry parseTests(device, configuration, vendorConfiguration, testBundles, blockListenerArgumentOverride) } catch (e: CancellationException) { throw e - } catch (e: Exception) { - logger.debug(e) { "Remote parsing failed. Retrying" } + } catch (e: PossibleListenerIssueException) { + logger.warn { "The previous parse operation failed. The most possible reason is " + + "a developer missed this step https://docs.marathonlabs.io/android/configure#test-parser. " + + "The next attempt will be done without overridden testrun listener." } + blockListenerArgumentOverride = true throw e + } catch (throwable: Throwable) { + logger.debug(throwable) { "Remote parsing failed. Retrying" } + throw throwable } } } @@ -59,7 +68,8 @@ class AmInstrumentTestParser( device: AdamAndroidDevice, configuration: Configuration, vendorConfiguration: VendorConfiguration.AndroidConfiguration, - testBundles: List + testBundles: List, + blockListenerArgumentOverride: Boolean, ): List { return testBundles.flatMap { bundle -> val androidTestBundle = @@ -68,7 +78,10 @@ class AmInstrumentTestParser( val testParserConfiguration = vendorConfiguration.testParserConfiguration val overrides: Map = when { - testParserConfiguration is TestParserConfiguration.RemoteTestParserConfiguration -> testParserConfiguration.instrumentationArgs + testParserConfiguration is TestParserConfiguration.RemoteTestParserConfiguration -> { + if (blockListenerArgumentOverride) testParserConfiguration.instrumentationArgs.filterKeys { it != LISTENER_ARGUMENT } + else testParserConfiguration.instrumentationArgs + } else -> emptyMap() } @@ -125,9 +138,12 @@ class AmInstrumentTestParser( "Bundle ${bundle.id} did not report any test annotations. If you need test annotations retrieval, remote test parser requires additional setup " + "see https://docs.marathonlabs.io/android/configure#test-parser" } + if (overrides.containsKey(LISTENER_ARGUMENT)) throw PossibleListenerIssueException() } tests } } } + +private class PossibleListenerIssueException : RuntimeException()