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

Add onRetry for setting JVM options for fork differently #349

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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 @@ -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.
Expand Down Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -41,4 +45,5 @@ public interface TestRetryTaskExtensionAccessor {

boolean getSimulateNotRetryableTest();

Action<? super JavaForkOptions> getOnRetry();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down