Closed akrejcir closed 4 months ago
hey there - I appreciate the surprise factor here isn't great - but this is operating as intended. I should probably make the docs much clearer on this point but my intent with DeferCleanup
is to provide a cleaner and simpler mechanism for cleanup and want to nudge users in the direction of favoring it over After*
- you can mix the two in a given spec but then you'll end up with these edge cases.
Ginkgo could track things at the nesting level as you're describing but this will add complexity to the code (particularly some of the gnarly complexity around Ordered
). Also, at this point, it would constitute a change in behavior so I'm not inclined to change the cleanup ordering.
That makes sense, thank you for the explanation.
In one of our projects, we've noticed that
DeferCleanup()
blocks are run after allAfterEach()
blocks, without considering nesting. It may lead to a hard to find bug, when one of the top-levelAfterEach()
cleans up some resources, that a lower-levelDeferCleanup()
uses.Here is a simple code for illustration:
It prints:
I would expect this order:
I've tested it on the latest
master
of this repository (cd418b74c1e8).Related Issue: https://github.com/onsi/ginkgo/issues/1284