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

Remove duplicated code in e2e tests #155

Merged
merged 1 commit into from
Sep 7, 2024

Conversation

k-keiichi-rh
Copy link
Contributor

Why we need this PR

Refactoring for the duplicated code in e2e tests

Changes made

Extract the common test routine and remove the duplication

Copy link
Contributor

openshift-ci bot commented Aug 29, 2024

Hi @k-keiichi-rh. Thanks for your PR.

I'm waiting for a medik8s member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

@@ -163,8 +126,18 @@ var _ = Describe("FAR E2e", func() {
remediationTimes = append(remediationTimes, time.Since(startTime))
})
})
}

Context("stress cluster with OutOfServiceTaint remediation strategy", func() {
Copy link
Member

Choose a reason for hiding this comment

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

The context doesn't match the RemediationStrategy.

Suggested change
Context("stress cluster with OutOfServiceTaint remediation strategy", func() {
Context("stress cluster with ResourceDeletion remediation strategy", func() {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry. Fixed it.

@razo7
Copy link
Member

razo7 commented Aug 29, 2024

/ok-to-test

})
})
Context("stress cluster with OutOfServiceTaint remediation strategy", func() {
runFARTests := func(remediationStrategy v1alpha1.RemediationStrategyType, skipCondition func() bool) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe I'm missing something, but can we just use a normal function here?

func runFARTest(...) bool {
...
}

Copy link
Member

Choose a reason for hiding this comment

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

I've seen and used this pattern especially in tests more often. Advantages IMHO:

  • the function is "physically" located nearer to the code where it's used, which improves readability IMHO
  • the function has direct access to vars of the context, so less args are needed
  • often these functions are very special for the tests of a specific context. Making them a regular func would make them available for all tests though, which isn't needed

Copy link
Contributor

Choose a reason for hiding this comment

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

Fair enough, could we make it stand up a bit more in the context then? Even some space around might be enough

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@slintes Thank you for the explanation. This is everything I thought.
In the current code, the test routine I wrote is duplicated and it will be troubled for maintenance in the future.
To remove the duplicated code, it needs access to vars of the context. This is the reason why I used this pattern.
@clobrano
Thank you for the comment. I added the following comment. Is that fine for you?

+       // runFARTests is a utility function to run FAR tests.
+       // It accepts a remediation strategy and a condition to determine if the tests should be skipped.
+       runFARTests := func(remediationStrategy v1alpha1.RemediationStrategyType, skipCondition func() bool) {

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, thank you

@razo7
Copy link
Member

razo7 commented Aug 30, 2024

/retest

@razo7
Copy link
Member

razo7 commented Sep 1, 2024

If the PR changes suit your needs and it is ready to be approved and reviewed, then please remove [WIP] from the PR title as it adds a blocker label do-not-merge/work-in-progress @k-keiichi-rh

@razo7
Copy link
Member

razo7 commented Sep 1, 2024

/approve

Copy link
Contributor

openshift-ci bot commented Sep 1, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: k-keiichi-rh, 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

@openshift-ci openshift-ci bot added the approved label Sep 1, 2024
@k-keiichi-rh k-keiichi-rh changed the title [WIP] Remove duplicated code in e2e tests Remove duplicated code in e2e tests Sep 6, 2024
@k-keiichi-rh
Copy link
Contributor Author

As far as I checked, I have no concerns for this patch.
I appreciate it if you could review the patch. Thanks.

@razo7
Copy link
Member

razo7 commented Sep 7, 2024

Looking at the logs it works as designed.
Thank you @k-keiichi-rh for this improvement to the e2e test code.
/lgtm

@openshift-ci openshift-ci bot added the lgtm label Sep 7, 2024
@openshift-merge-bot openshift-merge-bot bot merged commit 646fb5e into medik8s:main Sep 7, 2024
27 checks passed
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