Cleanup e2e tests

This commit is contained in:
Manuel Alejandro de Brito Fontes 2020-07-30 23:59:09 -04:00
parent ff1718e57f
commit 3b31b9a0a8
2 changed files with 42 additions and 51 deletions

View file

@ -20,6 +20,7 @@ import (
"fmt" "fmt"
"strconv" "strconv"
"strings" "strings"
"sync"
"github.com/onsi/ginkgo" "github.com/onsi/ginkgo"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -43,73 +44,61 @@ var _ = framework.DescribeAnnotation("Annotation - limit-connections", func() {
return strings.Contains(server, fmt.Sprintf("server_name %s ;", host)) return strings.Contains(server, fmt.Sprintf("server_name %s ;", host))
}) })
// prerequisite
configKey := "variables-hash-bucket-size"
configValue := "256"
f.UpdateNginxConfigMapData(configKey, configValue)
f.WaitForNginxConfiguration(func(server string) bool {
return strings.Contains(server, fmt.Sprintf("variables_hash_bucket_size %s;", configValue))
})
// limit connections // limit connections
annotations := make(map[string]string)
connectionLimit := 8 connectionLimit := 8
annotations["nginx.ingress.kubernetes.io/limit-connections"] = strconv.Itoa(connectionLimit) annotations := map[string]string{
"nginx.ingress.kubernetes.io/limit-connections": strconv.Itoa(connectionLimit),
}
ing.SetAnnotations(annotations) ing.SetAnnotations(annotations)
f.UpdateIngress(ing) f.UpdateIngress(ing)
f.WaitForNginxConfiguration(func(server string) bool { f.WaitForNginxConfiguration(func(server string) bool {
return strings.Contains(server, "limit_conn") && strings.Contains(server, fmt.Sprintf("conn %v;", connectionLimit)) return strings.Contains(server, "limit_conn") && strings.Contains(server, fmt.Sprintf("conn %v;", connectionLimit))
}) })
type asyncResult struct { requests := 20
index int results := make(chan int, requests)
status int
}
response := make(chan *asyncResult) worker := func(wg *sync.WaitGroup) {
maxRequestNumber := 20 defer wg.Done()
for currentRequestNumber := 0; currentRequestNumber < maxRequestNumber; currentRequestNumber++ {
go func(requestNumber int, responeChannel chan *asyncResult) {
resp := f.HTTPTestClient().
GET("/sleep/10").
WithHeader("Host", host).
Expect().
Raw()
code := 0 resp := f.HTTPTestClient().
if resp != nil { GET("/sleep/10").
code = resp.StatusCode WithHeader("Host", host).
} Expect().
responeChannel <- &asyncResult{requestNumber, code} Raw()
}(currentRequestNumber, response)
} if resp != nil {
var results []asyncResult results <- resp.StatusCode
for {
res := <-response
results = append(results, *res)
if len(results) >= maxRequestNumber {
break
} }
} }
close(response) var wg sync.WaitGroup
for currentRequest := 0; currentRequest < requests; currentRequest++ {
wg.Add(1)
go worker(&wg)
}
okRequest := 0 wg.Wait()
failedRequest := 0
requestError := 0 ok := 0
expectedFail := maxRequestNumber - connectionLimit failed := 0
for _, result := range results { errors := 0
if result.status == 200 {
okRequest++ close(results)
} else if result.status == 503 { for status := range results {
failedRequest++ switch status {
} else { case 200:
requestError++ ok++
case 503:
failed++
default:
errors++
} }
} }
assert.Equal(ginkgo.GinkgoT(), okRequest, connectionLimit, "expecting the ok (200) requests number should equal the connection limit")
assert.Equal(ginkgo.GinkgoT(), failedRequest, expectedFail, "expecting the failed (503) requests number should equal the expected to fail request number") assert.Equal(ginkgo.GinkgoT(), connectionLimit, ok, "expecting the ok (200) requests to be equal to the connection limit")
assert.Equal(ginkgo.GinkgoT(), requestError, 0, "expecting the failed (other than 503) requests number should equal zero") assert.Equal(ginkgo.GinkgoT(), requests-connectionLimit, failed, "expecting the failed (503) requests to be the total requests - connection limit")
assert.Equal(ginkgo.GinkgoT(), 0, errors, "expecting failed (other than 503) requests to ber zero")
}) })
}) })

View file

@ -101,6 +101,8 @@ var _ = framework.IngressNginxDescribe("[Status] status update", func() {
_, cmd, err = f.KubectlProxy(port) _, cmd, err = f.KubectlProxy(port)
assert.Nil(ginkgo.GinkgoT(), err, "unexpected error starting kubectl proxy") assert.Nil(ginkgo.GinkgoT(), err, "unexpected error starting kubectl proxy")
defer func() { defer func() {
defer ginkgo.GinkgoRecover()
if cmd != nil { if cmd != nil {
err := cmd.Process.Kill() err := cmd.Process.Kill()
assert.Nil(ginkgo.GinkgoT(), err, "unexpected error terminating kubectl proxy") assert.Nil(ginkgo.GinkgoT(), err, "unexpected error terminating kubectl proxy")