(t *testing.T)
| 191 | } |
| 192 | |
| 193 | func 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 | |
| 232 | func TestBreakerUpdateConcurrency(t *testing.T) { |
| 233 | params := BreakerParams{QueueDepth: 1, MaxConcurrency: 1, InitialCapacity: 0} |
nothing calls this directly
no test coverage detected