Skip to content

Commit 9060198

Browse files
author
Erik Strid
committed
Call all setup/cleanup methods in super specs when retrying
1 parent bab7491 commit 9060198

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

src/main/groovy/com/anotherchrisberry/spock/extensions/retry/RetryInterceptor.groovy

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,28 @@ class RetryInterceptor implements IMethodInterceptor {
2929
if (attempts > retryMax) {
3030
throw t
3131
}
32-
invocation.spec.cleanupMethods.each {
33-
try {
34-
if (it.reflection) {
35-
ReflectionUtil.invokeMethod(invocation.target, it.reflection)
32+
invocation.spec.specsBottomToTop.each { spec ->
33+
spec.cleanupMethods.each {
34+
try {
35+
if (it.reflection) {
36+
ReflectionUtil.invokeMethod(invocation.target, it.reflection)
37+
}
38+
} catch (Throwable t2) {
39+
LOG.warn("Retry caught failure ${attempts + 1} / ${retryMax + 1} while cleaning up", t2)
3640
}
37-
} catch (Throwable t2) {
38-
LOG.warn("Retry caught failure ${attempts + 1} / ${retryMax + 1} while cleaning up", t2)
3941
}
4042
}
41-
invocation.spec.setupMethods.each {
42-
try {
43-
if (it.reflection) {
44-
ReflectionUtil.invokeMethod(invocation.target, it.reflection)
43+
invocation.spec.specsTopToBottom.each { spec ->
44+
spec.setupMethods.each {
45+
try {
46+
if (it.reflection) {
47+
ReflectionUtil.invokeMethod(invocation.target, it.reflection)
48+
}
49+
} catch (Throwable t2) {
50+
// increment counter, since this is the start of the re-run
51+
attempts++
52+
LOG.info("Retry caught failure ${attempts + 1} / ${retryMax + 1} while setting up", t2)
4553
}
46-
} catch (Throwable t2) {
47-
// increment counter, since this is the start of the re-run
48-
attempts++
49-
LOG.info("Retry caught failure ${attempts + 1} / ${retryMax + 1} while setting up", t2)
5054
}
5155
}
5256
}

0 commit comments

Comments
 (0)