-
-
Notifications
You must be signed in to change notification settings - Fork 659
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
first-in-last-out order for AfterEach and DeferCleanup #1022
Comments
hey @pohly I'm going to update the documentation to better describe the ordering for clean-up nodes so that it can be clearer going forward; however the current ordering behavior for
This ordering has the side-effect of making it hard to write support structures like Describe("...", func() {
var f *framework.Framework
BeforeEach(func() {
f = framework.NewFramework()
f.Setup()
})
AfterEach(func() {
f.Cleanup()
})
// ...tests
}) This is, admittedly, more boilerplate and error-prone. With V2, however, you can keep what you want: Describe(..., func() {
f := framework.NewDefaultFramework()
AfterEach(func() {
// use f
})
}) ...you just need to use func NewDefaultFramework() *framework.Framework {
var f *framework.Framework
BeforeEach(func() {
f = &framework.Framework{}
//...
DeferCleanup(func() {
f.Cleanup()
//etc...
})
})
return f
}) This will work as desired because of how Ginkgo orders All of this needs to be better documented but |
I agree that |
ok great. i'll plan to close this issue after i update the docs, then. |
In the Kubernetes E2E framework, we have tests like this:
NewDefaultFramework
callsBeforeEach
to set up the content of f andAfterEach
to clean up for each test.The problem now is that currently
AfterEach
seems to be called in first-in-first-out order inside the same node.Therefore this code is slightly wrong because although the f pointer is valid, its content no longer is (already cleaned up).
The workaround is this:
But that causes additional indention and the reason for it is not obvious without comments.
A better solution would be to execute
AfterEach
in first-in-last-out order. My reading of the current documentation is that only the order of nested nodes is specified (inner first), while the behavior inside the same node is undefined. Therefore defining and implementing it as first-in-last-out would be a clarification, not an API break.The same order would be needed for
DeferCleanup
.The text was updated successfully, but these errors were encountered: