Skip to content
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

fix(flaky): ensure that the space is always unblocked for its deletion #1090

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

MatousJobanek
Copy link
Collaborator

make sure that the space is unblocked for the cleanup, even for the cases when the test execution is stopped in the middle and the sub-test (that is supposed to unblock the space) is not triggered: https://redhat-internal.slack.com/archives/C06MJ2DVBU4/p1736342796950679?thread_ts=1736333943.812749&cid=C06MJ2DVBU4

Copy link
Contributor

@fbm3307 fbm3307 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick fix

@@ -77,6 +77,20 @@ func TestCreateSpace(t *testing.T) {
// then
VerifyResourcesProvisionedForSpace(t, awaitilities, space.Name)

// ensure that the space is reset back to the original (valid) target cluster
// so the cleanup logic can delete the Space
var resetOnce sync.Once
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm... what's the point of using Once here? resetOnce.Do() will be called a single time only (for this specific resetOnce instance) anyway. What am I missing?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to ensure that this reset is called only once - either as part of the sub-test or at the end of the test. If it happens that the sub-test (that resets the target cluster) is called, then the space would be deleted - see:

t.Run("update target cluster to unblock deletion", func(t *testing.T) {
// when
reset()
// then
// space should be finally deleted
err = hostAwait.WaitUntilSpaceAndSpaceBindingsDeleted(t, s.Name)
require.NoError(t, err)
})

so the space wouldn't be present anymore

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or were you were asking why do I define the variable resetOnce outside of the function? Well, the variable has to stay outside, so when the function is called, it always uses the same instance of the Once. If it was moved inside of the function, then it would create a new instance of Once for every call of the function

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should not be a problem - but should we move this definition in the parent test TestCreateSpace ( where we define awaitilities , hostAwait, memberAwait ) ? Just to be on the safe side.

Copy link
Contributor

@alexeykazakov alexeykazakov Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I was missing is that the reset() was called twice (not once!). Once in the defer and the second time in the sub-test bellow. I saw it only in called by defer and was wondering why do you need once if it's already called only once :)
Sorry for the confusion.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we move this definition in the parent test TestCreateSpace ( where we define awaitilities , hostAwait, memberAwait ) ? Just to be on the safe side.

not really, it has to stay in the same (sub)test where the space is provisioned, so it's tied to the actual space (and also the the function that executes this sub-test)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not really, it has to stay in the same (sub)test where the space is provisioned, so it's tied to the actual space

makes sense , thanks for explaining that 👍

Copy link

sonarqubecloud bot commented Jan 9, 2025

Copy link
Contributor

@mfrancisc mfrancisc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍

@@ -77,6 +77,20 @@ func TestCreateSpace(t *testing.T) {
// then
VerifyResourcesProvisionedForSpace(t, awaitilities, space.Name)

// ensure that the space is reset back to the original (valid) target cluster
// so the cleanup logic can delete the Space
var resetOnce sync.Once
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should not be a problem - but should we move this definition in the parent test TestCreateSpace ( where we define awaitilities , hostAwait, memberAwait ) ? Just to be on the safe side.

Copy link

openshift-ci bot commented Jan 9, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alexeykazakov, fbm3307, MatousJobanek, mfrancisc, rajivnathan

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [MatousJobanek,alexeykazakov,fbm3307,mfrancisc,rajivnathan]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants