MCPcopy
hub / github.com/cortexlabs/cortex / TestProxyHandlerQueueFull

Function TestProxyHandlerQueueFull

pkg/proxy/handler_test.go:37–77  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

35)
36
37func 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
79func TestProxyHandlerBreakerTimeout(t *testing.T) {
80 // This test sends a request which will take a long time to complete.

Callers

nothing calls this directly

Calls 4

NewBreakerFunction · 0.92
HandlerFunction · 0.92
EqualMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected