Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add onRetry
Browse files Browse the repository at this point in the history
U1F984 committed Nov 8, 2024
1 parent dfd2d5e commit 73849a9
Showing 5 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -19,6 +19,8 @@
import org.gradle.api.provider.Property;
import org.gradle.api.provider.SetProperty;
import org.gradle.api.tasks.testing.Test;
import org.gradle.process.JavaForkOptions;
import org.jetbrains.annotations.Nullable;

/**
* Allows configuring test retry mechanics.
@@ -91,6 +93,13 @@ public interface TestRetryTaskExtension {
*/
void filter(Action<? super Filter> action);

/**
* Invoked when test are retried.
*/
void onRetry(Action<? super JavaForkOptions> action);

@Nullable Action<? super JavaForkOptions> getOnRetry();

/**
* A filter for specifying which tests may be retried.
* <p>
Original file line number Diff line number Diff line change
@@ -19,7 +19,10 @@
import org.gradle.api.model.ObjectFactory;
import org.gradle.api.provider.Property;
import org.gradle.api.provider.SetProperty;
import org.gradle.api.tasks.testing.Test;
import org.gradle.process.JavaForkOptions;
import org.gradle.testretry.TestRetryTaskExtension;
import org.jetbrains.annotations.Nullable;

import javax.inject.Inject;

@@ -33,6 +36,8 @@ public class DefaultTestRetryTaskExtension implements TestRetryTaskExtension {

private final ClassRetryCriteria classRetryCriteria;

private Action<? super JavaForkOptions> onRetry;

@Inject
public DefaultTestRetryTaskExtension(ObjectFactory objects) {
this.failOnPassedAfterRetry = objects.property(Boolean.class);
@@ -79,6 +84,16 @@ public void classRetry(Action<? super ClassRetryCriteria> action) {
action.execute(classRetryCriteria);
}

@Override
public void onRetry(Action<? super JavaForkOptions> action) {
onRetry = action;
}

@Override
public @Nullable Action<? super JavaForkOptions> getOnRetry() {
return onRetry;
}

private static final class FilterImpl implements Filter {

private final SetProperty<String> includeClasses;
Original file line number Diff line number Diff line change
@@ -15,6 +15,10 @@
*/
package org.gradle.testretry.internal.config;

import org.gradle.api.Action;
import org.gradle.api.tasks.testing.Test;
import org.gradle.process.JavaForkOptions;

import java.util.Set;

public interface TestRetryTaskExtensionAccessor {
@@ -41,4 +45,5 @@ public interface TestRetryTaskExtensionAccessor {

boolean getSimulateNotRetryableTest();

Action<? super JavaForkOptions> getOnRetry();
}
Original file line number Diff line number Diff line change
@@ -15,10 +15,13 @@
*/
package org.gradle.testretry.internal.config;

import org.gradle.api.Action;
import org.gradle.api.provider.Property;
import org.gradle.api.provider.Provider;
import org.gradle.api.provider.ProviderFactory;
import org.gradle.api.provider.SetProperty;
import org.gradle.api.tasks.testing.Test;
import org.gradle.process.JavaForkOptions;
import org.gradle.testretry.TestRetryTaskExtension;
import org.gradle.util.GradleVersion;

@@ -164,6 +167,11 @@ public boolean getSimulateNotRetryableTest() {
return simulateNotRetryableTest;
}

@Override
public Action<? super JavaForkOptions> getOnRetry() {
return extension.getOnRetry();
}

private <T> T read(Property<T> property, T defaultValue) {
return useConventions ? property.get() : property.getOrElse(defaultValue);
}
Original file line number Diff line number Diff line change
@@ -15,13 +15,15 @@
*/
package org.gradle.testretry.internal.executer;

import org.gradle.api.Action;
import org.gradle.api.internal.tasks.testing.JvmTestExecutionSpec;
import org.gradle.api.internal.tasks.testing.TestExecuter;
import org.gradle.api.internal.tasks.testing.TestFramework;
import org.gradle.api.internal.tasks.testing.TestResultProcessor;
import org.gradle.api.model.ObjectFactory;
import org.gradle.api.tasks.testing.Test;
import org.gradle.internal.reflect.Instantiator;
import org.gradle.process.JavaForkOptions;
import org.gradle.testretry.internal.config.TestRetryTaskExtensionAccessor;
import org.gradle.testretry.internal.executer.framework.TestFrameworkStrategy;
import org.gradle.testretry.internal.filter.AnnotationInspectorImpl;
@@ -115,6 +117,12 @@ public void execute(JvmTestExecutionSpec spec, TestResultProcessor testResultPro
JvmTestExecutionSpec testExecutionSpec = spec;

while (true) {
if (retryCount == 1) {
Action<? super JavaForkOptions> onRetry = extension.getOnRetry();
if (onRetry != null) {
onRetry.execute(testExecutionSpec.getJavaForkOptions());
}
}
delegate.execute(testExecutionSpec, retryTestResultProcessor);
RoundResult result = retryTestResultProcessor.getResult();
lastResult = result;

0 comments on commit 73849a9

Please sign in to comment.