| 1 | package gateway |
| 2 | |
| 3 | import ( |
| 4 | "io" |
| 5 | "net/http" |
| 6 | "net/http/httptest" |
| 7 | "net/url" |
| 8 | "testing" |
| 9 | ) |
| 10 | |
| 11 | // BenchmarkProxy sends requests through a proxy to a service that answers |
| 12 | // with a small JSON body, like most of ours do. |
| 13 | func BenchmarkProxy(b *testing.B) { |
| 14 | svc := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 15 | w.Header().Set("Content-Type", "application/json") |
| 16 | io.WriteString(w, `{"id":"0b5c7a8e-4f5e-4d6c-9a62-2f7a1c3e9d10","state":"pending"}`) |
| 17 | })) |
| 18 | b.Cleanup(svc.Close) |
| 19 | target, _ := url.Parse(svc.URL) |
| 20 | proxy := newProxy(target) |
| 21 | for b.Loop() { |
| 22 | proxy.ServeHTTP(httptest.NewRecorder(), httptest.NewRequest("GET", "/v1/transfers/42", nil)) |
| 23 | } |
| 24 | } |