-
Notifications
You must be signed in to change notification settings - Fork 51
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
Cannot use this plugin in tandem with Kotlin Multiplatform Tests #116
Comments
Mirror issue on Kotlin side: https://youtrack.jetbrains.com/issue/KT-49155 |
Found a workaround: tasks.withType<KotlinJvmTest>().configureEach {
applyTestRetryCompatibilityWorkaround()
}
/**
* Test retry plugin is incompatible with test tasks that override the `createTestExecuter` method.
* This includes the [KotlinJvmTest] task which wraps the test executor with its own wrapper.
*
* This workaround heavily relies on the internal implementation details of the test-retry plugin and KGP.
*
* The test retry plugin adds a `doFirst` action, which:
* - Retrieves the test executer using `createTestExecuter` (KGP returns wrapped test executer here)
* - Wraps it with `RetryTestExecuter`
* - Sets the executer using `setTestExecuter`
*
* In the `doLast` action, it expects that `createTestExecuter` returns the previously created `RetryTestExecuter` instance.
* However, KGP wraps every result of `createTestExecutor` with its own wrapper, resulting in the following nesting:
* KotlinJvmTarget$Executer(RetryTestExecuter(KotlinJvmTarget$Executer(DefaultTestExecuter)))
*
* KGP wraps the executer only if `targetName` is present, as it is needed to add the target name suffix to the test name.
* The workaround sets `targetName` to `null` after the first KGP wrapper is created,
* so `createTestExecuter` returns the previously created executer:
* RetryTestExecuter(KotlinJvmTarget$Executer(DefaultTestExecuter))
*
* Issue: https://github.com/gradle/test-retry-gradle-plugin/issues/116 (KT-49155)
*/
private fun KotlinJvmTest.applyTestRetryCompatibilityWorkaround() {
if (targetName == null) return
val executeTestsActionIndex = taskActions.indexOfLast { it.displayName == "Execute executeTests" }
check(executeTestsActionIndex != -1) { "Action executeTests not found" }
// Add the workaround action and then move it to the correct position right before tests execution.
doFirst("workaround for compatibility with testRetry") {
targetName = null
}
val injectedAction = taskActions.removeFirst()
taskActions.add(executeTestsActionIndex, injectedAction)
} I hope it doesn't break any stuff related to task inputs as |
In my opinion, the problem is in protected TestExecuter<JvmTestExecutionSpec> createTestExecuter() {
if (testExecuter == null) {
return new DefaultTestExecuter(...);
} else {
return testExecuter;
}
} What could be done on a KGP side (or any other plugin's overriding an executer) is to check if the override fun createTestExecuter(): TestExecuter<JvmTestExecutionSpec> {
val executer = super.createTestExecuter()
return if (executer is DefaultTestExecuter) {
// Wrap the executer or create a new one
} else {
// Executer was set by test-retry plugin, return it "as is"
executer
}
} Though it would be even better to resolve this problem in Gradle. Probably by introducing a new method protected final TestExecuter<JvmTestExecutionSpec> getTestExecuter() {
if (testExecuter == null) {
return createTestExecuter();
} else {
return testExecuter;
}
}
protected TestExecuter<JvmTestExecutionSpec> createTestExecuter() {
return new DefaultTestExecuter(...);
} Third-party plugins will be able to override |
Bug reproducer project
The text was updated successfully, but these errors were encountered: