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 framework improvement, doing proper clean up in BeforeSuite(), AfterEach(), AfterSuite() #225

Merged
merged 11 commits into from
Apr 26, 2023

Conversation

zijun726911
Copy link
Contributor

@zijun726911 zijun726911 commented Apr 24, 2023

Changes

Test

make e2etest pass

Ran 3 of 3 Specs in 808.077 seconds
SUCCESS! -- 3 Passed | 0 Failed | 0 Pending | 0 Skipped

Update removed https traffic test in the new revision now it only have 2 test case

Full log: https://gist.github.com/zijun726911/7c8ed592b02f4f9911632c8c6a439a3d

Zijun Wang added 4 commits April 23, 2023 15:36
- Add service import and export traffic test
- Further Test Framework imporvement
- Bug fix for service import and export, when handling Kind: ServiceExport k8s resource, the latticestore should create create a IsServiceImport==true cache for it
@zijun726911
Copy link
Contributor Author

Closed the previous PR

#224

@coveralls
Copy link

coveralls commented Apr 24, 2023

Pull Request Test Coverage Report for Build 4789745461

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 31.824%

Totals Coverage Status
Change from base Build 4788183481: 0.0%
Covered Lines: 3169
Relevant Lines: 9958

💛 - Coveralls

clientDeployment, clientService := testFramework.NewHttpApp(test.HTTPAppOptions{Name: "client"})
serverDeployment, serverService := testFramework.NewHttpApp(test.HTTPAppOptions{Name: "https-gw-server"})
httproute := testFramework.NewPathMatchHttpRoute(gateway, []client.Object{serverService}, "https")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

to pass "https" in the NewPathMatchHttpRoute(), it will refer the "https" section in the gateway listener

@zijun726911
Copy link
Contributor Author

Update: removed https traffic test in the new revision now it only have 2 test case

@coveralls
Copy link

coveralls commented Apr 24, 2023

Pull Request Test Coverage Report for Build 4812312590

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 31.824%

Totals Coverage Status
Change from base Build 4788183481: 0.0%
Covered Lines: 3169
Relevant Lines: 9958

💛 - Coveralls

Copy link
Contributor

Choose a reason for hiding this comment

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

Will this mess that folks(most of us) doing development on clouddesktop ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Developer should run (or set it in GoLand manually) load_env_variables.sh manually, and no where refer it.

I have some comments in this script, if it is still confusing, I could remove this script

Copy link
Contributor

Choose a reason for hiding this comment

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

Today, Makefile takes care of all these environment variable setting. @ellistarn should we merge these into Makefile?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not familiar with golang env vars, but I'd avoid any ide specific configuration. At the end of the day, your team needs to choose the development practices that work best for you. I setup what works for me, and how I run other OSS projects. Feel free to change things.

@@ -5,7 +5,7 @@ import (
"sigs.k8s.io/gateway-api/apis/v1beta1"
)

func (env *Framework) NewGateway() *v1beta1.Gateway {
func (env *Framework) NewHttpGateway() *v1beta1.Gateway {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason to make this? A gateway can have multiple listener(s), one for HTTP and one for HTTPs. And need a e2e test case to cover a single HTTPRoute can be accessed through HTTP and HTTPs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe put 2 listeners in one GW is better, I will change to that one in the next revision

Spec: v1beta1.GatewaySpec{
				GatewayClassName: "amazon-vpc-lattice",
				Listeners: []v1beta1.Listener{
					{
						Name:     "http",
						Protocol: v1beta1.HTTPProtocolType,
						Port:     80,
					},
					{
						Name:     "https",
						Protocol: v1beta1.HTTPSProtocolType,
						Port:     443,
					},
				},
			},

t.SetName(RandomName())
}
if t.GetNamespace() == "" {
t.SetNamespace("default")
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a note, we also need to test things in non-default namespace, e.g.

  • httproute
  • gateway

@zijun726911 zijun726911 changed the title Add Https Listener traffic test, Test framework improvement Test framework improvement, doing proper clean up in BeforeSuite(), AfterEach(), AfterSuite() Apr 24, 2023
Makefile Outdated
@@ -2,6 +2,8 @@ export KUBEBUILDER_ASSETS ?= ${HOME}/.kubebuilder/bin
export CLUSTER_NAME ?= $(shell kubectl config view --minify -o jsonpath='{.clusters[].name}' | rev | cut -d"/" -f1 | rev | cut -d"." -f1)
export CLUSTER_VPC_ID ?= $(shell aws eks describe-cluster --name $(CLUSTER_NAME) | jq -r ".cluster.resourcesVpcConfig.vpcId")
export AWS_ACCOUNT_ID ?= $(shell aws sts get-caller-identity --query Account --output text)
export GATEWAY_API_CONTROLLER_LOGLEVEL ?= dubug
Copy link
Contributor

Choose a reason for hiding this comment

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

typo: debug?

Makefile Outdated
@@ -2,6 +2,8 @@ export KUBEBUILDER_ASSETS ?= ${HOME}/.kubebuilder/bin
export CLUSTER_NAME ?= $(shell kubectl config view --minify -o jsonpath='{.clusters[].name}' | rev | cut -d"/" -f1 | rev | cut -d"." -f1)
export CLUSTER_VPC_ID ?= $(shell aws eks describe-cluster --name $(CLUSTER_NAME) | jq -r ".cluster.resourcesVpcConfig.vpcId")
export AWS_ACCOUNT_ID ?= $(shell aws sts get-caller-identity --query Account --output text)
export GATEWAY_API_CONTROLLER_LOGLEVEL ?= debug
Copy link
Contributor

Choose a reason for hiding this comment

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

remove these from Makefile

Makefile Outdated
@@ -2,6 +2,8 @@ export KUBEBUILDER_ASSETS ?= ${HOME}/.kubebuilder/bin
export CLUSTER_NAME ?= $(shell kubectl config view --minify -o jsonpath='{.clusters[].name}' | rev | cut -d"/" -f1 | rev | cut -d"." -f1)
export CLUSTER_VPC_ID ?= $(shell aws eks describe-cluster --name $(CLUSTER_NAME) | jq -r ".cluster.resourcesVpcConfig.vpcId")
export AWS_ACCOUNT_ID ?= $(shell aws sts get-caller-identity --query Account --output text)
export GATEWAY_API_CONTROLLER_LOGLEVEL ?= debug
export REGION ?= us-west-2
Copy link
Contributor

Choose a reason for hiding this comment

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

remove these from Makefile

@@ -0,0 +1,46 @@
#!/bin/sh
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you update docs/developer.md and mentioned that this can be used for when u want to run it inside golang IDE locally

@@ -82,10 +83,20 @@ func NewFramework(ctx context.Context) *Framework {

SetDefaultEventuallyTimeout(180 * time.Second)
SetDefaultEventuallyPollingInterval(10 * time.Second)
AfterEach(func() { framework.ExpectToBeClean(ctx) })
BeforeSuite(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.

Will change to:

BeforeEach((func(){ExpectToBeClean()})

and remove current BeforeSuite()

}
framework.TestCasesCreatedK8sResource = nil
framework.CleanServiceNetworkVpcAssociationForCurrentK8sClusterVpc()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In AfterEach do framework.CleanTestEnvironment(ctx) to clean all pevious test created k8s resource and vpcLattice resource

@zijun726911
Copy link
Contributor Author

New test result, make e2etest still passed https://gist.github.com/zijun726911/3240c8e9a6990db894237015a31753bb

Do CleanTestEnvironment() in AfterEach()
Pass `FOCUS` environment variable to run some specific test cases based on filter condition:
```bash
export REGION=us-west-2
export FOCUS="HTTPRoute should support multiple path matches"
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a note on how to find out the this FOCUS string to a particular test. thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, Added more description in the next revision

Logger(ctx).Infof("Deleting k8s resource %s %s/%s", reflect.TypeOf(object), object.GetNamespace(), object.GetName())
env.Delete(ctx, object)
//Ignore resource-not-found error here, as the test case logic itself could already clear the resources
}

//Theoretically, Deleting all k8s resource by `env.ExpectDeleteAllToSucceed()`, will make controller delete all related VPC Lattice resource,
//but the controller is still developing in the progress and may leaking some vPCLattice resource, need to invoke vpcLattice api to double confirm and delete leaking resource.
env.DeleteAllFrameworkTracedServiceNetworks(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's NOT do these automatically. The test should failed and stopped if this is the case, and let developer debug why it is the case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, actually now no where invoke the CleanTestEnvironment(), we could remove this method, but maybe we could keep it in case we use it in the future?

@@ -324,7 +320,25 @@ func (env *Framework) DeleteAllFrameworkTracedServiceNetworks(ctx aws.Context) {
}
}

//TODO: check and delete serviceNetwork VPC associations
var allServiceNetworkVpcAssociationIdsToBeDeleted []*string
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's not use test code to cleanup the resource for now. Let developer debug why it is leaked and manually clean them up.

Also, if these are not cleanup, the test should stop

podList := &v1.PodList{}
g.Expect(env.List(ctx, podList, client.MatchingLabels(deployment.Spec.Selector.MatchLabels))).To(Succeed())
expectedMatchingLabels := make(map[string]string, len(deployment.Spec.Selector.MatchLabels))
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible these are the one causing my 2nd test stucked waiting for target?

Copy link
Contributor

@liwenwu-amazon liwenwu-amazon 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!

@zijun726911 zijun726911 merged commit 0a27c5b into aws:main Apr 26, 2023
@zijun726911 zijun726911 deleted the https-test branch September 20, 2023 16:26
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