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

Function TestBreakerCancel

pkg/proxy/breaker_test.go:193–230  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

191}
192
193func TestBreakerCancel(t *testing.T) {
194 params := BreakerParams{QueueDepth: 1, MaxConcurrency: 1, InitialCapacity: 0}
195 b := NewBreaker(params)
196 reqs := newRequestor(b)
197
198 // Cancel a request which cannot get capacity.
199 ctx1, cancel1 := context.WithCancel(context.Background())
200 reqs.requestWithContext(ctx1)
201 cancel1()
202 reqs.expectFailure(t)
203
204 // This request cannot get capacity either. This reproduced a bug we had when
205 // freeing slots on the pendingRequests channel.
206 ctx2, cancel2 := context.WithCancel(context.Background())
207 reqs.requestWithContext(ctx2)
208 cancel2()
209 reqs.expectFailure(t)
210
211 // Let through a request with capacity then timeout following request
212 b.UpdateConcurrency(1)
213 reqs.request()
214
215 // Exceed capacity and assert one failure. This makes sure the Breaker is consistently
216 // at capacity.
217 reqs.request()
218 reqs.request()
219 reqs.expectFailure(t)
220
221 // This request cannot get capacity.
222 ctx3, cancel3 := context.WithCancel(context.Background())
223 reqs.requestWithContext(ctx3)
224 cancel3()
225 reqs.expectFailure(t)
226
227 // The requests that were put in earlier should succeed.
228 reqs.processSuccessfully(t)
229 reqs.processSuccessfully(t)
230}
231
232func TestBreakerUpdateConcurrency(t *testing.T) {
233 params := BreakerParams{QueueDepth: 1, MaxConcurrency: 1, InitialCapacity: 0}

Callers

nothing calls this directly

Calls 7

UpdateConcurrencyMethod · 0.95
NewBreakerFunction · 0.85
newRequestorFunction · 0.85
requestWithContextMethod · 0.80
expectFailureMethod · 0.80
requestMethod · 0.80
processSuccessfullyMethod · 0.80

Tested by

no test coverage detected