(t *testing.T)
| 35 | ) |
| 36 | |
| 37 | func TestProxyHandlerQueueFull(t *testing.T) { |
| 38 | // This test sends three requests of which one should fail immediately as the queue |
| 39 | // saturates. |
| 40 | resp := make(chan struct{}) |
| 41 | blockHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 42 | <-resp |
| 43 | }) |
| 44 | |
| 45 | breaker := proxy.NewBreaker( |
| 46 | proxy.BreakerParams{ |
| 47 | QueueDepth: 1, |
| 48 | MaxConcurrency: 1, |
| 49 | InitialCapacity: 1, |
| 50 | }, |
| 51 | ) |
| 52 | |
| 53 | h := proxy.Handler(breaker, blockHandler) |
| 54 | |
| 55 | req := httptest.NewRequest(http.MethodGet, userContainerHost, nil) |
| 56 | resps := make(chan *httptest.ResponseRecorder) |
| 57 | for i := 0; i < 3; i++ { |
| 58 | go func() { |
| 59 | rec := httptest.NewRecorder() |
| 60 | h(rec, req) |
| 61 | resps <- rec |
| 62 | }() |
| 63 | } |
| 64 | |
| 65 | // One of the three requests fails and it should be the first we see since the others |
| 66 | // are still held by the resp channel. |
| 67 | failure := <-resps |
| 68 | require.Equal(t, http.StatusServiceUnavailable, failure.Code) |
| 69 | require.True(t, strings.Contains(failure.Body.String(), "pending request queue full")) |
| 70 | |
| 71 | // Allow the remaining requests to pass. |
| 72 | close(resp) |
| 73 | for i := 0; i < 2; i++ { |
| 74 | res := <-resps |
| 75 | require.Equal(t, http.StatusOK, res.Code) |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | func TestProxyHandlerBreakerTimeout(t *testing.T) { |
| 80 | // This test sends a request which will take a long time to complete. |
nothing calls this directly
no test coverage detected