Fix 50% split between canary and mainline tests (#8315)
* fix 50% canary test * fix past tense * after code review * revert go.sum and go.mod * run gofmt
This commit is contained in:
parent
01b92b8b3a
commit
ba7f295538
1 changed files with 13 additions and 10 deletions
|
@ -18,7 +18,6 @@ package annotations
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"reflect"
|
"reflect"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
@ -806,7 +805,7 @@ var _ = framework.DescribeAnnotation("canary-*", func() {
|
||||||
Contains(canaryService)
|
Contains(canaryService)
|
||||||
})
|
})
|
||||||
|
|
||||||
ginkgo.It("should route requests evenly split between mainline and canary if canary weight is 50", func() {
|
ginkgo.It("should route requests split between mainline and canary if canary weight is 50", func() {
|
||||||
host := "foo"
|
host := "foo"
|
||||||
annotations := map[string]string{}
|
annotations := map[string]string{}
|
||||||
|
|
||||||
|
@ -829,7 +828,7 @@ var _ = framework.DescribeAnnotation("canary-*", func() {
|
||||||
f.Namespace, canaryService, 80, canaryAnnotations)
|
f.Namespace, canaryService, 80, canaryAnnotations)
|
||||||
f.EnsureIngress(canaryIng)
|
f.EnsureIngress(canaryIng)
|
||||||
|
|
||||||
TestEvenMainlineCanaryDistribution(f, host)
|
TestMainlineCanaryDistribution(f, host)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -1079,18 +1078,24 @@ var _ = framework.DescribeAnnotation("canary-*", func() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TestEvenMainlineCanaryDistribution(f, host)
|
TestMainlineCanaryDistribution(f, host)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// This method assumes canary weight being configured at 50%.
|
// This method assumes canary weight being configured at 50%.
|
||||||
func TestEvenMainlineCanaryDistribution(f *framework.Framework, host string) {
|
func TestMainlineCanaryDistribution(f *framework.Framework, host string) {
|
||||||
re := regexp.MustCompile(fmt.Sprintf(`%s.*`, framework.EchoService))
|
re := regexp.MustCompile(fmt.Sprintf(`%s.*`, framework.EchoService))
|
||||||
replicaRequestCount := map[string]int{}
|
replicaRequestCount := map[string]int{}
|
||||||
|
|
||||||
for i := 0; i < 200; i++ {
|
// The implementation of choice by weight doesn't guarantee exact
|
||||||
|
// number of requests, so verify if mainline and canary have at
|
||||||
|
// least some requests
|
||||||
|
requestsToGet := 200
|
||||||
|
requestsNumberToTest := (40 * requestsToGet) / 100
|
||||||
|
|
||||||
|
for i := 0; i < requestsToGet; i++ {
|
||||||
body := f.HTTPTestClient().
|
body := f.HTTPTestClient().
|
||||||
GET("/").
|
GET("/").
|
||||||
WithHeader("Host", host).
|
WithHeader("Host", host).
|
||||||
|
@ -1111,8 +1116,6 @@ func TestEvenMainlineCanaryDistribution(f *framework.Framework, host string) {
|
||||||
|
|
||||||
assert.Equal(ginkgo.GinkgoT(), 2, len(keys))
|
assert.Equal(ginkgo.GinkgoT(), 2, len(keys))
|
||||||
|
|
||||||
// The implmentation of choice by weight doesn't guarantee exact
|
assert.GreaterOrEqual(ginkgo.GinkgoT(), int(replicaRequestCount[keys[0].String()]), requestsNumberToTest)
|
||||||
// number of requests, so verify if request imbalance is within an
|
assert.GreaterOrEqual(ginkgo.GinkgoT(), int(replicaRequestCount[keys[1].String()]), requestsNumberToTest)
|
||||||
// acceptable range.
|
|
||||||
assert.LessOrEqual(ginkgo.GinkgoT(), math.Abs(float64(replicaRequestCount[keys[0].String()]-replicaRequestCount[keys[1].String()]))/math.Max(float64(replicaRequestCount[keys[0].String()]), float64(replicaRequestCount[keys[1].String()])), 0.2)
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue