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

Fix @RepeatUntilFailure extension with unknown iteration count #2031

Merged
merged 1 commit into from
Nov 5, 2024
Merged
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
1 change: 1 addition & 0 deletions docs/release_notes.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ include::include.adoc[]
* Fix mocking issue with the ByteBuddy MockMaker when using multiple classloaders in Java 21 spockIssue:2017[]
* Fix mocking of final classes via `@SpringBean` and `@SpringSpy` spockIssue:1960[]
* Size of data providers is no longer calculated multiple times but only once
* Fix exception when using `@RepeatUntilFailure` with a data provider with unknown iteration amount. spockPull:2031[]

== 2.4-M4 (2024-03-21)

Expand Down
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);
Vampire marked this conversation as resolved.
Show resolved Hide resolved
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