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

fix(android_parsing): remote parse without overridden testrun listene… #876

Closed
Closed
Changes from 3 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
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 }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is going to filter all listener arguments, not just the one for parsing. It's possible to use lots of listeners at the same and just one of them would be the test parser annotation producer

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a check for the value (annotation producer)

else testParserConfiguration.instrumentationArgs
}
else -> emptyMap()
}

Expand Down Expand Up @@ -112,7 +125,9 @@ class AmInstrumentTestParser(
testBundleIdentifier.put(test, androidTestBundle)
}

is TestRunFailed -> Unit
is TestRunFailed -> {
if (overrides.containsKey(LISTENER_ARGUMENT)) throw PossibleListenerIssueException()
}
is TestRunStopped -> Unit
is TestRunEnded -> Unit
}
Expand All @@ -131,3 +146,5 @@ class AmInstrumentTestParser(
}
}
}

private class PossibleListenerIssueException : RuntimeException()
Loading