Merge branch v2.11 into v3.4
This commit is contained in:
commit
bd4bfd8919
110 changed files with 493 additions and 494 deletions
|
|
@ -1,7 +1,6 @@
|
|||
package failover
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
|
@ -51,7 +50,7 @@ func TestFailover(t *testing.T) {
|
|||
assert.Equal(t, []int{200}, recorder.status)
|
||||
assert.True(t, status)
|
||||
|
||||
failover.SetHandlerStatus(context.Background(), false)
|
||||
failover.SetHandlerStatus(t.Context(), false)
|
||||
|
||||
recorder = &responseRecorder{ResponseRecorder: httptest.NewRecorder(), save: map[string]int{}}
|
||||
failover.ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, "/", nil))
|
||||
|
|
@ -61,7 +60,7 @@ func TestFailover(t *testing.T) {
|
|||
assert.Equal(t, []int{200}, recorder.status)
|
||||
assert.True(t, status)
|
||||
|
||||
failover.SetFallbackHandlerStatus(context.Background(), false)
|
||||
failover.SetFallbackHandlerStatus(t.Context(), false)
|
||||
|
||||
recorder = &responseRecorder{ResponseRecorder: httptest.NewRecorder(), save: map[string]int{}}
|
||||
failover.ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, "/", nil))
|
||||
|
|
@ -92,7 +91,7 @@ func TestFailoverDownThenUp(t *testing.T) {
|
|||
assert.Equal(t, 0, recorder.save["fallback"])
|
||||
assert.Equal(t, []int{200}, recorder.status)
|
||||
|
||||
failover.SetHandlerStatus(context.Background(), false)
|
||||
failover.SetHandlerStatus(t.Context(), false)
|
||||
|
||||
recorder = &responseRecorder{ResponseRecorder: httptest.NewRecorder(), save: map[string]int{}}
|
||||
failover.ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, "/", nil))
|
||||
|
|
@ -101,7 +100,7 @@ func TestFailoverDownThenUp(t *testing.T) {
|
|||
assert.Equal(t, 1, recorder.save["fallback"])
|
||||
assert.Equal(t, []int{200}, recorder.status)
|
||||
|
||||
failover.SetHandlerStatus(context.Background(), true)
|
||||
failover.SetHandlerStatus(t.Context(), true)
|
||||
|
||||
recorder = &responseRecorder{ResponseRecorder: httptest.NewRecorder(), save: map[string]int{}}
|
||||
failover.ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, "/", nil))
|
||||
|
|
@ -129,7 +128,7 @@ func TestFailoverPropagate(t *testing.T) {
|
|||
rw.WriteHeader(http.StatusOK)
|
||||
}))
|
||||
err := failover.RegisterStatusUpdater(func(up bool) {
|
||||
topFailover.SetHandlerStatus(context.Background(), up)
|
||||
topFailover.SetHandlerStatus(t.Context(), up)
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
|
|
@ -141,7 +140,7 @@ func TestFailoverPropagate(t *testing.T) {
|
|||
assert.Equal(t, 0, recorder.save["topFailover"])
|
||||
assert.Equal(t, []int{200}, recorder.status)
|
||||
|
||||
failover.SetHandlerStatus(context.Background(), false)
|
||||
failover.SetHandlerStatus(t.Context(), false)
|
||||
|
||||
recorder = &responseRecorder{ResponseRecorder: httptest.NewRecorder(), save: map[string]int{}}
|
||||
topFailover.ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, "/", nil))
|
||||
|
|
@ -151,7 +150,7 @@ func TestFailoverPropagate(t *testing.T) {
|
|||
assert.Equal(t, 0, recorder.save["topFailover"])
|
||||
assert.Equal(t, []int{200}, recorder.status)
|
||||
|
||||
failover.SetFallbackHandlerStatus(context.Background(), false)
|
||||
failover.SetFallbackHandlerStatus(t.Context(), false)
|
||||
|
||||
recorder = &responseRecorder{ResponseRecorder: httptest.NewRecorder(), save: map[string]int{}}
|
||||
topFailover.ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, "/", nil))
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package mirror
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
|
|
@ -20,7 +19,7 @@ func TestMirroringOn100(t *testing.T) {
|
|||
handler := http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
|
||||
rw.WriteHeader(http.StatusOK)
|
||||
})
|
||||
pool := safe.NewPool(context.Background())
|
||||
pool := safe.NewPool(t.Context())
|
||||
mirror := New(handler, pool, true, defaultMaxBodySize, nil)
|
||||
err := mirror.AddMirror(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
|
||||
atomic.AddInt32(&countMirror1, 1)
|
||||
|
|
@ -49,7 +48,7 @@ func TestMirroringOn10(t *testing.T) {
|
|||
handler := http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
|
||||
rw.WriteHeader(http.StatusOK)
|
||||
})
|
||||
pool := safe.NewPool(context.Background())
|
||||
pool := safe.NewPool(t.Context())
|
||||
mirror := New(handler, pool, true, defaultMaxBodySize, nil)
|
||||
err := mirror.AddMirror(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
|
||||
atomic.AddInt32(&countMirror1, 1)
|
||||
|
|
@ -74,7 +73,7 @@ func TestMirroringOn10(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestInvalidPercent(t *testing.T) {
|
||||
mirror := New(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {}), safe.NewPool(context.Background()), true, defaultMaxBodySize, nil)
|
||||
mirror := New(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {}), safe.NewPool(t.Context()), true, defaultMaxBodySize, nil)
|
||||
err := mirror.AddMirror(nil, -1)
|
||||
assert.Error(t, err)
|
||||
|
||||
|
|
@ -92,7 +91,7 @@ func TestHijack(t *testing.T) {
|
|||
handler := http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
|
||||
rw.WriteHeader(http.StatusOK)
|
||||
})
|
||||
pool := safe.NewPool(context.Background())
|
||||
pool := safe.NewPool(t.Context())
|
||||
mirror := New(handler, pool, true, defaultMaxBodySize, nil)
|
||||
|
||||
var mirrorRequest bool
|
||||
|
|
@ -116,7 +115,7 @@ func TestFlush(t *testing.T) {
|
|||
handler := http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
|
||||
rw.WriteHeader(http.StatusOK)
|
||||
})
|
||||
pool := safe.NewPool(context.Background())
|
||||
pool := safe.NewPool(t.Context())
|
||||
mirror := New(handler, pool, true, defaultMaxBodySize, nil)
|
||||
|
||||
var mirrorRequest bool
|
||||
|
|
@ -144,7 +143,7 @@ func TestMirroringWithBody(t *testing.T) {
|
|||
body = []byte(`body`)
|
||||
)
|
||||
|
||||
pool := safe.NewPool(context.Background())
|
||||
pool := safe.NewPool(t.Context())
|
||||
|
||||
handler := http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||
assert.NotNil(t, r.Body)
|
||||
|
|
@ -186,7 +185,7 @@ func TestMirroringWithIgnoredBody(t *testing.T) {
|
|||
emptyBody = []byte(``)
|
||||
)
|
||||
|
||||
pool := safe.NewPool(context.Background())
|
||||
pool := safe.NewPool(t.Context())
|
||||
|
||||
handler := http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||
assert.NotNil(t, r.Body)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package p2c
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strconv"
|
||||
|
|
@ -207,7 +206,7 @@ func TestBalancerPropagate(t *testing.T) {
|
|||
assert.Equal(t, http.StatusOK, recorder.Code)
|
||||
|
||||
// two gets downed, but balancer still up since first is still up.
|
||||
balancer.SetStatus(context.Background(), "second", false)
|
||||
balancer.SetStatus(t.Context(), "second", false)
|
||||
assert.Equal(t, 0, calls)
|
||||
|
||||
recorder = httptest.NewRecorder()
|
||||
|
|
@ -216,7 +215,7 @@ func TestBalancerPropagate(t *testing.T) {
|
|||
assert.Equal(t, "first", recorder.Header().Get("server"))
|
||||
|
||||
// first gets downed, balancer is down.
|
||||
balancer.SetStatus(context.Background(), "first", false)
|
||||
balancer.SetStatus(t.Context(), "first", false)
|
||||
assert.Equal(t, 1, calls)
|
||||
|
||||
recorder = httptest.NewRecorder()
|
||||
|
|
@ -224,7 +223,7 @@ func TestBalancerPropagate(t *testing.T) {
|
|||
assert.Equal(t, http.StatusServiceUnavailable, recorder.Code)
|
||||
|
||||
// two gets up, balancer up.
|
||||
balancer.SetStatus(context.Background(), "second", true)
|
||||
balancer.SetStatus(t.Context(), "second", true)
|
||||
assert.Equal(t, 2, calls)
|
||||
|
||||
recorder = httptest.NewRecorder()
|
||||
|
|
|
|||
|
|
@ -76,8 +76,8 @@ func TestBalancerNoServiceUp(t *testing.T) {
|
|||
rw.WriteHeader(http.StatusInternalServerError)
|
||||
}), pointer(1), false)
|
||||
|
||||
balancer.SetStatus(context.WithValue(context.Background(), serviceName, "parent"), "first", false)
|
||||
balancer.SetStatus(context.WithValue(context.Background(), serviceName, "parent"), "second", false)
|
||||
balancer.SetStatus(context.WithValue(t.Context(), serviceName, "parent"), "first", false)
|
||||
balancer.SetStatus(context.WithValue(t.Context(), serviceName, "parent"), "second", false)
|
||||
|
||||
recorder := httptest.NewRecorder()
|
||||
balancer.ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, "/", nil))
|
||||
|
|
@ -96,7 +96,7 @@ func TestBalancerOneServerDown(t *testing.T) {
|
|||
balancer.Add("second", http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
|
||||
rw.WriteHeader(http.StatusInternalServerError)
|
||||
}), pointer(1), false)
|
||||
balancer.SetStatus(context.WithValue(context.Background(), serviceName, "parent"), "second", false)
|
||||
balancer.SetStatus(context.WithValue(t.Context(), serviceName, "parent"), "second", false)
|
||||
|
||||
recorder := &responseRecorder{ResponseRecorder: httptest.NewRecorder(), save: map[string]int{}}
|
||||
for range 3 {
|
||||
|
|
@ -118,7 +118,7 @@ func TestBalancerDownThenUp(t *testing.T) {
|
|||
rw.Header().Set("server", "second")
|
||||
rw.WriteHeader(http.StatusOK)
|
||||
}), pointer(1), false)
|
||||
balancer.SetStatus(context.WithValue(context.Background(), serviceName, "parent"), "second", false)
|
||||
balancer.SetStatus(context.WithValue(t.Context(), serviceName, "parent"), "second", false)
|
||||
|
||||
recorder := &responseRecorder{ResponseRecorder: httptest.NewRecorder(), save: map[string]int{}}
|
||||
for range 3 {
|
||||
|
|
@ -126,7 +126,7 @@ func TestBalancerDownThenUp(t *testing.T) {
|
|||
}
|
||||
assert.Equal(t, 3, recorder.save["first"])
|
||||
|
||||
balancer.SetStatus(context.WithValue(context.Background(), serviceName, "parent"), "second", true)
|
||||
balancer.SetStatus(context.WithValue(t.Context(), serviceName, "parent"), "second", true)
|
||||
recorder = &responseRecorder{ResponseRecorder: httptest.NewRecorder(), save: map[string]int{}}
|
||||
for range 2 {
|
||||
balancer.ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, "/", nil))
|
||||
|
|
@ -160,13 +160,13 @@ func TestBalancerPropagate(t *testing.T) {
|
|||
topBalancer := New(nil, true)
|
||||
topBalancer.Add("balancer1", balancer1, pointer(1), false)
|
||||
_ = balancer1.RegisterStatusUpdater(func(up bool) {
|
||||
topBalancer.SetStatus(context.WithValue(context.Background(), serviceName, "top"), "balancer1", up)
|
||||
topBalancer.SetStatus(context.WithValue(t.Context(), serviceName, "top"), "balancer1", up)
|
||||
// TODO(mpl): if test gets flaky, add channel or something here to signal that
|
||||
// propagation is done, and wait on it before sending request.
|
||||
})
|
||||
topBalancer.Add("balancer2", balancer2, pointer(1), false)
|
||||
_ = balancer2.RegisterStatusUpdater(func(up bool) {
|
||||
topBalancer.SetStatus(context.WithValue(context.Background(), serviceName, "top"), "balancer2", up)
|
||||
topBalancer.SetStatus(context.WithValue(t.Context(), serviceName, "top"), "balancer2", up)
|
||||
})
|
||||
|
||||
recorder := &responseRecorder{ResponseRecorder: httptest.NewRecorder(), save: map[string]int{}}
|
||||
|
|
@ -181,7 +181,7 @@ func TestBalancerPropagate(t *testing.T) {
|
|||
assert.Equal(t, wantStatus, recorder.status)
|
||||
|
||||
// fourth gets downed, but balancer2 still up since third is still up.
|
||||
balancer2.SetStatus(context.WithValue(context.Background(), serviceName, "top"), "fourth", false)
|
||||
balancer2.SetStatus(context.WithValue(t.Context(), serviceName, "top"), "fourth", false)
|
||||
recorder = &responseRecorder{ResponseRecorder: httptest.NewRecorder(), save: map[string]int{}}
|
||||
for range 8 {
|
||||
topBalancer.ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, "/", nil))
|
||||
|
|
@ -195,7 +195,7 @@ func TestBalancerPropagate(t *testing.T) {
|
|||
|
||||
// third gets downed, and the propagation triggers balancer2 to be marked as
|
||||
// down as well for topBalancer.
|
||||
balancer2.SetStatus(context.WithValue(context.Background(), serviceName, "top"), "third", false)
|
||||
balancer2.SetStatus(context.WithValue(t.Context(), serviceName, "top"), "third", false)
|
||||
recorder = &responseRecorder{ResponseRecorder: httptest.NewRecorder(), save: map[string]int{}}
|
||||
for range 8 {
|
||||
topBalancer.ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, "/", nil))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue