Skip to content

Commit

Permalink
fix(android_parsing): remote parse without overridden testrun listene…
Browse files Browse the repository at this point in the history
…r if a user forgot to add the correspondent dependency in the project
  • Loading branch information
matzuk committed Dec 11, 2023
1 parent cad1958 commit 1e07aba
Showing 1 changed file with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -42,15 +44,22 @@ class AmInstrumentTestParser(

override suspend fun extract(device: Device): List<Test> {
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
}
}
}
Expand All @@ -59,7 +68,8 @@ class AmInstrumentTestParser(
device: AdamAndroidDevice,
configuration: Configuration,
vendorConfiguration: VendorConfiguration.AndroidConfiguration,
testBundles: List<AndroidTestBundle>
testBundles: List<AndroidTestBundle>,
blockListenerArgumentOverride: Boolean,
): List<Test> {
return testBundles.flatMap { bundle ->
val androidTestBundle =
Expand All @@ -68,7 +78,10 @@ class AmInstrumentTestParser(

val testParserConfiguration = vendorConfiguration.testParserConfiguration
val overrides: Map<String, String> = when {
testParserConfiguration is TestParserConfiguration.RemoteTestParserConfiguration -> testParserConfiguration.instrumentationArgs
testParserConfiguration is TestParserConfiguration.RemoteTestParserConfiguration -> {
if (blockListenerArgumentOverride) testParserConfiguration.instrumentationArgs.filterKeys { it != LISTENER_ARGUMENT }
else testParserConfiguration.instrumentationArgs
}
else -> emptyMap()
}

Expand Down Expand Up @@ -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()

0 comments on commit 1e07aba

Please sign in to comment.