Skip to content

Commit 2b269aa

Browse files
Merge pull request #12 from strido/retry-super-setup-cleanup
Call all setup/cleanup methods in super specs when retrying
2 parents 642ca0b + 6efe48f commit 2b269aa

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

Diff for: src/main/groovy/com/anotherchrisberry/spock/extensions/retry/RetryInterceptor.groovy

+18-14
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,28 @@ class RetryInterceptor implements IMethodInterceptor {
3131
if (attempts > retryMax) {
3232
throw t
3333
}
34-
invocation.spec.cleanupMethods.each {
35-
try {
36-
if (it.reflection) {
37-
ReflectionUtil.invokeMethod(invocation.target, it.reflection)
34+
invocation.spec.specsBottomToTop.each { spec ->
35+
spec.cleanupMethods.each {
36+
try {
37+
if (it.reflection) {
38+
ReflectionUtil.invokeMethod(invocation.target, it.reflection)
39+
}
40+
} catch (Throwable t2) {
41+
LOG.warn("Retry caught failure ${attempts + 1} / ${retryMax + 1} while cleaning up", t2)
3842
}
39-
} catch (Throwable t2) {
40-
LOG.warn("Retry caught failure ${attempts + 1} / ${retryMax + 1} while cleaning up", t2)
4143
}
4244
}
43-
invocation.spec.setupMethods.each {
44-
try {
45-
if (it.reflection) {
46-
ReflectionUtil.invokeMethod(invocation.target, it.reflection)
45+
invocation.spec.specsTopToBottom.each { spec ->
46+
spec.setupMethods.each {
47+
try {
48+
if (it.reflection) {
49+
ReflectionUtil.invokeMethod(invocation.target, it.reflection)
50+
}
51+
} catch (Throwable t2) {
52+
// increment counter, since this is the start of the re-run
53+
attempts++
54+
LOG.info("Retry caught failure ${attempts + 1} / ${retryMax + 1} while setting up", t2)
4755
}
48-
} catch (Throwable t2) {
49-
// increment counter, since this is the start of the re-run
50-
attempts++
51-
LOG.info("Retry caught failure ${attempts + 1} / ${retryMax + 1} while setting up", t2)
5256
}
5357
}
5458

0 commit comments

Comments
 (0)