Skip to content

Commit

Permalink
Fix @RepeatUntilFailure extension with unknown iteration count
Browse files Browse the repository at this point in the history
  • Loading branch information
Vampire committed Nov 4, 2024
1 parent b54202a commit a9f299a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.spockframework.runtime.extension.builtin;

import org.spockframework.runtime.DataIteratorFactory;
import org.spockframework.runtime.IDataIterator;
import org.spockframework.runtime.extension.*;
import org.spockframework.runtime.model.*;
Expand All @@ -8,6 +9,8 @@
import java.util.*;
import java.util.concurrent.ExecutionException;

import static org.spockframework.runtime.DataIteratorFactory.UNKNOWN_ITERATIONS;

public class RepeatUntilFailureExtension implements IAnnotationDrivenExtension<RepeatUntilFailure> {
@Override
public void visitFeatureAnnotation(RepeatUntilFailure annotation, FeatureInfo feature) {
Expand All @@ -32,8 +35,8 @@ public RepeatUntilFailureDataDriver(int maxAttempts) {
@Override
public void runIterations(IDataIterator dataIterator, IIterationRunner iterationRunner, List<ParameterInfo> parameters) {
int estimatedNumIterations = dataIterator.getEstimatedNumIterations();
int maxIterations = estimatedNumIterations * maxAttempts;
List<Object[]> arguments = new ArrayList<>(estimatedNumIterations);
int maxIterations = estimatedNumIterations == UNKNOWN_ITERATIONS ? UNKNOWN_ITERATIONS : (estimatedNumIterations * maxAttempts);
List<Object[]> arguments = estimatedNumIterations == UNKNOWN_ITERATIONS ? new ArrayList<>() : new ArrayList<>(estimatedNumIterations);
dataIterator.forEachRemaining(arguments::add);
for (int attempt = 0; attempt < maxAttempts; attempt++) {
for (Object[] args : arguments) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,30 @@ class RepeatUntilFailureExtensionSpec extends EmbeddedSpecification {
result.testsSkippedCount == 2
}

def "repeats with unknown iteration count"() {
given:
runner.throwFailure = false

when:
def result = runner.runSpecBody """
@Shared
int count = 0
@RepeatUntilFailure
def "test"() {
expect:
++count < 3
where:
x << [1].iterator()
}
"""

then:
result.testsStartedCount == 1 + 3
result.testsSucceededCount == 1 + 2
result.testsFailedCount == 1
}

def "ignores aborted tests"() {
when:
Expand Down

0 comments on commit a9f299a

Please sign in to comment.