-
Notifications
You must be signed in to change notification settings - Fork 471
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
Make @Retry repeatable (#1030) #1197
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,17 +20,19 @@ | |
import org.spockframework.runtime.model.*; | ||
import spock.lang.Retry; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* @author Leonard Brünings | ||
* @since 1.2 | ||
*/ | ||
public class RetryExtension implements IAnnotationDrivenExtension<Retry> { | ||
@Override | ||
public void visitSpecAnnotation(Retry annotation, SpecInfo spec) { | ||
public void visitSpecAnnotations(List<Retry> annotations, SpecInfo spec) { | ||
if (noSubSpecWithRetryAnnotation(spec.getSubSpec())) { | ||
for (FeatureInfo feature : spec.getBottomSpec().getAllFeatures()) { | ||
if (noRetryAnnotation(feature.getFeatureMethod())) { | ||
visitFeatureAnnotation(annotation, feature); | ||
visitFeatureAnnotations(annotations, feature); | ||
} | ||
} | ||
} | ||
|
@@ -44,7 +46,7 @@ private boolean noSubSpecWithRetryAnnotation(SpecInfo spec) { | |
} | ||
|
||
private boolean noRetryAnnotation(NodeInfo node) { | ||
return !node.getReflection().isAnnotationPresent(Retry.class); | ||
return !node.isAnnotationPresent(Retry.class); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about |
||
} | ||
|
||
@Override | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package org.spockframework.docs.extension | ||
|
||
import groovy.sql.Sql | ||
import spock.lang.Retry | ||
import spock.lang.Shared | ||
import spock.lang.Specification | ||
|
||
abstract | ||
// tag::example-common[] | ||
class FlakyIntegrationSpec extends Specification { | ||
// end::example-common[] | ||
@Shared | ||
def sql = Sql.newInstance("jdbc:h2:mem:", "org.h2.Driver") | ||
|
||
// tag::example-d[] | ||
@Retry(exceptions = IllegalArgumentException, count = 2) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add a test, that actually alternately throws both these exceptions? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is unfortunately a good idea, though in the test spec, not the doc spec. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or you might have a look, as you invented the whole extension and probably know the code better than me. |
||
@Retry(exceptions = IllegalAccessException, count = 4) | ||
def retryDependingOnException() { | ||
// end::example-d[] | ||
expect: true | ||
} | ||
} | ||
|
||
class FlakyIntegrationSpecA extends FlakyIntegrationSpec { | ||
// tag::example-a[] | ||
@Retry | ||
def retry3Times() { | ||
expect: true | ||
} | ||
|
||
@Retry(count = 5) | ||
def retry5Times() { | ||
expect: true | ||
} | ||
|
||
@Retry(exceptions = [IOException]) | ||
def onlyRetryIOException() { | ||
expect: true | ||
} | ||
|
||
@Retry(condition = { failure.message.contains('foo') }) | ||
def onlyRetryIfConditionOnFailureHolds() { | ||
expect: true | ||
} | ||
|
||
@Retry(condition = { instance.field != null }) | ||
def onlyRetryIfConditionOnInstanceHolds() { | ||
expect: true | ||
} | ||
|
||
@Retry | ||
def retryFailingIterations() { | ||
expect: true | ||
|
||
where: | ||
data << sql.execute('') | ||
} | ||
|
||
@Retry(mode = Retry.Mode.SETUP_FEATURE_CLEANUP) | ||
def retryWholeFeature() { | ||
expect: true | ||
|
||
where: | ||
data << sql.execute('') | ||
} | ||
|
||
@Retry(delay = 1000) | ||
def retryAfter1000MsDelay() { | ||
expect: true | ||
} | ||
} | ||
// end::example-a[] | ||
|
||
// tag::example-b1[] | ||
@Retry | ||
// end::example-b1[] | ||
class FlakyIntegrationSpecB extends FlakyIntegrationSpec { | ||
// tag::example-b2[] | ||
def "will be retried with config from class"() { | ||
expect: true | ||
} | ||
|
||
@Retry(count = 5) | ||
def "will be retried using its own config"() { | ||
expect: true | ||
} | ||
} | ||
// end::example-b2[] | ||
|
||
// tag::example-c[] | ||
@Retry(count = 1) | ||
abstract class AbstractIntegrationSpec extends Specification { | ||
def inherited() { | ||
expect: true | ||
} | ||
} | ||
|
||
class FooIntegrationSpec extends AbstractIntegrationSpec { | ||
def foo() { | ||
expect: true | ||
} | ||
} | ||
|
||
@Retry(count = 2) | ||
class BarIntegrationSpec extends AbstractIntegrationSpec { | ||
def bar() { | ||
expect: true | ||
} | ||
} | ||
// end::example-c[] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we want code backed docs where ever possible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All pimped