Bump to go1.24
Co-authored-by: Romain <rtribotte@users.noreply.github.com>
This commit is contained in:
parent
5f35c88805
commit
cd16321dd9
88 changed files with 284 additions and 362 deletions
|
|
@ -57,7 +57,7 @@ func (p *mockProvider) Init() error {
|
|||
}
|
||||
|
||||
func TestNewConfigurationWatcher(t *testing.T) {
|
||||
routinesPool := safe.NewPool(context.Background())
|
||||
routinesPool := safe.NewPool(t.Context())
|
||||
t.Cleanup(routinesPool.Stop)
|
||||
|
||||
pvd := &mockProvider{
|
||||
|
|
@ -114,7 +114,7 @@ func TestNewConfigurationWatcher(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestWaitForRequiredProvider(t *testing.T) {
|
||||
routinesPool := safe.NewPool(context.Background())
|
||||
routinesPool := safe.NewPool(t.Context())
|
||||
|
||||
pvdAggregator := &mockProvider{
|
||||
wait: 5 * time.Millisecond,
|
||||
|
|
@ -162,7 +162,7 @@ func TestWaitForRequiredProvider(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestIgnoreTransientConfiguration(t *testing.T) {
|
||||
routinesPool := safe.NewPool(context.Background())
|
||||
routinesPool := safe.NewPool(t.Context())
|
||||
|
||||
config := &dynamic.Configuration{
|
||||
HTTP: th.BuildConfiguration(
|
||||
|
|
@ -298,7 +298,7 @@ func TestIgnoreTransientConfiguration(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestListenProvidersThrottleProviderConfigReload(t *testing.T) {
|
||||
routinesPool := safe.NewPool(context.Background())
|
||||
routinesPool := safe.NewPool(t.Context())
|
||||
|
||||
pvd := &mockProvider{
|
||||
wait: 10 * time.Millisecond,
|
||||
|
|
@ -343,7 +343,7 @@ func TestListenProvidersThrottleProviderConfigReload(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestListenProvidersSkipsEmptyConfigs(t *testing.T) {
|
||||
routinesPool := safe.NewPool(context.Background())
|
||||
routinesPool := safe.NewPool(t.Context())
|
||||
|
||||
pvd := &mockProvider{
|
||||
messages: []dynamic.Message{{ProviderName: "mock"}},
|
||||
|
|
@ -364,7 +364,7 @@ func TestListenProvidersSkipsEmptyConfigs(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestListenProvidersSkipsSameConfigurationForProvider(t *testing.T) {
|
||||
routinesPool := safe.NewPool(context.Background())
|
||||
routinesPool := safe.NewPool(t.Context())
|
||||
|
||||
message := dynamic.Message{
|
||||
ProviderName: "mock",
|
||||
|
|
@ -398,7 +398,7 @@ func TestListenProvidersSkipsSameConfigurationForProvider(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestListenProvidersDoesNotSkipFlappingConfiguration(t *testing.T) {
|
||||
routinesPool := safe.NewPool(context.Background())
|
||||
routinesPool := safe.NewPool(t.Context())
|
||||
|
||||
configuration := &dynamic.Configuration{
|
||||
HTTP: th.BuildConfiguration(
|
||||
|
|
@ -466,7 +466,7 @@ func TestListenProvidersDoesNotSkipFlappingConfiguration(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestListenProvidersIgnoreSameConfig(t *testing.T) {
|
||||
routinesPool := safe.NewPool(context.Background())
|
||||
routinesPool := safe.NewPool(t.Context())
|
||||
|
||||
configuration := &dynamic.Configuration{
|
||||
HTTP: th.BuildConfiguration(
|
||||
|
|
@ -557,7 +557,7 @@ func TestListenProvidersIgnoreSameConfig(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestApplyConfigUnderStress(t *testing.T) {
|
||||
routinesPool := safe.NewPool(context.Background())
|
||||
routinesPool := safe.NewPool(t.Context())
|
||||
|
||||
watcher := NewConfigurationWatcher(routinesPool, &mockProvider{}, []string{}, "")
|
||||
|
||||
|
|
@ -600,7 +600,7 @@ func TestApplyConfigUnderStress(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestListenProvidersIgnoreIntermediateConfigs(t *testing.T) {
|
||||
routinesPool := safe.NewPool(context.Background())
|
||||
routinesPool := safe.NewPool(t.Context())
|
||||
|
||||
configuration := &dynamic.Configuration{
|
||||
HTTP: th.BuildConfiguration(
|
||||
|
|
@ -691,7 +691,7 @@ func TestListenProvidersIgnoreIntermediateConfigs(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestListenProvidersPublishesConfigForEachProvider(t *testing.T) {
|
||||
routinesPool := safe.NewPool(context.Background())
|
||||
routinesPool := safe.NewPool(t.Context())
|
||||
|
||||
configuration := &dynamic.Configuration{
|
||||
HTTP: th.BuildConfiguration(
|
||||
|
|
@ -756,7 +756,7 @@ func TestListenProvidersPublishesConfigForEachProvider(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestPublishConfigUpdatedByProvider(t *testing.T) {
|
||||
routinesPool := safe.NewPool(context.Background())
|
||||
routinesPool := safe.NewPool(t.Context())
|
||||
|
||||
pvdConfiguration := dynamic.Configuration{
|
||||
TCP: &dynamic.TCPConfiguration{
|
||||
|
|
@ -802,7 +802,7 @@ func TestPublishConfigUpdatedByProvider(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestPublishConfigUpdatedByConfigWatcherListener(t *testing.T) {
|
||||
routinesPool := safe.NewPool(context.Background())
|
||||
routinesPool := safe.NewPool(t.Context())
|
||||
|
||||
pvd := &mockProvider{
|
||||
wait: 10 * time.Millisecond,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package middleware
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
|
|
@ -20,7 +19,7 @@ func TestBuilder_BuildChainNilConfig(t *testing.T) {
|
|||
}
|
||||
middlewaresBuilder := NewBuilder(testConfig, nil, nil)
|
||||
|
||||
chain := middlewaresBuilder.BuildChain(context.Background(), []string{"empty"})
|
||||
chain := middlewaresBuilder.BuildChain(t.Context(), []string{"empty"})
|
||||
_, err := chain.Then(nil)
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
|
@ -31,7 +30,7 @@ func TestBuilder_BuildChainNonExistentChain(t *testing.T) {
|
|||
}
|
||||
middlewaresBuilder := NewBuilder(testConfig, nil, nil)
|
||||
|
||||
chain := middlewaresBuilder.BuildChain(context.Background(), []string{"empty"})
|
||||
chain := middlewaresBuilder.BuildChain(t.Context(), []string{"empty"})
|
||||
_, err := chain.Then(nil)
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
|
@ -259,7 +258,7 @@ func TestBuilder_BuildChainWithContext(t *testing.T) {
|
|||
t.Run(test.desc, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
if len(test.contextProvider) > 0 {
|
||||
ctx = provider.AddInContext(ctx, "foobar@"+test.contextProvider)
|
||||
}
|
||||
|
|
@ -366,7 +365,7 @@ func TestBuilder_buildConstructor(t *testing.T) {
|
|||
t.Run(test.desc, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
constructor, err := middlewaresBuilder.buildConstructor(context.Background(), test.middlewareID)
|
||||
constructor, err := middlewaresBuilder.buildConstructor(t.Context(), test.middlewareID)
|
||||
require.NoError(t, err)
|
||||
|
||||
middleware, err2 := constructor(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {}))
|
||||
|
|
|
|||
|
|
@ -16,31 +16,31 @@ func TestAddInContext(t *testing.T) {
|
|||
}{
|
||||
{
|
||||
desc: "without provider information",
|
||||
ctx: context.Background(),
|
||||
ctx: t.Context(),
|
||||
name: "test",
|
||||
expected: "",
|
||||
},
|
||||
{
|
||||
desc: "provider name embedded in element name",
|
||||
ctx: context.Background(),
|
||||
ctx: t.Context(),
|
||||
name: "test@foo",
|
||||
expected: "foo",
|
||||
},
|
||||
{
|
||||
desc: "provider name in context",
|
||||
ctx: context.WithValue(context.Background(), key, "foo"),
|
||||
ctx: context.WithValue(t.Context(), key, "foo"),
|
||||
name: "test",
|
||||
expected: "foo",
|
||||
},
|
||||
{
|
||||
desc: "provider name in context and different provider name embedded in element name",
|
||||
ctx: context.WithValue(context.Background(), key, "foo"),
|
||||
ctx: context.WithValue(t.Context(), key, "foo"),
|
||||
name: "test@fii",
|
||||
expected: "fii",
|
||||
},
|
||||
{
|
||||
desc: "provider name in context and same provider name embedded in element name",
|
||||
ctx: context.WithValue(context.Background(), key, "foo"),
|
||||
ctx: context.WithValue(t.Context(), key, "foo"),
|
||||
name: "test@foo",
|
||||
expected: "foo",
|
||||
},
|
||||
|
|
@ -71,31 +71,31 @@ func TestGetQualifiedName(t *testing.T) {
|
|||
}{
|
||||
{
|
||||
desc: "empty name",
|
||||
ctx: context.Background(),
|
||||
ctx: t.Context(),
|
||||
name: "",
|
||||
expected: "",
|
||||
},
|
||||
{
|
||||
desc: "without provider",
|
||||
ctx: context.Background(),
|
||||
ctx: t.Context(),
|
||||
name: "test",
|
||||
expected: "test",
|
||||
},
|
||||
{
|
||||
desc: "with explicit provider",
|
||||
ctx: context.Background(),
|
||||
ctx: t.Context(),
|
||||
name: "test@foo",
|
||||
expected: "test@foo",
|
||||
},
|
||||
{
|
||||
desc: "with provider in context",
|
||||
ctx: context.WithValue(context.Background(), key, "foo"),
|
||||
ctx: context.WithValue(t.Context(), key, "foo"),
|
||||
name: "test",
|
||||
expected: "test@foo",
|
||||
},
|
||||
{
|
||||
desc: "with provider in context and explicit name",
|
||||
ctx: context.WithValue(context.Background(), key, "foo"),
|
||||
ctx: context.WithValue(t.Context(), key, "foo"),
|
||||
name: "test@fii",
|
||||
expected: "test@fii",
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package router
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"math"
|
||||
"net/http"
|
||||
|
|
@ -322,7 +321,7 @@ func TestRouterManager_Get(t *testing.T) {
|
|||
|
||||
routerManager := NewManager(rtConf, serviceManager, middlewaresBuilder, chainBuilder, metrics.NewVoidRegistry(), tlsManager)
|
||||
|
||||
handlers := routerManager.BuildHandlers(context.Background(), test.entryPoints, false)
|
||||
handlers := routerManager.BuildHandlers(t.Context(), test.entryPoints, false)
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
req := testhelpers.MustNewRequest(http.MethodGet, "http://foo.bar/", nil)
|
||||
|
|
@ -429,7 +428,7 @@ func TestAccessLog(t *testing.T) {
|
|||
|
||||
routerManager := NewManager(rtConf, serviceManager, middlewaresBuilder, chainBuilder, metrics.NewVoidRegistry(), tlsManager)
|
||||
|
||||
handlers := routerManager.BuildHandlers(context.Background(), test.entryPoints, false)
|
||||
handlers := routerManager.BuildHandlers(t.Context(), test.entryPoints, false)
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
req := testhelpers.MustNewRequest(http.MethodGet, "http://foo.bar/", nil)
|
||||
|
|
@ -813,12 +812,12 @@ func TestRuntimeConfiguration(t *testing.T) {
|
|||
middlewaresBuilder := middleware.NewBuilder(rtConf.Middlewares, serviceManager, nil)
|
||||
chainBuilder := middleware.NewChainBuilder(nil, nil, nil)
|
||||
tlsManager := tls.NewManager()
|
||||
tlsManager.UpdateConfigs(context.Background(), nil, test.tlsOptions, nil)
|
||||
tlsManager.UpdateConfigs(t.Context(), nil, test.tlsOptions, nil)
|
||||
|
||||
routerManager := NewManager(rtConf, serviceManager, middlewaresBuilder, chainBuilder, metrics.NewVoidRegistry(), tlsManager)
|
||||
|
||||
_ = routerManager.BuildHandlers(context.Background(), entryPoints, false)
|
||||
_ = routerManager.BuildHandlers(context.Background(), entryPoints, true)
|
||||
_ = routerManager.BuildHandlers(t.Context(), entryPoints, false)
|
||||
_ = routerManager.BuildHandlers(t.Context(), entryPoints, true)
|
||||
|
||||
// even though rtConf was passed by argument to the manager builders above,
|
||||
// it's ok to use it as the result we check, because everything worth checking
|
||||
|
|
@ -894,7 +893,7 @@ func TestProviderOnMiddlewares(t *testing.T) {
|
|||
|
||||
routerManager := NewManager(rtConf, serviceManager, middlewaresBuilder, chainBuilder, metrics.NewVoidRegistry(), tlsManager)
|
||||
|
||||
_ = routerManager.BuildHandlers(context.Background(), entryPoints, false)
|
||||
_ = routerManager.BuildHandlers(t.Context(), entryPoints, false)
|
||||
|
||||
assert.Equal(t, []string{"chain@file", "m1@file"}, rtConf.Routers["router@file"].Middlewares)
|
||||
assert.Equal(t, []string{"m1@file", "m2@file", "m1@file"}, rtConf.Middlewares["chain@file"].Chain.Middlewares)
|
||||
|
|
@ -963,7 +962,7 @@ func BenchmarkRouterServe(b *testing.B) {
|
|||
|
||||
routerManager := NewManager(rtConf, serviceManager, middlewaresBuilder, chainBuilder, metrics.NewVoidRegistry(), tlsManager)
|
||||
|
||||
handlers := routerManager.BuildHandlers(context.Background(), entryPoints, false)
|
||||
handlers := routerManager.BuildHandlers(b.Context(), entryPoints, false)
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
req := testhelpers.MustNewRequest(http.MethodGet, "http://foo.bar/", nil)
|
||||
|
|
@ -1003,7 +1002,7 @@ func BenchmarkService(b *testing.B) {
|
|||
w := httptest.NewRecorder()
|
||||
req := testhelpers.MustNewRequest(http.MethodGet, "http://foo.bar/", nil)
|
||||
|
||||
handler, _ := serviceManager.BuildHTTP(context.Background(), "foo-service")
|
||||
handler, _ := serviceManager.BuildHTTP(b.Context(), "foo-service")
|
||||
b.ReportAllocs()
|
||||
for range b.N {
|
||||
handler.ServeHTTP(w, req)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package tcp
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"math"
|
||||
"net/http"
|
||||
|
|
@ -347,7 +346,7 @@ func TestRuntimeConfiguration(t *testing.T) {
|
|||
serviceManager := tcp.NewManager(conf)
|
||||
tlsManager := traefiktls.NewManager()
|
||||
tlsManager.UpdateConfigs(
|
||||
context.Background(),
|
||||
t.Context(),
|
||||
map[string]traefiktls.Store{},
|
||||
map[string]traefiktls.Options{
|
||||
"default": {
|
||||
|
|
@ -367,7 +366,7 @@ func TestRuntimeConfiguration(t *testing.T) {
|
|||
routerManager := NewManager(conf, serviceManager, middlewaresBuilder,
|
||||
nil, nil, tlsManager)
|
||||
|
||||
_ = routerManager.BuildHandlers(context.Background(), entryPoints)
|
||||
_ = routerManager.BuildHandlers(t.Context(), entryPoints)
|
||||
|
||||
// even though conf was passed by argument to the manager builders above,
|
||||
// it's ok to use it as the result we check, because everything worth checking
|
||||
|
|
@ -658,7 +657,7 @@ func TestDomainFronting(t *testing.T) {
|
|||
serviceManager := tcp.NewManager(conf)
|
||||
|
||||
tlsManager := traefiktls.NewManager()
|
||||
tlsManager.UpdateConfigs(context.Background(), map[string]traefiktls.Store{}, test.tlsOptions, []*traefiktls.CertAndStores{})
|
||||
tlsManager.UpdateConfigs(t.Context(), map[string]traefiktls.Store{}, test.tlsOptions, []*traefiktls.CertAndStores{})
|
||||
|
||||
httpsHandler := map[string]http.Handler{
|
||||
"web": http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {}),
|
||||
|
|
@ -668,7 +667,7 @@ func TestDomainFronting(t *testing.T) {
|
|||
|
||||
routerManager := NewManager(conf, serviceManager, middlewaresBuilder, nil, httpsHandler, tlsManager)
|
||||
|
||||
routers := routerManager.BuildHandlers(context.Background(), entryPoints)
|
||||
routers := routerManager.BuildHandlers(t.Context(), entryPoints)
|
||||
|
||||
router, ok := routers["web"]
|
||||
require.True(t, ok)
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package tcp
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
|
@ -172,7 +171,7 @@ func Test_Routing(t *testing.T) {
|
|||
// Creates the tlsManager and defines the TLS 1.0 and 1.2 TLSOptions.
|
||||
tlsManager := traefiktls.NewManager()
|
||||
tlsManager.UpdateConfigs(
|
||||
context.Background(),
|
||||
t.Context(),
|
||||
map[string]traefiktls.Store{
|
||||
tlsalpn01.ACMETLS1Protocol: {},
|
||||
},
|
||||
|
|
@ -588,7 +587,7 @@ func Test_Routing(t *testing.T) {
|
|||
router(dynConf)
|
||||
}
|
||||
|
||||
router, err := manager.buildEntryPointHandler(context.Background(), dynConf.TCPRouters, dynConf.Routers, nil, nil)
|
||||
router, err := manager.buildEntryPointHandler(t.Context(), dynConf.TCPRouters, dynConf.Routers, nil, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
if test.allowACMETLSPassthrough {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package udp
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
|
@ -118,7 +117,7 @@ func TestRuntimeConfiguration(t *testing.T) {
|
|||
serviceManager := udp.NewManager(conf)
|
||||
routerManager := NewManager(conf, serviceManager)
|
||||
|
||||
_ = routerManager.BuildHandlers(context.Background(), entryPoints)
|
||||
_ = routerManager.BuildHandlers(t.Context(), entryPoints)
|
||||
|
||||
// even though conf was passed by argument to the manager builders above,
|
||||
// it's ok to use it as the result we check, because everything worth checking
|
||||
|
|
|
|||
|
|
@ -31,8 +31,6 @@ import (
|
|||
"github.com/traefik/traefik/v2/pkg/server/service"
|
||||
"github.com/traefik/traefik/v2/pkg/tcp"
|
||||
"github.com/traefik/traefik/v2/pkg/types"
|
||||
"golang.org/x/net/http2"
|
||||
"golang.org/x/net/http2/h2c"
|
||||
)
|
||||
|
||||
var httpServerLogger = stdlog.New(log.WithoutContext().WriterLevel(logrus.DebugLevel), "", 0)
|
||||
|
|
@ -577,11 +575,12 @@ func createHTTPServer(ctx context.Context, ln net.Listener, configuration *stati
|
|||
handler = newKeepAliveMiddleware(handler, configuration.Transport.KeepAliveMaxRequests, configuration.Transport.KeepAliveMaxTime)
|
||||
}
|
||||
|
||||
if withH2c {
|
||||
handler = h2c.NewHandler(handler, &http2.Server{
|
||||
MaxConcurrentStreams: uint32(configuration.HTTP2.MaxConcurrentStreams),
|
||||
})
|
||||
}
|
||||
var protocols http.Protocols
|
||||
protocols.SetHTTP1(true)
|
||||
protocols.SetHTTP2(true)
|
||||
|
||||
// With the addition of UnencryptedHTTP2 in http.Server#Protocols in go1.24 setting the h2c handler is not necessary anymore.
|
||||
protocols.SetUnencryptedHTTP2(withH2c)
|
||||
|
||||
if configuration.HTTP.EncodeQuerySemicolons {
|
||||
handler = encodeQuerySemicolons(handler)
|
||||
|
|
@ -602,11 +601,15 @@ func createHTTPServer(ctx context.Context, ln net.Listener, configuration *stati
|
|||
handler = denyFragment(handler)
|
||||
|
||||
serverHTTP := &http.Server{
|
||||
Protocols: &protocols,
|
||||
Handler: handler,
|
||||
ErrorLog: httpServerLogger,
|
||||
ReadTimeout: time.Duration(configuration.Transport.RespondingTimeouts.ReadTimeout),
|
||||
WriteTimeout: time.Duration(configuration.Transport.RespondingTimeouts.WriteTimeout),
|
||||
IdleTimeout: time.Duration(configuration.Transport.RespondingTimeouts.IdleTimeout),
|
||||
HTTP2: &http.HTTP2Config{
|
||||
MaxConcurrentStreams: int(configuration.HTTP2.MaxConcurrentStreams),
|
||||
},
|
||||
}
|
||||
if debugConnection || (configuration.Transport != nil && (configuration.Transport.KeepAliveMaxTime > 0 || configuration.Transport.KeepAliveMaxRequests > 0)) {
|
||||
serverHTTP.ConnContext = func(ctx context.Context, c net.Conn) context.Context {
|
||||
|
|
@ -640,19 +643,6 @@ func createHTTPServer(ctx context.Context, ln net.Listener, configuration *stati
|
|||
return ctx
|
||||
}
|
||||
|
||||
// ConfigureServer configures HTTP/2 with the MaxConcurrentStreams option for the given server.
|
||||
// Also keeping behavior the same as
|
||||
// https://cs.opensource.google/go/go/+/refs/tags/go1.17.7:src/net/http/server.go;l=3262
|
||||
if !strings.Contains(os.Getenv("GODEBUG"), "http2server=0") {
|
||||
err = http2.ConfigureServer(serverHTTP, &http2.Server{
|
||||
MaxConcurrentStreams: uint32(configuration.HTTP2.MaxConcurrentStreams),
|
||||
NewWriteScheduler: func() http2.WriteScheduler { return http2.NewPriorityWriteScheduler(nil) },
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("configure HTTP/2 server: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
listener := newHTTPForwarder(ln)
|
||||
go func() {
|
||||
err := serverHTTP.Serve(listener)
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package server
|
|||
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"net/http"
|
||||
|
|
@ -87,7 +86,7 @@ func TestHTTP3AdvertisedPort(t *testing.T) {
|
|||
epConfig := &static.EntryPointsTransport{}
|
||||
epConfig.SetDefaults()
|
||||
|
||||
entryPoint, err := NewTCPEntryPoint(context.Background(), &static.EntryPoint{
|
||||
entryPoint, err := NewTCPEntryPoint(t.Context(), &static.EntryPoint{
|
||||
Address: "127.0.0.1:0",
|
||||
Transport: epConfig,
|
||||
ForwardedHeaders: &static.ForwardedHeaders{},
|
||||
|
|
@ -108,7 +107,7 @@ func TestHTTP3AdvertisedPort(t *testing.T) {
|
|||
rw.WriteHeader(http.StatusOK)
|
||||
}), nil)
|
||||
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
go entryPoint.Start(ctx)
|
||||
entryPoint.SwitchRouter(router)
|
||||
|
||||
|
|
@ -151,7 +150,7 @@ func TestHTTP30RTT(t *testing.T) {
|
|||
epConfig := &static.EntryPointsTransport{}
|
||||
epConfig.SetDefaults()
|
||||
|
||||
entryPoint, err := NewTCPEntryPoint(context.Background(), &static.EntryPoint{
|
||||
entryPoint, err := NewTCPEntryPoint(t.Context(), &static.EntryPoint{
|
||||
Address: "127.0.0.1:8090",
|
||||
Transport: epConfig,
|
||||
ForwardedHeaders: &static.ForwardedHeaders{},
|
||||
|
|
@ -170,7 +169,7 @@ func TestHTTP30RTT(t *testing.T) {
|
|||
rw.WriteHeader(http.StatusOK)
|
||||
}), nil)
|
||||
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
go entryPoint.Start(ctx)
|
||||
entryPoint.SwitchRouter(router)
|
||||
|
||||
|
|
@ -193,7 +192,7 @@ func TestHTTP30RTT(t *testing.T) {
|
|||
tlsConf.ClientSessionCache = cache
|
||||
|
||||
// This first DialAddrEarly connection is here to populate the cache.
|
||||
earlyConnection, err := quic.DialAddrEarly(context.Background(), "127.0.0.1:8090", tlsConf, &quic.Config{})
|
||||
earlyConnection, err := quic.DialAddrEarly(t.Context(), "127.0.0.1:8090", tlsConf, &quic.Config{})
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Cleanup(func() {
|
||||
|
|
@ -207,7 +206,7 @@ func TestHTTP30RTT(t *testing.T) {
|
|||
// 0RTT is always false on the first connection.
|
||||
require.False(t, earlyConnection.ConnectionState().Used0RTT)
|
||||
|
||||
earlyConnection, err = quic.DialAddrEarly(context.Background(), "127.0.0.1:8090", tlsConf, &quic.Config{})
|
||||
earlyConnection, err = quic.DialAddrEarly(t.Context(), "127.0.0.1:8090", tlsConf, &quic.Config{})
|
||||
require.NoError(t, err)
|
||||
|
||||
<-earlyConnection.HandshakeComplete()
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ func testShutdown(t *testing.T, router *tcprouter.Router) {
|
|||
epConfig.RespondingTimeouts.ReadTimeout = ptypes.Duration(5 * time.Second)
|
||||
epConfig.RespondingTimeouts.WriteTimeout = ptypes.Duration(5 * time.Second)
|
||||
|
||||
entryPoint, err := NewTCPEntryPoint(context.Background(), &static.EntryPoint{
|
||||
entryPoint, err := NewTCPEntryPoint(t.Context(), &static.EntryPoint{
|
||||
// We explicitly use an IPV4 address because on Alpine, with an IPV6 address
|
||||
// there seems to be shenanigans related to properly cleaning up file descriptors
|
||||
Address: "127.0.0.1:0",
|
||||
|
|
@ -91,7 +91,7 @@ func testShutdown(t *testing.T, router *tcprouter.Router) {
|
|||
}, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
conn, err := startEntrypoint(entryPoint, router)
|
||||
conn, err := startEntrypoint(t, entryPoint, router)
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() { _ = conn.Close() })
|
||||
|
||||
|
|
@ -114,7 +114,7 @@ func testShutdown(t *testing.T, router *tcprouter.Router) {
|
|||
_, err = reader.Peek(1)
|
||||
require.NoError(t, err)
|
||||
|
||||
go entryPoint.Shutdown(context.Background())
|
||||
go entryPoint.Shutdown(t.Context())
|
||||
|
||||
// Make sure that new connections are not permitted anymore.
|
||||
// Note that this should be true not only after Shutdown has returned,
|
||||
|
|
@ -145,8 +145,10 @@ func testShutdown(t *testing.T, router *tcprouter.Router) {
|
|||
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
||||
}
|
||||
|
||||
func startEntrypoint(entryPoint *TCPEntryPoint, router *tcprouter.Router) (net.Conn, error) {
|
||||
go entryPoint.Start(context.Background())
|
||||
func startEntrypoint(t *testing.T, entryPoint *TCPEntryPoint, router *tcprouter.Router) (net.Conn, error) {
|
||||
t.Helper()
|
||||
|
||||
go entryPoint.Start(t.Context())
|
||||
|
||||
entryPoint.SwitchRouter(router)
|
||||
|
||||
|
|
@ -168,7 +170,7 @@ func TestReadTimeoutWithoutFirstByte(t *testing.T) {
|
|||
epConfig.SetDefaults()
|
||||
epConfig.RespondingTimeouts.ReadTimeout = ptypes.Duration(2 * time.Second)
|
||||
|
||||
entryPoint, err := NewTCPEntryPoint(context.Background(), &static.EntryPoint{
|
||||
entryPoint, err := NewTCPEntryPoint(t.Context(), &static.EntryPoint{
|
||||
Address: ":0",
|
||||
Transport: epConfig,
|
||||
ForwardedHeaders: &static.ForwardedHeaders{},
|
||||
|
|
@ -183,7 +185,7 @@ func TestReadTimeoutWithoutFirstByte(t *testing.T) {
|
|||
rw.WriteHeader(http.StatusOK)
|
||||
}))
|
||||
|
||||
conn, err := startEntrypoint(entryPoint, router)
|
||||
conn, err := startEntrypoint(t, entryPoint, router)
|
||||
require.NoError(t, err)
|
||||
|
||||
errChan := make(chan error)
|
||||
|
|
@ -207,7 +209,7 @@ func TestReadTimeoutWithFirstByte(t *testing.T) {
|
|||
epConfig.SetDefaults()
|
||||
epConfig.RespondingTimeouts.ReadTimeout = ptypes.Duration(2 * time.Second)
|
||||
|
||||
entryPoint, err := NewTCPEntryPoint(context.Background(), &static.EntryPoint{
|
||||
entryPoint, err := NewTCPEntryPoint(t.Context(), &static.EntryPoint{
|
||||
Address: ":0",
|
||||
Transport: epConfig,
|
||||
ForwardedHeaders: &static.ForwardedHeaders{},
|
||||
|
|
@ -222,7 +224,7 @@ func TestReadTimeoutWithFirstByte(t *testing.T) {
|
|||
rw.WriteHeader(http.StatusOK)
|
||||
}))
|
||||
|
||||
conn, err := startEntrypoint(entryPoint, router)
|
||||
conn, err := startEntrypoint(t, entryPoint, router)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = conn.Write([]byte("GET /some HTTP/1.1\r\n"))
|
||||
|
|
@ -249,7 +251,7 @@ func TestKeepAliveMaxRequests(t *testing.T) {
|
|||
epConfig.SetDefaults()
|
||||
epConfig.KeepAliveMaxRequests = 3
|
||||
|
||||
entryPoint, err := NewTCPEntryPoint(context.Background(), &static.EntryPoint{
|
||||
entryPoint, err := NewTCPEntryPoint(t.Context(), &static.EntryPoint{
|
||||
Address: ":0",
|
||||
Transport: epConfig,
|
||||
ForwardedHeaders: &static.ForwardedHeaders{},
|
||||
|
|
@ -264,7 +266,7 @@ func TestKeepAliveMaxRequests(t *testing.T) {
|
|||
rw.WriteHeader(http.StatusOK)
|
||||
}))
|
||||
|
||||
conn, err := startEntrypoint(entryPoint, router)
|
||||
conn, err := startEntrypoint(t, entryPoint, router)
|
||||
require.NoError(t, err)
|
||||
|
||||
http.DefaultClient.Transport = &http.Transport{
|
||||
|
|
@ -297,7 +299,7 @@ func TestKeepAliveMaxTime(t *testing.T) {
|
|||
epConfig.SetDefaults()
|
||||
epConfig.KeepAliveMaxTime = ptypes.Duration(time.Millisecond)
|
||||
|
||||
entryPoint, err := NewTCPEntryPoint(context.Background(), &static.EntryPoint{
|
||||
entryPoint, err := NewTCPEntryPoint(t.Context(), &static.EntryPoint{
|
||||
Address: ":0",
|
||||
Transport: epConfig,
|
||||
ForwardedHeaders: &static.ForwardedHeaders{},
|
||||
|
|
@ -312,7 +314,7 @@ func TestKeepAliveMaxTime(t *testing.T) {
|
|||
rw.WriteHeader(http.StatusOK)
|
||||
}))
|
||||
|
||||
conn, err := startEntrypoint(entryPoint, router)
|
||||
conn, err := startEntrypoint(t, entryPoint, router)
|
||||
require.NoError(t, err)
|
||||
|
||||
http.DefaultClient.Transport = &http.Transport{
|
||||
|
|
@ -341,7 +343,7 @@ func TestKeepAliveH2c(t *testing.T) {
|
|||
epConfig.SetDefaults()
|
||||
epConfig.KeepAliveMaxRequests = 1
|
||||
|
||||
entryPoint, err := NewTCPEntryPoint(context.Background(), &static.EntryPoint{
|
||||
entryPoint, err := NewTCPEntryPoint(t.Context(), &static.EntryPoint{
|
||||
Address: ":0",
|
||||
Transport: epConfig,
|
||||
ForwardedHeaders: &static.ForwardedHeaders{},
|
||||
|
|
@ -356,7 +358,7 @@ func TestKeepAliveH2c(t *testing.T) {
|
|||
rw.WriteHeader(http.StatusOK)
|
||||
}))
|
||||
|
||||
conn, err := startEntrypoint(entryPoint, router)
|
||||
conn, err := startEntrypoint(t, entryPoint, router)
|
||||
require.NoError(t, err)
|
||||
|
||||
http2Transport := &http2.Transport{
|
||||
|
|
@ -574,7 +576,7 @@ func TestPathOperations(t *testing.T) {
|
|||
configuration.SetDefaults()
|
||||
|
||||
// Create the HTTP server using createHTTPServer.
|
||||
server, err := createHTTPServer(context.Background(), ln, configuration, false, requestdecorator.New(nil))
|
||||
server, err := createHTTPServer(t.Context(), ln, configuration, false, requestdecorator.New(nil))
|
||||
require.NoError(t, err)
|
||||
|
||||
server.Switcher.UpdateHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net"
|
||||
"testing"
|
||||
|
|
@ -27,7 +26,7 @@ func TestShutdownUDPConn(t *testing.T) {
|
|||
entryPoint, err := NewUDPEntryPoint(&ep)
|
||||
require.NoError(t, err)
|
||||
|
||||
go entryPoint.Start(context.Background())
|
||||
go entryPoint.Start(t.Context())
|
||||
entryPoint.Switch(udp.HandlerFunc(func(conn *udp.Conn) {
|
||||
for {
|
||||
b := make([]byte, 1024*1024)
|
||||
|
|
@ -56,7 +55,7 @@ func TestShutdownUDPConn(t *testing.T) {
|
|||
|
||||
doneChan := make(chan struct{})
|
||||
go func() {
|
||||
entryPoint.Shutdown(context.Background())
|
||||
entryPoint.Shutdown(t.Context())
|
||||
close(doneChan)
|
||||
}()
|
||||
|
||||
|
|
|
|||
|
|
@ -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, 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)
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"net"
|
||||
|
|
@ -351,7 +350,7 @@ func TestKerberosRoundTripper(t *testing.T) {
|
|||
}),
|
||||
}
|
||||
|
||||
ctx := AddTransportOnContext(context.Background())
|
||||
ctx := AddTransportOnContext(t.Context())
|
||||
for _, expected := range test.expectedStatusCode {
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, "http://127.0.0.1", http.NoBody)
|
||||
require.NoError(t, err)
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ func TestGetLoadBalancer(t *testing.T) {
|
|||
t.Run(test.desc, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
handler, err := sm.getLoadBalancer(context.Background(), test.serviceName, test.service, test.fwd)
|
||||
handler, err := sm.getLoadBalancer(t.Context(), test.serviceName, test.service, test.fwd)
|
||||
if test.expectError {
|
||||
require.Error(t, err)
|
||||
assert.Nil(t, handler)
|
||||
|
|
@ -336,7 +336,7 @@ func TestGetLoadBalancerServiceHandler(t *testing.T) {
|
|||
|
||||
for _, test := range testCases {
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
handler, err := sm.getLoadBalancerServiceHandler(context.Background(), test.serviceName, test.service)
|
||||
handler, err := sm.getLoadBalancerServiceHandler(t.Context(), test.serviceName, test.service)
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, handler)
|
||||
|
|
@ -414,7 +414,7 @@ func Test1xxResponses(t *testing.T) {
|
|||
},
|
||||
},
|
||||
}
|
||||
handler, err := sm.getLoadBalancerServiceHandler(context.Background(), "foobar", config)
|
||||
handler, err := sm.getLoadBalancerServiceHandler(t.Context(), "foobar", config)
|
||||
assert.NoError(t, err)
|
||||
|
||||
frontend := httptest.NewServer(handler)
|
||||
|
|
@ -458,7 +458,7 @@ func Test1xxResponses(t *testing.T) {
|
|||
return nil
|
||||
},
|
||||
}
|
||||
req, _ := http.NewRequestWithContext(httptrace.WithClientTrace(context.Background(), trace), http.MethodGet, frontend.URL, nil)
|
||||
req, _ := http.NewRequestWithContext(httptrace.WithClientTrace(t.Context(), trace), http.MethodGet, frontend.URL, nil)
|
||||
|
||||
res, err := frontendClient.Do(req)
|
||||
assert.NoError(t, err)
|
||||
|
|
@ -506,15 +506,15 @@ func TestManager_ServiceBuilders(t *testing.T) {
|
|||
return nil, nil
|
||||
}))
|
||||
|
||||
h, err := manager.BuildHTTP(context.Background(), "test@internal")
|
||||
h, err := manager.BuildHTTP(t.Context(), "test@internal")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, internalHandler, h)
|
||||
|
||||
h, err = manager.BuildHTTP(context.Background(), "test@test")
|
||||
h, err = manager.BuildHTTP(t.Context(), "test@test")
|
||||
require.NoError(t, err)
|
||||
assert.NotNil(t, h)
|
||||
|
||||
_, err = manager.BuildHTTP(context.Background(), "wrong@test")
|
||||
_, err = manager.BuildHTTP(t.Context(), "wrong@test")
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
|
|
@ -571,7 +571,7 @@ func TestManager_Build(t *testing.T) {
|
|||
},
|
||||
})
|
||||
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
if len(test.providerName) > 0 {
|
||||
ctx = provider.AddInContext(ctx, "foobar@"+test.providerName)
|
||||
}
|
||||
|
|
@ -598,6 +598,6 @@ func TestMultipleTypeOnBuildHTTP(t *testing.T) {
|
|||
},
|
||||
})
|
||||
|
||||
_, err := manager.BuildHTTP(context.Background(), "test@file")
|
||||
_, err := manager.BuildHTTP(t.Context(), "test@file")
|
||||
assert.Error(t, err, "cannot create service: multi-types service not supported, consider declaring two different pieces of service instead")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package tcp
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
|
@ -181,7 +180,7 @@ func TestManager_BuildTCP(t *testing.T) {
|
|||
TCPServices: test.configs,
|
||||
})
|
||||
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
if len(test.providerName) > 0 {
|
||||
ctx = provider.AddInContext(ctx, "foobar@"+test.providerName)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package udp
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
|
@ -181,7 +180,7 @@ func TestManager_BuildUDP(t *testing.T) {
|
|||
UDPServices: test.configs,
|
||||
})
|
||||
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
if len(test.providerName) > 0 {
|
||||
ctx = provider.AddInContext(ctx, "foobar@"+test.providerName)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue