Make the loadbalancers servers order random
Co-authored-by: Mathieu Lonjaret <mathieu.lonjaret@gmail.com> Co-authored-by: Romain <rtribotte@users.noreply.github.com>
This commit is contained in:
parent
89dc466b23
commit
788f8fa951
7 changed files with 177 additions and 46 deletions
|
@ -111,6 +111,7 @@ func TestGetLoadBalancerServiceHandler(t *testing.T) {
|
|||
type ExpectedResult struct {
|
||||
StatusCode int
|
||||
XFrom string
|
||||
LoadBalanced bool
|
||||
SecureCookie bool
|
||||
HTTPOnlyCookie bool
|
||||
}
|
||||
|
@ -139,12 +140,12 @@ func TestGetLoadBalancerServiceHandler(t *testing.T) {
|
|||
},
|
||||
expected: []ExpectedResult{
|
||||
{
|
||||
StatusCode: http.StatusOK,
|
||||
XFrom: "first",
|
||||
StatusCode: http.StatusOK,
|
||||
LoadBalanced: true,
|
||||
},
|
||||
{
|
||||
StatusCode: http.StatusOK,
|
||||
XFrom: "second",
|
||||
StatusCode: http.StatusOK,
|
||||
LoadBalanced: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -193,11 +194,9 @@ func TestGetLoadBalancerServiceHandler(t *testing.T) {
|
|||
expected: []ExpectedResult{
|
||||
{
|
||||
StatusCode: http.StatusOK,
|
||||
XFrom: "first",
|
||||
},
|
||||
{
|
||||
StatusCode: http.StatusOK,
|
||||
XFrom: "first",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -302,13 +301,27 @@ func TestGetLoadBalancerServiceHandler(t *testing.T) {
|
|||
req.Header.Set("Cookie", test.cookieRawValue)
|
||||
}
|
||||
|
||||
var prevXFrom string
|
||||
for _, expected := range test.expected {
|
||||
recorder := httptest.NewRecorder()
|
||||
|
||||
handler.ServeHTTP(recorder, req)
|
||||
|
||||
assert.Equal(t, expected.StatusCode, recorder.Code)
|
||||
assert.Equal(t, expected.XFrom, recorder.Header().Get("X-From"))
|
||||
|
||||
if expected.XFrom != "" {
|
||||
assert.Equal(t, expected.XFrom, recorder.Header().Get("X-From"))
|
||||
}
|
||||
|
||||
xFrom := recorder.Header().Get("X-From")
|
||||
if prevXFrom != "" {
|
||||
if expected.LoadBalanced {
|
||||
assert.NotEqual(t, prevXFrom, xFrom)
|
||||
} else {
|
||||
assert.Equal(t, prevXFrom, xFrom)
|
||||
}
|
||||
}
|
||||
prevXFrom = xFrom
|
||||
|
||||
cookieHeader := recorder.Header().Get("Set-Cookie")
|
||||
if len(cookieHeader) > 0 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue