From b6470497e73dc7c7b367c25906ba05b8e17f5b03 Mon Sep 17 00:00:00 2001 From: Srinivas Hegde Date: Tue, 24 Jul 2018 14:40:19 -0700 Subject: [PATCH] Run the e2e tests in parallel --- test/README.md | 17 +++++++++-------- test/e2e-tests.sh | 6 +++++- test/e2e/autoscale_test.go | 2 +- test/e2e/build_test.go | 4 ++-- test/e2e/e2e.go | 9 +++++++-- test/e2e/errorcondition_test.go | 2 +- test/e2e/helloworld_test.go | 2 +- 7 files changed, 26 insertions(+), 16 deletions(-) diff --git a/test/README.md b/test/README.md index 7c95b6ca9890..d2765f9096cf 100644 --- a/test/README.md +++ b/test/README.md @@ -45,7 +45,7 @@ To run [the e2e tests](./e2e) and [the conformance tests](./conformance), you ne ```bash go test -v -tags=e2e -count=1 ./test/conformance -go test -v -tags=e2e -count=1 ./test/e2e +go test -v -tags=e2e -count=1 -parallel=4 ./test/e2e ``` ### One test case @@ -76,13 +76,14 @@ These tests require: enabled is recommended (`-v`). * Using [`--logverbose`](#output-verbose-log) to see the verbose log output from test as well as from k8s libraries. * Using `-count=1` is [the idiomatic way to disable test caching](https://golang.org/doc/go1.10#test) +* Using `-parallel=4` to run upto 4 [parallel test functions](https://golang.org/pkg/testing/#T.Parallel) from the test package in [parallel](https://golang.org/cmd/go/#hdr-Testing_flags) You can [use test flags](#flags) to control the environment your tests run against, i.e. override [your environment variables](/DEVELOPMENT.md#environment-setup): ```bash go test -v -tags=e2e -count=1 ./test/conformance --kubeconfig ~/special/kubeconfig --cluster myspecialcluster --dockerrepo myspecialdockerrepo -go test -v -tags=e2e -count=1 ./test/e2e --kubeconfig ~/special/kubeconfig --cluster myspecialcluster --dockerrepo myspecialdockerrepo +go test -v -tags=e2e -count=1 -parallel=4 ./test/e2e --kubeconfig ~/special/kubeconfig --cluster myspecialcluster --dockerrepo myspecialdockerrepo ``` If you are running against an environment with no loadbalancer for the ingress, at the moment @@ -91,7 +92,7 @@ your only option is to use a domain which will resolve to the IP of the running ```bash go test -v -tags=e2e -count=1 ./test/conformance --resolvabledomain -go test -v -tags=e2e -count=1 ./test/e2e --resolvabledomain +go test -v -tags=e2e -count=1 -parallel=4 ./test/e2e --resolvabledomain ``` ## Test images @@ -147,7 +148,7 @@ To run the tests with a non-default kubeconfig file: ```bash go test -v -tags=e2e -count=1 ./test/conformance --kubeconfig /my/path/kubeconfig -go test -v -tags=e2e -count=1 ./test/e2e --kubeconfig /my/path/kubeconfig +go test -v -tags=e2e -count=1 -parallel=4 ./test/e2e --kubeconfig /my/path/kubeconfig ``` ### Specifying cluster @@ -159,7 +160,7 @@ if not specified. ```bash go test -v -tags=e2e -count=1 ./test/conformance --cluster your-cluster-name -go test -v -tags=e2e -count=1 ./test/e2e --cluster your-cluster-name +go test -v -tags=e2e -count=1 -parallel=4 ./test/e2e --cluster your-cluster-name ``` The current cluster names can be obtained by running: @@ -175,7 +176,7 @@ tests. By default, `conformance` will use `noodleburg` and `e2e` will use `pizza ```bash go test -v -tags=e2e -count=1 ./test/conformance --namespace your-namespace-name -go test -v -tags=e2e -count=1 ./test/e2e --namespace your-namespace-name +go test -v -tags=e2e -parallel=4 -count=1 ./test/e2e --namespace your-namespace-name ``` ### Overridding docker repo @@ -187,7 +188,7 @@ if not specified. ```bash go test -v -tags=e2e -count=1 ./test/conformance --dockerrepo gcr.myhappyproject -go test -v -tags=e2e -count=1 ./test/e2e --dockerrepo gcr.myhappyproject +go test -v -tags=e2e -count=1 -parallel=4 ./test/e2e --dockerrepo gcr.myhappyproject ``` ### Using a resolvable domain @@ -210,7 +211,7 @@ If you have configured your cluster to use a resolvable domain, you can use the The `--logverbose` argument lets you see verbose test logs and k8s logs. ```bash -go test -v -tags=e2e -count=1 ./test/e2e --logverbose +go test -v -tags=e2e -count=1 -parallel=4 ./test/e2e --logverbose ``` ### Emit metrics diff --git a/test/e2e-tests.sh b/test/e2e-tests.sh index 8f3a7acad583..8390755795cc 100755 --- a/test/e2e-tests.sh +++ b/test/e2e-tests.sh @@ -106,7 +106,11 @@ function run_e2e_tests() { kubectl label namespace $2 istio-injection=enabled --overwrite local options="" (( EMIT_METRICS )) && options="-emitmetrics" - report_go_test -v -tags=e2e -count=1 ./test/$1 -dockerrepo gcr.io/knative-tests/test-images/$1 ${options} + if [ "$1" = "e2e" ]; then + report_go_test -v -tags=e2e -count=1 -parallel=4 ./test/$1 -dockerrepo gcr.io/knative-tests/test-images/$1 ${options} + else + report_go_test -v -tags=e2e -count=1 ./test/$1 -dockerrepo gcr.io/knative-tests/test-images/$1 ${options} + fi; local result=$? [[ ${result} -ne 0 ]] && dump_cluster_state diff --git a/test/e2e/autoscale_test.go b/test/e2e/autoscale_test.go index 3b690e4788d0..4484ee80a0ec 100644 --- a/test/e2e/autoscale_test.go +++ b/test/e2e/autoscale_test.go @@ -86,7 +86,7 @@ func setScaleToZeroThreshold(clients *test.Clients, threshold string) error { } func setup(t *testing.T, logger *zap.SugaredLogger) *test.Clients { - clients := Setup(t) + clients := Setup(t, false) configMap, err := getAutoscalerConfigMap(clients) if err != nil { diff --git a/test/e2e/build_test.go b/test/e2e/build_test.go index 3b0a255dd2c9..c6cbcd63a702 100644 --- a/test/e2e/build_test.go +++ b/test/e2e/build_test.go @@ -29,7 +29,7 @@ import ( ) func TestBuildAndServe(t *testing.T) { - clients := Setup(t) + clients := Setup(t, true) // Add test case specific name to its own logger. logger := test.GetContextLogger("TestBuildAndServe") @@ -99,7 +99,7 @@ func TestBuildAndServe(t *testing.T) { } func TestBuildFailure(t *testing.T) { - clients := Setup(t) + clients := Setup(t, true) // Add test case specific name to its own logger. logger := test.GetContextLogger("TestBuildFailure") diff --git a/test/e2e/e2e.go b/test/e2e/e2e.go index d7fd7eb9ef7b..c1d20703f8c1 100644 --- a/test/e2e/e2e.go +++ b/test/e2e/e2e.go @@ -20,12 +20,17 @@ const ( defaultNamespaceName = "noodleburg" ) -// Setup creates the client objects needed in the e2e tests. -func Setup(t *testing.T) *test.Clients { +// Setup creates the client objects needed in the e2e tests. If parallel is true, +// the test will be marked so as to run in parallel with other parallel tests. +func Setup(t *testing.T, parallel bool) *test.Clients { if test.Flags.Namespace == "" { test.Flags.Namespace = defaultNamespaceName } + if parallel { + t.Parallel() + } + clients, err := test.NewClients( test.Flags.Kubeconfig, test.Flags.Cluster, diff --git a/test/e2e/errorcondition_test.go b/test/e2e/errorcondition_test.go index c89a0cfa861d..df27f1c6e495 100644 --- a/test/e2e/errorcondition_test.go +++ b/test/e2e/errorcondition_test.go @@ -41,7 +41,7 @@ const ( func TestContainerErrorMsg(t *testing.T) { //t.Skip("Skipping until https://github.com/knative/serving/issues/1240 is closed") - clients := Setup(t) + clients := Setup(t, true) //add test case specific name to its own logger logger := test.GetContextLogger("TestContainerErrorMsg") diff --git a/test/e2e/helloworld_test.go b/test/e2e/helloworld_test.go index 6e3b27f6424a..4b80e6480739 100644 --- a/test/e2e/helloworld_test.go +++ b/test/e2e/helloworld_test.go @@ -31,7 +31,7 @@ const ( ) func TestHelloWorld(t *testing.T) { - clients := Setup(t) + clients := Setup(t, true) //add test case specific name to its own logger logger := test.GetContextLogger("TestHelloWorld")