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

Test refactoring #153

Closed
wants to merge 14 commits into from
Closed

Test refactoring #153

wants to merge 14 commits into from

Conversation

frodopwns
Copy link
Contributor

@frodopwns frodopwns commented Aug 28, 2019

What this PR does / why we need it:

This PR rips out ginkgo for controller integration testing. My experience with Ginkgo has largely been poor and at this point, I believe we can get by without it.

  • Go Test is simpler to understand and write in. The BDD syntax (Describe, It syntax) doesn't add much value when compared to normal comments/logs
  • Ability to add build tags so we can select what tests to run
  • Output is similar to this if we enable ginkgo.verbose or debug, but we can control the output using Go Test better

The tests can all be run in parallel.

Run via

go test -parallel 3 -v -tags all ./controllers/...

or

makke test

If you are unsure whether all tests passed: echo $? to get the exit code

Expect(apierrors.IsInvalid(err)).To(Equal(false))
Expect(err).NotTo(HaveOccurred())

// prep query gor Get
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
// prep query gor Get
// prep query for Get

@frodopwns
Copy link
Contributor Author

note: the output needs some work still for sure

@frodopwns
Copy link
Contributor Author

Part of the goal here is to be able to debug individual tests from within the IDE. I think the build flags will need to be removed for that.

@szoio
Copy link
Contributor

szoio commented Sep 2, 2019

Hi @frodopwns

Some comments/questions/observations:

Go Test is simpler to understand and write in. The BDD syntax (Describe, It syntax) doesn't add much value when compared to normal comments/logs

Totally agree with this - can't say I ever quite drank the BDD kool-aid myself

The tests can all be run in parallel.

Can/will it accommodate synchronized shared setup and teardown?

Part of the goal here is to be able to debug individual tests from within the IDE. I think the build flags will need to be removed for that.

I've been using focus specs FDescribe etc to do this, definitely it's not ideal to have to edit the code to do this.

My experience with Ginkgo has largely been poor

So far my experience has been pretty average. I have been able to improve it a little with this PR to improve the existing tests (#172).
Not suggesting not to get rid of Ginkgo, but some small changes have improved the ginkgo experience quite a bit.

In fact happy to get rid of Ginkgo and move to go test, provided one can do common test setup, run several tests in parallel, then do common teardown.

}, tcfg.Timeout, tcfg.Poll,
).Should(BeTrue())

}
Copy link
Contributor

Choose a reason for hiding this comment

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

Secret test been removed?
(maybe they should be tested separately anyway)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This PR shouldn't be considered as ready to merge so much as a proposal to abandon Ginkkgo.


consumerGroupNamespacedName := types.NamespacedName{Name: consumerGroupName, Namespace: "default"}

Eventually(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.

Do we want to carry on using the Gomega assertions?
some other assertion lib?

@@ -115,3 +116,25 @@ func (eventhub *Eventhub) AddFinalizer(finalizerName string) {
func (eventhub *Eventhub) RemoveFinalizer(finalizerName string) {
eventhub.ObjectMeta.Finalizers = helpers.RemoveString(eventhub.ObjectMeta.Finalizers, finalizerName)
}

func NewTestEventhub(cfg TestConfig, namespace string) *Eventhub {
Copy link
Contributor

Choose a reason for hiding this comment

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

For Simplicity Please move this function to a separate file that contains all the initializations for the test.

@@ -99,3 +99,16 @@ func (eventhubNamespace *EventhubNamespace) AddFinalizer(finalizerName string) {
func (eventhubNamespace *EventhubNamespace) RemoveFinalizer(finalizerName string) {
eventhubNamespace.ObjectMeta.Finalizers = helpers.RemoveString(eventhubNamespace.ObjectMeta.Finalizers, finalizerName)
}

func NewTestEventhubNamespace(cfg TestConfig) *EventhubNamespace {
Copy link
Contributor

Choose a reason for hiding this comment

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

For Simplicity Please move this function to a separate file that contains all the initializations for the test

@@ -83,3 +83,15 @@ func (resourceGroup *ResourceGroup) AddFinalizer(finalizerName string) {
func (resourceGroup *ResourceGroup) RemoveFinalizer(finalizerName string) {
resourceGroup.ObjectMeta.Finalizers = helpers.RemoveString(resourceGroup.ObjectMeta.Finalizers, finalizerName)
}

func NewTestResourceGroup(cfg TestConfig) *ResourceGroup {
Copy link
Contributor

Choose a reason for hiding this comment

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

For Simplicity Please move this function to a separate file that contains all the initializations for the test

@Azadehkhojandi
Copy link
Contributor

I don’t have any preference in terms of a testing framework the only comment I would add there are some drawbacks if branch out from kubebuilder test framework

  1. We will lose the auto-generated test codes when we add new Resource. @erin Corson have you checked if kubebuilder create api --group xxx --version xxx --kind xxx works after your changes?
  2. .@erin Corson have you benchmarked the two approaches and do you have a duration of each approach?
  3. We might not be able to benefit from the community contribution towards tests in kubebuilder repo.
  4. It might affect onboarding and the community contribution at this point whoever read kubebuilder book can jump in but with the new framework we need to add documentation and guideline

@frodopwns
Copy link
Contributor Author

frodopwns commented Sep 4, 2019

The tests can all be run in parallel.

Can/will it accommodate synchronized shared setup and teardown?

Currently it allows a Global setup/teardown. It happens before parallelization starts, so I'm assuming it is "synchronized".
edit - There does seem to be errors at the end of the integration tests I think from the tests and k8smanager not ending at the same time.

Part of the goal here is to be able to debug individual tests from within the IDE. I think the build flags will need to be removed for that.

I've been using focus specs FDescribe etc to do this, definitely it's not ideal to have to edit the code to do this.

I've never heard of this which immediately makes me not like it. Normal go tests can be isolated simply from the VSCode IDE code lenses.

My experience with Ginkgo has largely been poor

So far my experience has been pretty average. I have been able to improve it a little with this PR to improve the existing tests (#172).
Not suggesting not to get rid of Ginkgo, but some small changes have improved the ginkgo experience quite a bit.

In fact happy to get rid of Ginkgo and move to go test, provided one can do common test setup, run several tests in parallel, then do common teardown.

This is possible and exists in this PR. I'm not dead set on making this change. For the most part I wanted to draw attention to the state of the tests which were hard to run and harder to debug. Which is the opposite of how we want the tests.

@frodopwns
Copy link
Contributor Author

I don’t have any preference in terms of a testing framework the only comment I would add there are some drawbacks if branch out from kubebuilder test framework

  1. We will lose the auto-generated test codes when we add new Resource. @erin Corson have you checked if kubebuilder create api --group xxx --version xxx --kind xxx works after your changes?

The only issue preventing kubebuilder create from working is that I removed the Gomega import from suite_test.go. So the go vet call at the end of the generation causes a failure. Putting the gomega import back in causes the generation to work fine.

  1. .@erin Corson have you benchmarked the two approaches and do you have a duration of each approach?

The tests in master aren't currently being run in parallel (I think?), so I didn't compare them. I would expect performance not to change otherwise.

  1. We might not be able to benefit from the community contribution towards tests in kubebuilder repo.

I'm not aware of anything coming down the line that would be useful to us wrt testing.

  1. It might affect onboarding and the community contribution at this point whoever read kubebuilder book can jump in but with the new framework we need to add documentation and guideline

Having more go-like testing should be a boon to new devs on the project as it would match their expectation more closely.

@frodopwns
Copy link
Contributor Author

I think I have a new proposal. The more I think about it, the more I think the controller tests in /controllers should be mocking the Azure bit in some way. Maybe that means skipping the call to Azure, maybe that means calling some fake service. It should check that the statuses get updated properly and that the correct actions would be taken if it were real.

The end-to-end integration tests should be run against a live AKS cluster. I'd like to see this take the form of actual applications that get deployed using the operator. Some apps like this already exist in the Azure world.

eg. https://github.com/Azure-Samples/azure-voting-app-redis

@frodopwns
Copy link
Contributor Author

closing this PR...discussed with stakeholders....

new plan is to make improvements to the current ginkgo usage and slowly move toward mocked azure interaction in the /controllers tests...e2e tests will be moved to z different directory

Porges pushed a commit that referenced this pull request May 11, 2021
- No change in CI, but this makes it easier to catch missing headers in the generator files before opening PRs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants