mirror of
https://github.com/lukaszraczylo/traefik-llmgateway.git
synced 2026-11-26 10:06:31 +00:00
The open count only grew, so each trip after a recovery waited longer than the last. The breaker now reads the open count on every refresh. A success sets the count to zero when the last refresh showed it above zero. The next trip then opens for the base duration.
36 lines
850 B
Go
36 lines
850 B
Go
package traefikllmgateway
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestSharedBreakerSuccessResetsBackoff(t *testing.T) {
|
|
store, clk := sharedTestEnv()
|
|
l := sharedTestLoop(store, clk)
|
|
b := testBreaker(l)
|
|
openKey := sharedBreakerKey("req", "p", "open")
|
|
openFor := func() time.Duration {
|
|
got, _ := store.getMulti([]string{openKey})
|
|
return time.UnixMilli(got[0]).Sub(clk.now())
|
|
}
|
|
trip := func() {
|
|
for i := 0; i < 3; i++ {
|
|
b.recordFailure("p")
|
|
}
|
|
l.refresh()
|
|
l.refresh()
|
|
}
|
|
trip()
|
|
if got := openFor(); got != testBrkOpenBase {
|
|
t.Fatalf("first trip open for %v, want %v", got, testBrkOpenBase)
|
|
}
|
|
clk.advance(testBrkOpenBase + time.Second)
|
|
b.recordSuccess("p")
|
|
l.refresh()
|
|
trip()
|
|
if got := openFor(); got != testBrkOpenBase {
|
|
t.Fatalf("trip after a success open for %v, want %v (backoff must reset)", got, testBrkOpenBase)
|
|
}
|
|
}
|