(t *testing.T)
| 91 | } |
| 92 | |
| 93 | func TestBreakerOverloadMixed(t *testing.T) { |
| 94 | // This tests when reservation and maybe are intermised. |
| 95 | params := BreakerParams{QueueDepth: 1, MaxConcurrency: 1, InitialCapacity: 1} |
| 96 | b := NewBreaker(params) // Breaker capacity = 2 |
| 97 | reqs := newRequestor(b) |
| 98 | |
| 99 | // Bring breaker to capacity. |
| 100 | reqs.request() |
| 101 | // This happens in go-routine, so spin. |
| 102 | for _, in := unpack(b.sem.state.Load()); in != 1; _, in = unpack(b.sem.state.Load()) { |
| 103 | time.Sleep(time.Millisecond * 2) |
| 104 | } |
| 105 | _, rr := b.Reserve(context.Background()) |
| 106 | if rr { |
| 107 | t.Fatal("Reserve was an unexpected success.") |
| 108 | } |
| 109 | // Open a slot. |
| 110 | reqs.processSuccessfully(t) |
| 111 | // Now reservation should work. |
| 112 | cb, rr := b.Reserve(context.Background()) |
| 113 | if !rr { |
| 114 | t.Fatal("Reserve unexpectedly failed") |
| 115 | } |
| 116 | // Process the reservation. |
| 117 | cb() |
| 118 | } |
| 119 | |
| 120 | func TestBreakerOverload(t *testing.T) { |
| 121 | params := BreakerParams{QueueDepth: 1, MaxConcurrency: 1, InitialCapacity: 1} |
nothing calls this directly
no test coverage detected