2019-03-14 08:30:04 +00:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
2019-08-03 01:58:23 +00:00
|
|
|
"github.com/containous/traefik/v2/pkg/testhelpers"
|
2019-03-14 08:30:04 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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{
|
|
|
|
StatusCode: 200,
|
|
|
|
Body: ioutil.NopCloser(strings.NewReader("")),
|
|
|
|
}
|
|
|
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
req := testhelpers.MustNewRequest(http.MethodGet, "http://foo.bar/", nil)
|
|
|
|
|
|
|
|
pool := newBufferPool()
|
2019-09-30 16:12:04 +00:00
|
|
|
handler, _ := buildProxy(Bool(false), nil, &staticTransport{res}, pool, nil)
|
2019-03-14 08:30:04 +00:00
|
|
|
|
|
|
|
b.ReportAllocs()
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
handler.ServeHTTP(w, req)
|
|
|
|
}
|
|
|
|
}
|