Cleanup e2e tests
This commit is contained in:
parent
ff1718e57f
commit
3b31b9a0a8
2 changed files with 42 additions and 51 deletions
|
@ -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
|
|
||||||
}
|
worker := func(wg *sync.WaitGroup) {
|
||||||
|
defer wg.Done()
|
||||||
|
|
||||||
response := make(chan *asyncResult)
|
|
||||||
maxRequestNumber := 20
|
|
||||||
for currentRequestNumber := 0; currentRequestNumber < maxRequestNumber; currentRequestNumber++ {
|
|
||||||
go func(requestNumber int, responeChannel chan *asyncResult) {
|
|
||||||
resp := f.HTTPTestClient().
|
resp := f.HTTPTestClient().
|
||||||
GET("/sleep/10").
|
GET("/sleep/10").
|
||||||
WithHeader("Host", host).
|
WithHeader("Host", host).
|
||||||
Expect().
|
Expect().
|
||||||
Raw()
|
Raw()
|
||||||
|
|
||||||
code := 0
|
|
||||||
if resp != nil {
|
if resp != nil {
|
||||||
code = resp.StatusCode
|
results <- resp.StatusCode
|
||||||
}
|
|
||||||
responeChannel <- &asyncResult{requestNumber, code}
|
|
||||||
}(currentRequestNumber, response)
|
|
||||||
|
|
||||||
}
|
|
||||||
var results []asyncResult
|
|
||||||
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")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -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")
|
||||||
|
|
Loading…
Reference in a new issue