2018-11-09 18:20:33 +00:00
|
|
|
/*
|
|
|
|
Copyright 2018 The Kubernetes Authors.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package settings
|
|
|
|
|
|
|
|
import (
|
|
|
|
"regexp"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/parnurzeal/gorequest"
|
|
|
|
|
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
. "github.com/onsi/gomega"
|
|
|
|
|
|
|
|
"k8s.io/ingress-nginx/test/e2e/framework"
|
|
|
|
)
|
|
|
|
|
2018-11-12 15:19:52 +00:00
|
|
|
var _ = framework.IngressNginxDescribe("Load Balance - Round Robin", func() {
|
|
|
|
f := framework.NewDefaultFramework("round-robin")
|
2018-11-09 18:20:33 +00:00
|
|
|
|
|
|
|
BeforeEach(func() {
|
|
|
|
f.NewEchoDeploymentWithReplicas(3)
|
2018-11-12 15:19:52 +00:00
|
|
|
f.UpdateNginxConfigMapData("worker-processes", "1")
|
2018-11-09 18:20:33 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
AfterEach(func() {
|
2018-11-12 15:19:52 +00:00
|
|
|
f.UpdateNginxConfigMapData("worker-processes", "")
|
2018-11-09 18:20:33 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
It("should evenly distribute requests with round-robin (default algorithm)", func() {
|
|
|
|
host := "load-balance.com"
|
|
|
|
|
2019-02-22 14:03:42 +00:00
|
|
|
f.EnsureIngress(framework.NewSingleIngress(host, "/", host, f.Namespace, "http-svc", 80, nil))
|
2018-11-09 18:20:33 +00:00
|
|
|
f.WaitForNginxServer(host,
|
|
|
|
func(server string) bool {
|
|
|
|
return strings.Contains(server, "server_name load-balance.com")
|
|
|
|
})
|
|
|
|
|
|
|
|
re, _ := regexp.Compile(`http-svc.*`)
|
|
|
|
replicaRequestCount := map[string]int{}
|
|
|
|
|
|
|
|
for i := 0; i < 600; i++ {
|
|
|
|
_, body, errs := gorequest.New().
|
2019-02-22 14:03:42 +00:00
|
|
|
Get(f.GetURL(framework.HTTP)).
|
2018-11-09 18:20:33 +00:00
|
|
|
Set("Host", host).
|
|
|
|
End()
|
2018-11-12 15:19:52 +00:00
|
|
|
Expect(errs).Should(BeEmpty())
|
2018-11-09 18:20:33 +00:00
|
|
|
|
|
|
|
replica := re.FindString(body)
|
|
|
|
Expect(replica).ShouldNot(Equal(""))
|
|
|
|
|
|
|
|
if _, ok := replicaRequestCount[replica]; !ok {
|
|
|
|
replicaRequestCount[replica] = 1
|
|
|
|
} else {
|
|
|
|
replicaRequestCount[replica]++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range replicaRequestCount {
|
2018-11-12 15:19:52 +00:00
|
|
|
Expect(v).Should(Equal(200))
|
2018-11-09 18:20:33 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|