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

Function TestBreakerOverloadMixed

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

Source from the content-addressed store, hash-verified

91}
92
93func 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
120func TestBreakerOverload(t *testing.T) {
121 params := BreakerParams{QueueDepth: 1, MaxConcurrency: 1, InitialCapacity: 1}

Callers

nothing calls this directly

Calls 6

ReserveMethod · 0.95
NewBreakerFunction · 0.85
newRequestorFunction · 0.85
unpackFunction · 0.85
requestMethod · 0.80
processSuccessfullyMethod · 0.80

Tested by

no test coverage detected