Skip to content
This repository has been archived by the owner on Nov 15, 2022. It is now read-only.

e2e test framework #77

Merged
merged 2 commits into from
Sep 1, 2017
Merged

e2e test framework #77

merged 2 commits into from
Sep 1, 2017

Conversation

surajssd
Copy link
Member

@surajssd surajssd commented Jun 27, 2017

Basic work for e2e test framework

Fixes #59

@surajssd
Copy link
Member Author

This won't compile in this directory right now because we have old client-go, right now to test it, just copy this script somewhere outside and following

go get k8s.io/client-go/...
go get -u k8s.io/apimachinery/...
go run main.go

@surajssd
Copy link
Member Author

@kadel @containscafeine initial feedback on this is welcome!

@surajssd surajssd changed the title e2e test framework [WIP] e2e test framework Jun 27, 2017
@surajssd surajssd mentioned this pull request Jun 27, 2017
@surajssd surajssd force-pushed the e2e_tests branch 2 times, most recently from a841c04 to 755e674 Compare June 28, 2017 11:18
@surajssd
Copy link
Member Author

surajssd commented Jun 28, 2017

  • add the new examples like single_file
  • add the new examples like envFrom
  • move from main to using testing framework this will need a removal of sync.WaitGroup
  • make the tests run in parallel by using t.Run on each test in table driven test and then add a t.Parallel in each test run.
  • delete ns even if the test fails
  • make the example test file name configurable relative to repo name(urgent)
  • once namespace support to kedge create is added then use that here.

@surajssd
Copy link
Member Author

Now since it is using golang test suite so the way to test is to goto e2e folder and run:

go test -v

@pradeepto
Copy link
Member

Very cool @surajssd . Thanks for taking this up proactively.

@concaf
Copy link
Collaborator

concaf commented Jul 3, 2017

Great work @surajssd, just that let's make sure this goes in small incremental PRs which are easier to review. I know this is blocked on updating client-go (:sob:), but yeah, this is for whenever that gets sorted.

@surajssd
Copy link
Member Author

@cdrage TBH in my workflow I never use make bin.

I just use:

make install

and then run kedge commands from wherever possible.

Now how do we make sure that people should have binary using make bin before running, the end to end tests.

@concaf
Copy link
Collaborator

concaf commented Aug 21, 2017

@surajssd the wordpress ns was failing for me and @surajnarwade the other day, was that fixed?

@surajssd
Copy link
Member Author

@containscafeine I might need to sit with you and get that resolved, because it works for the minikube I have, will have to figure why it fails.

@cdrage
Copy link
Collaborator

cdrage commented Aug 21, 2017

@surajssd In a lot of projects, there is no make install but rather the downloading of a binary from a website and moving to /usr/local/bin

make bin to make the binary and then make test-e2e for the tests. I'd much rather not use make install

@concaf
Copy link
Collaborator

concaf commented Aug 22, 2017

@surajssd works after the changes you suggested -

diff --git a/examples/wordpress/wordpress.yaml b/examples/wordpress/wordpress.yaml
index 1384034..d9df6f6 100644
--- a/examples/wordpress/wordpress.yaml
+++ b/examples/wordpress/wordpress.yaml
@@ -25,9 +25,12 @@ containers:
       httpGet:
         path: /
         port: 80
+      initialDelaySeconds: 20
+      timeoutSeconds: 5
+

@surajssd
Copy link
Member Author

@cdrage

@surajssd In a lot of projects, there is no make install but rather the downloading of a binary from a website and moving to /usr/local/bin make bin to make the binary and then make test-e2e for the tests. I'd much rather not use make install

done changes!

@containscafeine also done changes as you have shown in the diff!

@surajnarwade
Copy link
Collaborator

Works for me :)

$ make test-e2e 
go test github.com/kedgeproject/kedge/tests/e2e
ok  	github.com/kedgeproject/kedge/tests/e2e	191.008s

@surajssd
Copy link
Member Author

Can someone give LGTM and merge this one, I am not sure what is it blocked on now ? @cdrage @tkral @containscafeine

@cdrage
Copy link
Collaborator

cdrage commented Aug 28, 2017

So obviously not an error, but is there any way to add a time-out to these tests? For example, I ran the tests against a "dirty" minikube instance that had the previous namespaces and it took over 100seconds:

github.com/kedgeproject/kedge  pr_77 ✔                                                                                             12d  
▶ make test-e2e 
go test github.com/kedgeproject/kedge/tests/e2e
--- FAIL: Test_Integration (0.04s)
    --- FAIL: Test_Integration/Normal_Wordpress_test (0.02s)
        e2e_test.go:344: error creating namespace: namespaces "wordpress" already exists
    --- FAIL: Test_Integration/Testing_extraResources (0.02s)
        e2e_test.go:344: error creating namespace: namespaces "extraresources" already exists
    --- FAIL: Test_Integration/Testing_health (0.01s)
        e2e_test.go:344: error creating namespace: namespaces "health" already exists
    --- FAIL: Test_Integration/Testing_customVol (0.00s)
        e2e_test.go:344: error creating namespace: namespaces "customvol" already exists
FAIL
FAIL    github.com/kedgeproject/kedge/tests/e2e 105.803s
Makefile:60: recipe for target 'test-e2e' failed
make: *** [test-e2e] Error 1

@cdrage
Copy link
Collaborator

cdrage commented Aug 28, 2017

Another thing as well, I have no indication on what is being created / made... Can you somehow add some debug messages / info messages? make test-e2e doesn't show indication of it doing anything despite it creating containers and namespaces...

Literally all I get is this:

▶ make test-e2e 
go test github.com/kedgeproject/kedge/tests/e2e
ok      github.com/kedgeproject/kedge/tests/e2e 155.270s

Which isn't okay to see what tests have passed or not 👎

github.com/kedgeproject/kedge  pr_77 ✔                                                                                                                                                                                                                                      12d  
▶ kubectl get po
No resources found.

github.com/kedgeproject/kedge  pr_77 ✔                                                                                                                                                                                                                                      12d  
▶ kubectl get ns
NAME           STATUS    AGE
configmap      Active    4s
default        Active    1m
health         Active    4s
healthchecks   Active    4s
kube-public    Active    1m
kube-system    Active    1m
singlefile     Active    4s

github.com/kedgeproject/kedge  pr_77 ✔                                                                                                                                                                                                                                      12d  
▶ kubectl get po --all-namespaces
NAMESPACE      NAME                          READY     STATUS              RESTARTS   AGE
configmap      database-721670202-m62h0      0/1       ContainerCreating   0          8s
configmap      web-2351182281-zjjfl          0/1       ContainerCreating   0          6s
health         database-1377422287-t9rrz     0/1       ContainerCreating   0          8s
health         web-3359867758-snx34          0/1       ContainerCreating   0          7s
healthchecks   database-255470460-rsmbw      0/1       ContainerCreating   0          8s
healthchecks   web-2329707375-9s5pg          0/1       ContainerCreating   0          7s
healthchecks   web-2329707375-s27mr          0/1       ContainerCreating   0          7s
kube-system    kube-addon-manager-minikube   1/1       Running             0          1m
kube-system    kube-dns-1301475494-p6glm     3/3       Running             0          52s
kube-system    kubernetes-dashboard-nj4tg    1/1       Running             0          52s
singlefile     database-4172966911-mfhzm     0/1       ContainerCreating   0          8s
singlefile     wordpress-1717859168-bq3x2    0/1       ContainerCreating   0          7s

Another thing too, is there any way to rate-limit how many go routines are being created / what containers are being created? This slows down my computer A LOT and I wouldn't be surprised if this fails on Semaphore / Fabric8.

I believe we brought up the discussion in regards to adding a parameter to limit the amount of go routines (using go channels) with a passed in variable, for example: make test-e2e PARALLEL=2 or something.

@surajssd
Copy link
Member Author

surajssd commented Aug 31, 2017

@cdrage thanks for the review

So obviously not an error, but is there any way to add a time-out to these tests? For example, I ran the tests against a "dirty" minikube instance that had the previous namespaces and it took over 100seconds:

It took 100seconds because while some of the tests failed, some other tests were being run which passed. And golang test suite will show output only when tests are completed failed or passed. Since all the tests are run in parallel.

Another thing as well, I have no indication on what is being created / made... Can you somehow add some debug messages / info messages? make test-e2e doesn't show indication of it doing anything despite it creating containers and namespaces...

I have added bunch of log messages already, but the problem is with the golang test suite which will output only when all of tests have completed. So you won't see anything when it is in progress, but only after it has failed or passed.


About verbosity

I did not add verbosity to the tests because it is too much of output. Also when tests fail, the output is verbose anyway for the failed test. Like the following test:

Simulating an errorsome situation

$ kproject.sh wordpress
+ kubectl create ns wordpress
namespace "wordpress" created
+ kubectl config set-context minikube --namespace wordpress
Context "minikube" modified.


$ k get ns
NAME          STATUS    AGE
default       Active    13d
kube-public   Active    13d
kube-system   Active    13d
wordpress     Active    1m


$ make bin
go build -ldflags="-w -X github.com/kedgeproject/kedge/cmd.GITCOMMIT=0266683" -o kedge main.go

$ make test-e2e 
go test github.com/kedgeproject/kedge/tests/e2e
--- FAIL: Test_Integration (0.04s)
    --- FAIL: Test_Integration/Normal_Wordpress_test (0.01s)
        e2e_test.go:344: error creating namespace: namespaces "wordpress" already exists
FAIL
FAIL    github.com/kedgeproject/kedge/tests/e2e 117.438s
Makefile:60: recipe for target 'test-e2e' failed
make: *** [test-e2e] Error 1

Above you can see I see only output of failed test. But when you make it verbose for everything then it becomes hard to parse what failed and what passed due to amount of output that is thrown on the stdout.

Like see following with verbosity added:

$ make test-e2e
go test -v github.com/kedgeproject/kedge/tests/e2e
=== RUN   Test_Integration
=== RUN   Test_Integration/Testing_configMap
=== RUN   Test_Integration/Testing_customVol
=== RUN   Test_Integration/Testing_envFrom
=== RUN   Test_Integration/Testing_extraResources
=== RUN   Test_Integration/Testing_health
=== RUN   Test_Integration/Testing_healthChecks
=== RUN   Test_Integration/Testing_secret
=== RUN   Test_Integration/Testing_single_file
=== RUN   Test_Integration/Normal_Wordpress_test
--- FAIL: Test_Integration (0.03s)
    --- PASS: Test_Integration/Testing_single_file (31.88s)
        e2e_test.go:346: namespace "singlefile" created
        e2e_test.go:354: service "database" created
                deployment "database" created

[SNIP]

        e2e_test.go:183: "wordpress:8080" is running!
        e2e_test.go:370: Successfully pinged all endpoints!
        e2e_test.go:201: successfully deleted namespace: "singlefile"
    --- FAIL: Test_Integration/Normal_Wordpress_test (0.01s)
        e2e_test.go:344: error creating namespace: namespaces "wordpress" already exists
    --- PASS: Test_Integration/Testing_secret (32.17s)

[SNIP 300 lines]

        e2e_test.go:370: Successfully pinged all endpoints!
        e2e_test.go:201: successfully deleted namespace: "health"
FAIL
exit status 1
FAIL    github.com/kedgeproject/kedge/tests/e2e 87.011s
Makefile:60: recipe for target 'test-e2e' failed
make: *** [test-e2e] Error 1

Literally all I get is this:

I have added a verbose flag to the test suite, anyway. So now you will see more output than is there.

I believe we brought up the discussion in regards to adding a parameter to limit the amount of go routines (using go channels) with a passed in variable, for example: make test-e2e PARALLEL=2 or something.

Now you rate limit the number of go processes that run in parallel using the same: make test-e2e PARALLEL=2 otherwise it defaults to the number of processors that are there on your go test running machine. See this stackoverflow question for some background on this one.

@surajssd surajssd force-pushed the e2e_tests branch 2 times, most recently from 676ac66 to 5a852f5 Compare August 31, 2017 07:44
@surajssd
Copy link
Member Author

@cdrage also added instructions in docs/development.md

for _, test := range tests {
test := test // capture range variable
t.Run(test.TestName, func(t *testing.T) {
t.Parallel()
Copy link
Collaborator

Choose a reason for hiding this comment

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

See: https://golang.org/pkg/testing/ with t.Parallel() regardless of what you put as GOMAXPROCS it still runs everything at the same time. Deploying every test to Kubernetes.

Perhaps removing this would help...

Even with me setting the GOMAXPROCS to something lower, I still have every test being deploying at the same time to Kubernetes, which isn't helping.. There should be a limiter to how many tests are ran at a time.

Copy link
Member Author

Choose a reason for hiding this comment

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

@cdrage I think I know what is confusing you, follow the following steps.

I get this when I run tests:

$ make test-e2e PARALLEL=2
go test -parallel=2 -v github.com/kedgeproject/kedge/tests/e2e
=== RUN   Test_Integration
=== RUN   Test_Integration/Testing_configMap
=== RUN   Test_Integration/Testing_customVol
=== RUN   Test_Integration/Testing_envFrom
=== RUN   Test_Integration/Testing_extraResources
=== RUN   Test_Integration/Testing_health
=== RUN   Test_Integration/Testing_healthChecks
=== RUN   Test_Integration/Testing_secret
=== RUN   Test_Integration/Testing_single_file
=== RUN   Test_Integration/Normal_Wordpress_test
...

Above output shows that all of them are running, but

In another window, while above is happening I could see:

$ kubectl get ns -w
NAME          STATUS    AGE
default       Active    14d
kube-public   Active    14d
kube-system   Active    14d
configmap   Active    0s
singlefile   Active    0s
configmap   Terminating   16s
wordpress   Active    0s
configmap   Terminating   38s
configmap   Terminating   38s
wordpress   Terminating   33s
health    Active    0s
...

In above output you can see, configmap and singlefile were created; then configmap was done and wordpress was started and so on. So at anytime only two tests at maximum are running.

Copy link
Member Author

Choose a reason for hiding this comment

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

Also from docs and help:

$ go test -h
test [build/test flags] [packages] [build/test flags & test binary flags]

In addition to the build flags, the flags handled by 'go test' itself are:

        -args

...


        -parallel n
            Allow parallel execution of test functions that call t.Parallel.
            The value of this flag is the maximum number of tests to run
            simultaneously; by default, it is set to the value of GOMAXPROCS.
            Note that -parallel only applies within a single test binary.
            The 'go test' command may run tests for different packages
            in parallel as well, according to the setting of the -p flag
            (see 'go help build').

...

@cdrage
Copy link
Collaborator

cdrage commented Aug 31, 2017

See my above comment, I don't think we should be running this much in parallel... Even on a beefy machine it slows everything down deploying at the same time. GOMAXPROCS does nothing (i've gone ahead and tested it).

@surajssd
Copy link
Member Author

surajssd commented Aug 31, 2017

@cdrage you can have all tests run serially by running make test-e2e PARALLEL=1. But it can take more time about 7mins.

@cdrage
Copy link
Collaborator

cdrage commented Aug 31, 2017

@surajssd Yup, that'd do it. PARALLEL works. Thanks! I'll do another test.

@cdrage
Copy link
Collaborator

cdrage commented Aug 31, 2017

AWESOME WORK! LGTM!! Works from my end especially with PARALLEL. Now let's get this up on Semaphore / Fabric8. I'll volunteer (since I've done the stuff on Semaphore previously).

@cdrage
Copy link
Collaborator

cdrage commented Aug 31, 2017

@surajssd Merge whenever!

@pradeepto
Copy link
Member

Great stuff @surajssd, @cdrage and everyone involved in getting this done. Much thanks

Run e2e tests using:

```
make test-e2e
```

The tests run in parallel so you might want to rate limit on number
of tests that run in parallel, you can do that by running following:

```
make test-e2e PARALLEL=2
```

Above will run only two tests in parallel.
@surajssd surajssd merged commit 93451ea into master Sep 1, 2017
@cdrage cdrage deleted the e2e_tests branch September 19, 2017 17:18
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants