Skip to content

test/e2e: Refactor the Operator e2e tests to clean up testing resources #2518

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

timflannagan
Copy link
Member

Update test/e2e/operator_test.go and attempt to refactor the current e2e
specs to reduce the number of testing artifacts that are left behind
when individual tests pass/fail.

Signed-off-by: timflannagan [email protected]

Description of the change:

Motivation for the change:

Reviewer Checklist

  • Implementation matches the proposed design, or proposal is updated to match implementation
  • Sufficient unit test coverage
  • Sufficient end-to-end test coverage
  • Docs updated or added to /doc
  • Commit messages sensible and descriptive

Eventually(func() error {
return client.Create(clientCtx, o)
}).Should(Succeed())
Context("when an Operator resource can select its components by label", func() {
Copy link
Member Author

Choose a reason for hiding this comment

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

Note: moved this from an It to a Context so we gain access to BeforeEach/AfterEach/etc. blocks. Before, this It spec would leak testing Operator resources when it failed the test case (but cleaned up properly when it passed).

Copy link
Contributor

Choose a reason for hiding this comment

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

A question and a nit:

Question: Why not start with a When?

nit: We should probably clean up the long list in the comment too. I believe they were written when old tests were being ported over to ginkgo, but time constraint forced to putting these in It blocks and keep those comments for safe measures.

Copy link
Contributor

@tylerslaton tylerslaton Dec 16, 2021

Choose a reason for hiding this comment

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

@anik120 +1 for both points.

How easily accessible is the same information in those comments if we were to remove them? Only thing I'd want to make sure of is that we're not losing context in removing them.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep agreed - I removed the list of existing comments from this PR and changed the Context -> When container. I'd like to hold off on refactoring that "should surface referenced components in its status" test case as it's not been marked as a flaky when Per had added support for identifying and running flaky tests in their own workflow in #2624.

Expect(err).ToNot(HaveOccurred())
defer w.Stop()
It("should not contain copied csv status references", func() {
Consistently(o).ShouldNot(ContainCopiedCSVReferences())
Copy link
Member Author

Choose a reason for hiding this comment

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

I moved this check to it's own It spec as before we were checking whether the operator object had any CSV references before creating that resource, leading to what appeared to be a wasted check.

}
return err
}).Should(Succeed())
})
})

Context("when a subscription to a package exists", func() {
Copy link
Member Author

Choose a reason for hiding this comment

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

Note: we were previously leaking the kiali installation, it's CRDs, and the corresponding Operator resource that was generated despite these test cases passing or failing.

})
}).Should(Succeed())

By("Deleting the test Operator resource")
Copy link
Member Author

Choose a reason for hiding this comment

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

It's highly likely that the generated Operator resource will be left behind, despite this check being in place, as there's some caching issues in the current operator controller. I added a top-level DeleteCollection call in the AfterEach block to help alleviate the frequency this happens.

Copy link
Contributor

@anik120 anik120 left a comment

Choose a reason for hiding this comment

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

looks great Tim, have a few very small nits other lgtm

Eventually(func() error {
return client.Create(clientCtx, o)
}).Should(Succeed())
Context("when an Operator resource can select its components by label", func() {
Copy link
Contributor

Choose a reason for hiding this comment

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

A question and a nit:

Question: Why not start with a When?

nit: We should probably clean up the long list in the comment too. I believe they were written when old tests were being ported over to ginkgo, but time constraint forced to putting these in It blocks and keep those comments for safe measures.

Comment on lines +104 to +83
Expect(err).To(BeNil())
defer w.Stop()
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Expect(err).To(BeNil())
defer w.Stop()
defer w.Stop()
Expect(err).To(BeNil())
Suggested change
Expect(err).To(BeNil())
defer w.Stop()
Expect(err).To(BeNil())
defer w.Stop()

Copy link
Member Author

Choose a reason for hiding this comment

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

I updated the Context -> When given the comment structure was already there. Do you have any preference when to use a Context vs. When containers? I wasn't able to find any best practices around structuring ginkgo e2e tests so there might be something I'm missing.

Copy link
Contributor

@tylerslaton tylerslaton left a comment

Choose a reason for hiding this comment

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

/lgtm

Small question, but overall the approach looks great. I like the defer pattern you have for cleaning up the resources.

nsB.SetName(genName("ns-b-"))
return false
}))
defer w.Stop()
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this second defer w.Stop() necassary?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think so - I mainly just indented the existing test cases vs. making any heavy modifications.

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Dec 16, 2021
@timflannagan timflannagan force-pushed the ci/refactor-operator-e2e-tests branch from c813df3 to 2e808cf Compare January 27, 2022 16:52
@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Jan 27, 2022
@openshift-ci
Copy link

openshift-ci bot commented Jan 27, 2022

New changes are detected. LGTM label has been removed.

@openshift-ci
Copy link

openshift-ci bot commented Jan 27, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: timflannagan

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:

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

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 27, 2022
@timflannagan timflannagan force-pushed the ci/refactor-operator-e2e-tests branch 2 times, most recently from 46ff42f to 4bb317b Compare January 27, 2022 21:38
@timflannagan timflannagan force-pushed the ci/refactor-operator-e2e-tests branch from 4bb317b to c3bb990 Compare February 17, 2022 16:48
Update test/e2e/operator_test.go and attempt to refactor the current e2e
specs to reduce the number of testing artifacts that are left behind
when individual tests pass/fail.

Signed-off-by: timflannagan <[email protected]>
@timflannagan timflannagan force-pushed the ci/refactor-operator-e2e-tests branch from c3bb990 to 1a21657 Compare March 2, 2022 22:17
@openshift-ci
Copy link

openshift-ci bot commented Apr 9, 2022

@timflannagan: PR needs rebase.

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/test-infra repository.

@openshift-ci openshift-ci bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 9, 2022
@timflannagan timflannagan deleted the ci/refactor-operator-e2e-tests branch July 28, 2022 18:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants