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

Improving Unit Test Logic and Time #59

Merged
merged 3 commits into from
Jun 25, 2023

Conversation

razo7
Copy link
Member

@razo7 razo7 commented Jun 21, 2023

  1. Separate logical unit-test and order- Test taint and finalizer existence in eventually following an expect rather than one eventually with and a logical OR/AND of there existence. This way we better check the order of their creation. Related to older comment.
  2. Reduce eventually timeout and polling interval- the values were too high

Test taint and finalizer existence in eventually following an expect rather than one eventually with and a logical OR/AND of there existance. This way we better check the order of their creation
@openshift-ci openshift-ci bot requested review from beekhof and slintes June 21, 2023 13:56
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jun 21, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: razo7

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

@@ -133,29 +133,37 @@ var _ = Describe("FAR Controller", func() {
It("should have finalizer and taint", func() {
farNamespacedName := client.ObjectKey{Name: node01, Namespace: defaultNamespace}
nodeNamespacedName := client.ObjectKey{Name: node01}
Copy link
Member

Choose a reason for hiding this comment

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

This is a bit confusing, since namespace isn't relevant in the context of nodes

Copy link
Member

Choose a reason for hiding this comment

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

I usually use something like nodeKey: it represents the type (ObjectKey) and it doesn't matter if it has a namespace or not 🙂

@@ -133,29 +133,37 @@ var _ = Describe("FAR Controller", func() {
It("should have finalizer and taint", func() {
farNamespacedName := client.ObjectKey{Name: node01, Namespace: defaultNamespace}
nodeNamespacedName := client.ObjectKey{Name: node01}
By("Searching for remediation taint")
Eventually(func() bool {
Expect(k8sClient.Get(context.Background(), nodeNamespacedName, node)).To(Succeed())
Copy link
Member

@mshitrit mshitrit Jun 22, 2023

Choose a reason for hiding this comment

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

I think that checking for the node existence, which is created in the test code (and not in production code) is redundant.
IMO it's roughly the equivalent of:

It("some test", func() {
  someVar := true
  Expect(someVar).To(BeTrue())
})

Copy link
Member Author

Choose a reason for hiding this comment

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

On the same principle I can ignore checking the CR creation, right?

Copy link
Member Author

@razo7 razo7 Jun 22, 2023

Choose a reason for hiding this comment

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

Even though that I don't agree that I can ignore this line, because without this k8sClient.Get call node variable won't be updated with the node from reconcile (and with taints that we check on line 141)...

Copy link
Member

Choose a reason for hiding this comment

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

Good point, definitely need to check the taint on the node.

return controllerutil.ContainsFinalizer(underTestFAR, v1alpha1.FARFinalizer) && utils.TaintExists(node.Spec.Taints, &farNoExecuteTaint) && res
}, 1*time.Second, 500*time.Millisecond).Should(BeTrue(), "finalizer and taint should be added, and command format is correct")
return utils.TaintExists(node.Spec.Taints, &farNoExecuteTaint) && res
}, 20*time.Millisecond, 10*time.Millisecond).Should(BeTrue(), "taint should be added, and command format is correct")
Copy link
Member

Choose a reason for hiding this comment

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

Nit: retry of every 10ms over a period of 20ms seems like cutting it really close, which in part defeating the use of Eventually, maybe use a longer period ? (first param)

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 will change to 100ms

@mshitrit
Copy link
Member

/lgtm

@openshift-ci openshift-ci bot added the lgtm label Jun 25, 2023
@openshift-merge-robot openshift-merge-robot merged commit c288eb6 into medik8s:main Jun 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants