Skip to content

Commit

Permalink
Remove Retry.Mode.FEATURE (Breaking Change)
Browse files Browse the repository at this point in the history
it is not possible to keep the old behavior, since we always
unroll the executions, and it is not possible to hide the
iteration results from the reporting.
  • Loading branch information
leonard84 committed Oct 31, 2019
1 parent 5a35ab1 commit 24e7b92
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
package org.spockframework.runtime.extension.builtin;

import org.spockframework.runtime.extension.AbstractAnnotationDrivenExtension;
import org.spockframework.runtime.model.FeatureInfo;
import org.spockframework.runtime.model.NodeInfo;
import org.spockframework.runtime.model.SpecInfo;
import org.spockframework.runtime.model.*;
import spock.lang.Retry;

/**
Expand Down Expand Up @@ -51,9 +49,7 @@ private boolean noRetryAnnotation(NodeInfo node) {

@Override
public void visitFeatureAnnotation(Retry annotation, FeatureInfo feature) {
if (feature.isParameterized() && (annotation.mode() == Retry.Mode.FEATURE)) {
feature.addInterceptor(new RetryIterationInterceptor(annotation));
} else if (annotation.mode() == Retry.Mode.SETUP_FEATURE_CLEANUP) {
if (annotation.mode() == Retry.Mode.SETUP_FEATURE_CLEANUP) {
feature.addIterationInterceptor(new RetryIterationInterceptor(annotation));
} else {
feature.getFeatureMethod().addInterceptor(new RetryFeatureInterceptor(annotation));
Expand Down
8 changes: 2 additions & 6 deletions spock-core/src/main/java/spock/lang/Retry.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@

package spock.lang;

import groovy.lang.Closure;
import org.spockframework.runtime.extension.ExtensionAnnotation;
import org.spockframework.runtime.extension.builtin.RetryExtension;
import org.spockframework.util.Beta;

import java.lang.annotation.*;

import groovy.lang.Closure;


/**
* Retries the given feature if an exception occurs during execution.
Expand Down Expand Up @@ -92,11 +93,6 @@
Mode mode() default Mode.ITERATION;

enum Mode {
/**
* Retry the whole feature, if any iteration fails.
*/
FEATURE,

/**
* Retry the iterations individually.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ class Foo extends Specification {

where:
mode || expectedCount
Retry.Mode.FEATURE.name() || 1
Retry.Mode.ITERATION.name() || 1
Retry.Mode.SETUP_FEATURE_CLEANUP.name() || 4
}
Expand Down Expand Up @@ -189,30 +188,6 @@ class Foo extends Specification {
thrown(IllegalArgumentException)
}

def "@Retry rethrows non handled exceptions for data driven features with FEATURE mode"() {
given:
runner.throwFailure = true

when:
def result = runner.runWithImports("""
import spock.lang.Retry
class Foo extends Specification {
@Retry(exceptions=[IndexOutOfBoundsException], mode = Retry.Mode.FEATURE)
def bar() {
expect:
throw new IllegalArgumentException()
where:
ignore << [1, 2]
}
}
""")

then:
thrown(IllegalArgumentException)
}

def "@Retry works for data driven features"() {
when:
def result = runner.runWithImports("""
Expand Down Expand Up @@ -262,60 +237,6 @@ class Foo extends Specification {
featureCounter.get() == 4 + 2
}

def "@Retry mode FEATURE retries complete feature when an iteration fails"() {
when:
def result = runner.runWithImports("""
import spock.lang.Retry
class Foo extends Specification {
@Unroll
@Retry(mode=Retry.Mode.FEATURE)
def bar() {
org.spockframework.smoke.extension.RetryFeatureExtensionSpec.featureCounter.incrementAndGet()
expect: test
where:
test << [true, true, false]
}
}
""")

then:
// TODO revisit
result.testsSucceededCount == 2 * 3 * 4
result.testsFailedCount == 1
result.testsSkippedCount == 0

featureCounter.get() == 4 * 3
}

def "@Retry mode FEATURE stops retries after all iterations have passed once"() {
when:
def result = runner.runWithImports("""
import spock.lang.Retry
class Foo extends Specification {
static int[] counters = new int[3]
@Unroll
@Retry(mode=Retry.Mode.FEATURE)
def bar() {
counters[index]++
expect:
index < 2 || counters[index] > 1
where:
index << [0, 1, 2]
}
}
""")

then:
result.testsSucceededCount == 2 * 3
result.testsFailedCount == 0
result.testsSkippedCount == 0
}

def "@Retry doesn't affect data driven feature where all iterations pass"() {
when:
def result = runner.runWithImports("""
Expand All @@ -333,29 +254,7 @@ class Foo extends Specification {
""")

then:
result.testsSucceededCount == 1
result.testsFailedCount == 0
result.testsSkippedCount == 0
}

def "@Retry doesn't affect data driven feature where all iterations pass in mode FEATURE"() {
when:
def result = runner.runWithImports("""
import spock.lang.Retry
class Foo extends Specification {
@Retry(mode = Retry.Mode.FEATURE)
def bar() {
expect: test
where:
test << [true, true, true]
}
}
""")

then:
result.testsSucceededCount == 1
result.testsSucceededCount == 3
result.testsFailedCount == 0
result.testsSkippedCount == 0
}
Expand Down Expand Up @@ -403,32 +302,6 @@ class Foo extends Specification {
result.testsSkippedCount == 0
}

def "@Retry can add delay between executions"() {
when:
long start = System.currentTimeMillis()
def result = runner.runWithImports("""
import spock.lang.Retry
class Foo extends Specification {
@Retry(delay = 100, mode = Retry.Mode.FEATURE)
def bar() {
expect: test
where:
test << [false, false, false, false, false, false, false, false, true]
}
}
""")

then:
def duration = System.currentTimeMillis() - start
duration > 300
duration < 1000
result.testsSucceededCount == 1
result.testsFailedCount == 32
result.testsSkippedCount == 0
}

def "@Retry can add delay between iteration executions"() {
when:
long start = System.currentTimeMillis()
Expand Down

0 comments on commit 24e7b92

Please sign in to comment.