-
Notifications
You must be signed in to change notification settings - Fork 40.6k
use ginkgo.DeferCleanup to do cleanup tasks #128585
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
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: carlory The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
#128581 is at the merge pool, so I open this PR. |
Can you please give more details? (code itself LGTM, but I'm not a reviewer for this area) |
@ffromani there is an example. #127790 (comment) |
thanks, the reason I ask is because |
/triage accepted I think we have enough evidence this is a fix we want, so I'm triage-accepting. Deferring prioritization (and review) to sig-auth |
unrelated failure /retest |
@@ -268,11 +268,11 @@ var _ = SIGDescribe(feature.ClusterTrustBundle, feature.ClusterTrustBundleProjec | |||
var cleanups []func(ctx context.Context) | |||
var projections []v1.VolumeProjection | |||
|
|||
defer func() { |
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.
this is added to that hook at the beginning, see line 65
ginkgo.JustBeforeEach(func(ctx context.Context) {
cleanup := mustInitCTBs(ctx, f, initCTBs)
ginkgo.DeferCleanup(cleanup)
})
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.
@aojea The initCTBs
and cleanups
are declared in the It
container, not in its parent container Describe
.
child
https://github.com/carlory/kubernetes/blob/master/test/e2e/auth/projected_clustertrustbundle.go#L268parent
https://github.com/carlory/kubernetes/blob/master/test/e2e/auth/projected_clustertrustbundle.go#L64
so JustBeforeEach
won't call cleanups
.
BTW, in my opinion, the JustBeforeEach
is abused here. It's used to separate creation and configuration which is set with the BeforeEach
in each child It
container. JustBeforeEach
should be used with care as it can add complexity to a test suite.
While powerful and flexible overuse of JustBeforeEach (and nest JustBeforeEaches in particular!) can lead to confusing suites to be sure to use JustBeforeEach judiciously!
From the doc https://onsi.github.io/ginkgo/#separating-creation-and-configuration-justbeforeeach
BeforeEach
may be enough for this e2e suite.
I used this patch in #129053 (with correct author - you) if that's ok. Aside from fixing the tests to run in parallel, the PR also replaces the |
Thanks @stlaz /close |
@carlory: Closed this PR. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
What type of PR is this?
/kind flake
What this PR does / why we need it:
defer
cannot make sure the function is called when the test is unexpectedly terminated. Useginkgo.DeferCleanup
instead.Which issue(s) this PR fixes:
Ref #128578
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: