1
0
Fork 0

Bump to go1.24

Co-authored-by: Romain <rtribotte@users.noreply.github.com>
This commit is contained in:
Kevin Pollet 2025-06-02 10:36:05 +02:00 committed by GitHub
parent 5f35c88805
commit cd16321dd9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
88 changed files with 284 additions and 362 deletions

View file

@ -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))

View file

@ -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, 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, 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()), defaultMaxBodySize, nil)
mirror := New(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {}), safe.NewPool(t.Context()), 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, 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, 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)

View file

@ -90,8 +90,8 @@ func TestBalancerNoServiceUp(t *testing.T) {
rw.WriteHeader(http.StatusInternalServerError)
}), pointer(1))
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))
@ -110,7 +110,7 @@ func TestBalancerOneServerDown(t *testing.T) {
balancer.AddService("second", http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
rw.WriteHeader(http.StatusInternalServerError)
}), pointer(1))
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 {
@ -132,7 +132,7 @@ func TestBalancerDownThenUp(t *testing.T) {
rw.Header().Set("server", "second")
rw.WriteHeader(http.StatusOK)
}), pointer(1))
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 {
@ -140,7 +140,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))
@ -174,13 +174,13 @@ func TestBalancerPropagate(t *testing.T) {
topBalancer := New(nil, &dynamic.HealthCheck{})
topBalancer.AddService("balancer1", balancer1, pointer(1))
_ = 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.AddService("balancer2", balancer2, pointer(1))
_ = 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{}}
@ -195,7 +195,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))
@ -209,7 +209,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))