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

Migrate unit tests to use gomock. #203

Closed

Conversation

amshuman-kr
Copy link
Collaborator

@amshuman-kr amshuman-kr commented Jul 13, 2021

How to categorize this PR?

/area control-plane
/kind technical-debt

What this PR does / why we need it:

Migrate all controller unit tests to use gomock framework. I have also tried to make the test flow easier to understand, to contribute and maintain.

Which issue(s) this PR fixes:
Fixes #97

Special notes for your reviewer:

This is in preparation for #186 so that any regressions can be caught early in the unit tests.
Apologies for large changes to etcd_controller_test.go but it made sense to rationalise test flow. I have also added additional tests in the deletion use-case as well many other permutations and combinations for regular reconciliation.

Release note:

NONE

@amshuman-kr amshuman-kr requested a review from a team as a code owner July 13, 2021 08:33
@gardener-robot-ci-2 gardener-robot-ci-2 added the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Jul 13, 2021
@gardener-robot-ci-1 gardener-robot-ci-1 added needs/ok-to-test Needs approval for testing (check PR in detail before setting this label because PR is run on CI/CD) and removed reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) labels Jul 13, 2021
@gardener-robot gardener-robot added area/control-plane Control plane related kind/technical-debt Something that is only solved on the surface, but requires more (re)work to be done properly needs/review Needs review size/xl Size of pull request is huge (see gardener-robot robot/bots/size.py) needs/second-opinion Needs second review by someone else labels Jul 13, 2021
@gardener-robot-ci-2 gardener-robot-ci-2 added the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Jul 13, 2021
@gardener-robot-ci-1 gardener-robot-ci-1 removed the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Jul 13, 2021
@amshuman-kr
Copy link
Collaborator Author

The controller suite test execution time has come down from 2m35s to 2.79s.

@amshuman-kr
Copy link
Collaborator Author

/hold It would be a good idea to merge this PR after #197 because it has some more changes to reconciliation and controller tests which I would prefer to cover in the migration to Gomock (in that case, I will need to rebase and migrate the additional tests from #197).

@gardener-robot gardener-robot added the reviewed/do-not-merge Has no approval for merging as it may break things, be of poor quality or have (ext.) dependencies label Jul 14, 2021
@gardener-robot
Copy link

@shreyas-s-rao, @abdasgupta, @ishan16696 You have pull request review open invite, please check

@gardener-robot-ci-1 gardener-robot-ci-1 added the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Jul 16, 2021
@gardener-robot-ci-3 gardener-robot-ci-3 removed the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Jul 16, 2021
@amshuman-kr
Copy link
Collaborator Author

/unhold I have rebased the PR after #197 was merged. I have also migrated the additional tests from #197.

@gardener-robot gardener-robot removed the reviewed/do-not-merge Has no approval for merging as it may break things, be of poor quality or have (ext.) dependencies label Jul 16, 2021
@timuthy
Copy link
Member

timuthy commented Jul 19, 2021

/assign

@gardener-robot-ci-3 gardener-robot-ci-3 added the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Jul 21, 2021
@amshuman-kr
Copy link
Collaborator Author

I have rebased after the merge of #202 which conflicted with this PR.

@gardener-robot-ci-2 gardener-robot-ci-2 removed the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Jul 21, 2021
@gardener-robot-ci-3 gardener-robot-ci-3 added reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) and removed reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) labels Jul 26, 2021
@amshuman-kr
Copy link
Collaborator Author

Do you also want to remove the envtest tool from .ci/test?

It is still used in api_tests. I retained it just to verify if the CRDs are generated and working properly.

The test cover many different use-cases which is also the reason there is a lot of nesting. As a reviewer it's not trivial to understand or as a developer not easy to maintain this with all the different mocks and BeforeEach()/AfterEachs being involved.

The existing tests covered whole reconciliation. Wanting to be sure that I still cover all the existing test cases after the migration, I retained the migrated tests also to cover whole of reconciliation. But I used nesting to introduce more variations in the test cases by piecemeal nesting and also to avoid too much duplication of the test setup.

But I can imagine that these tests will help us to extract functionality into smaller junks, especially from etcd_controller.go with a lower risk of introducing regressions while doing so. I really hope that we're going to go that way with the Druid :)

Indeed, the goal is to modularise the reconciliation flow and to be able to then test these smaller functions independently. This way we should also be able to reduce the nesting of test blocks into independent test descriptions. I think this is best done over a few more PRs than in one single PR, if only to make sure we are not regressing or worse, losing test cases that were already covered.

@amshuman-kr
Copy link
Collaborator Author

@timuthy Thanks for the review! I have addressed your comments. Can you PTAL?

Copy link
Member

@timuthy timuthy left a comment

Choose a reason for hiding this comment

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

/lgtm
Thank you 👍

@gardener-robot gardener-robot added reviewed/lgtm Has approval for merging and removed needs/changes Needs (more) changes needs/review Needs review needs/second-opinion Needs second review by someone else labels Jul 26, 2021
@gardener-robot gardener-robot added needs/second-opinion Needs second review by someone else and removed reviewed/lgtm Has approval for merging labels Aug 24, 2021
@gardener-robot-ci-1 gardener-robot-ci-1 added the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Aug 24, 2021
@gardener-robot-ci-2 gardener-robot-ci-2 removed the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Aug 24, 2021
@amshuman-kr
Copy link
Collaborator Author

Rebased and resolved conflicts. Made the gmock based tests to work for the lease listing changes introduced in #214.

@gardener-robot-ci-2 gardener-robot-ci-2 added reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) and removed reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) labels Aug 31, 2021
@amshuman-kr
Copy link
Collaborator Author

Rebased after the v0.6.0 release.

@timuthy timuthy added reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) and removed needs/ok-to-test Needs approval for testing (check PR in detail before setting this label because PR is run on CI/CD) labels Sep 6, 2021
@gardener-robot-ci-2 gardener-robot-ci-2 added needs/ok-to-test Needs approval for testing (check PR in detail before setting this label because PR is run on CI/CD) and removed reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) labels Sep 6, 2021
@gardener-robot
Copy link

@amshuman-kr You need rebase this pull request with latest master branch. Please check.

@gardener-robot gardener-robot added the needs/rebase Needs git rebase label Nov 17, 2021
@timuthy
Copy link
Member

timuthy commented Dec 23, 2021

Let's close this in favor of #278 which will allow us to have sufficient coverage for single components (+ easy maintenance as opposed to maintaining plenty of Gomock assertions) and only a handful of envtest like tests which test the controller from end-to-end.
/close

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/control-plane Control plane related kind/technical-debt Something that is only solved on the surface, but requires more (re)work to be done properly needs/ok-to-test Needs approval for testing (check PR in detail before setting this label because PR is run on CI/CD) needs/rebase Needs git rebase needs/second-opinion Needs second review by someone else size/xl Size of pull request is huge (see gardener-robot robot/bots/size.py)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] Unit tests for etcd-druid reconciliation cycle
6 participants