traefik/pkg/server/service/proxy_test.go

38 lines
721 B
Go
Raw Normal View History

package service
import (
2021-03-04 19:08:03 +00:00
"io"
"net/http"
"net/http/httptest"
"strings"
"testing"
"github.com/traefik/traefik/v2/pkg/testhelpers"
)
type staticTransport struct {
res *http.Response
}
func (t *staticTransport) RoundTrip(r *http.Request) (*http.Response, error) {
return t.res, nil
}
func BenchmarkProxy(b *testing.B) {
res := &http.Response{
2022-08-09 15:36:08 +00:00
StatusCode: http.StatusOK,
2021-03-04 19:08:03 +00:00
Body: io.NopCloser(strings.NewReader("")),
}
w := httptest.NewRecorder()
req := testhelpers.MustNewRequest(http.MethodGet, "http://foo.bar/", nil)
pool := newBufferPool()
handler, _ := buildProxy(Bool(false), nil, &staticTransport{res}, pool)
b.ReportAllocs()
for i := 0; i < b.N; i++ {
handler.ServeHTTP(w, req)
}
}