(t *testing.T)
| 307 | } |
| 308 | |
| 309 | func TestHandlerMaxRequestsInFlight(t *testing.T) { |
| 310 | reg := prometheus.NewRegistry() |
| 311 | handler := HandlerFor(reg, HandlerOpts{MaxRequestsInFlight: 1}) |
| 312 | w1 := httptest.NewRecorder() |
| 313 | w2 := httptest.NewRecorder() |
| 314 | w3 := httptest.NewRecorder() |
| 315 | request, _ := http.NewRequest(http.MethodGet, "/", nil) |
| 316 | request.Header.Add(acceptHeader, acceptTextPlain) |
| 317 | |
| 318 | c := blockingCollector{Block: make(chan struct{}), CollectStarted: make(chan struct{}, 1)} |
| 319 | reg.MustRegister(c) |
| 320 | |
| 321 | rq1Done := make(chan struct{}) |
| 322 | go func() { |
| 323 | handler.ServeHTTP(w1, request) |
| 324 | close(rq1Done) |
| 325 | }() |
| 326 | <-c.CollectStarted |
| 327 | |
| 328 | handler.ServeHTTP(w2, request) |
| 329 | |
| 330 | if got, want := w2.Code, http.StatusServiceUnavailable; got != want { |
| 331 | t.Errorf("got HTTP status code %d, want %d", got, want) |
| 332 | } |
| 333 | if got, want := w2.Body.String(), "Limit of concurrent requests reached (1), try again later.\n"; got != want { |
| 334 | t.Errorf("got body %q, want %q", got, want) |
| 335 | } |
| 336 | |
| 337 | close(c.Block) |
| 338 | <-rq1Done |
| 339 | |
| 340 | handler.ServeHTTP(w3, request) |
| 341 | |
| 342 | if got, want := w3.Code, http.StatusOK; got != want { |
| 343 | t.Errorf("got HTTP status code %d, want %d", got, want) |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | func TestHandlerTimeout(t *testing.T) { |
| 348 | reg := prometheus.NewRegistry() |
nothing calls this directly
no test coverage detected