diff --git a/spock-core/src/main/java/org/spockframework/runtime/extension/builtin/RepeatUntilFailureExtension.java b/spock-core/src/main/java/org/spockframework/runtime/extension/builtin/RepeatUntilFailureExtension.java index 52af45d0fc..27e6171e72 100644 --- a/spock-core/src/main/java/org/spockframework/runtime/extension/builtin/RepeatUntilFailureExtension.java +++ b/spock-core/src/main/java/org/spockframework/runtime/extension/builtin/RepeatUntilFailureExtension.java @@ -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.*; @@ -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 { @Override public void visitFeatureAnnotation(RepeatUntilFailure annotation, FeatureInfo feature) { @@ -32,8 +35,8 @@ public RepeatUntilFailureDataDriver(int maxAttempts) { @Override public void runIterations(IDataIterator dataIterator, IIterationRunner iterationRunner, List parameters) { int estimatedNumIterations = dataIterator.getEstimatedNumIterations(); - int maxIterations = estimatedNumIterations * maxAttempts; - List arguments = new ArrayList<>(estimatedNumIterations); + int maxIterations = estimatedNumIterations == UNKNOWN_ITERATIONS ? UNKNOWN_ITERATIONS : (estimatedNumIterations * maxAttempts); + List arguments = estimatedNumIterations == UNKNOWN_ITERATIONS ? new ArrayList<>() : new ArrayList<>(estimatedNumIterations); dataIterator.forEachRemaining(arguments::add); for (int attempt = 0; attempt < maxAttempts; attempt++) { for (Object[] args : arguments) { diff --git a/spock-specs/src/test/groovy/org/spockframework/smoke/extension/RepeatUntilFailureExtensionSpec.groovy b/spock-specs/src/test/groovy/org/spockframework/smoke/extension/RepeatUntilFailureExtensionSpec.groovy index 9b4fa7c045..ff1508aaa1 100644 --- a/spock-specs/src/test/groovy/org/spockframework/smoke/extension/RepeatUntilFailureExtensionSpec.groovy +++ b/spock-specs/src/test/groovy/org/spockframework/smoke/extension/RepeatUntilFailureExtensionSpec.groovy @@ -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: