mirror of
https://github.com/lukaszraczylo/traefik-llmgateway.git
synced 2026-11-26 10:06:31 +00:00
test(shared-state): pin discovery half-open re-trip and quiet success
A failed half-open probe on one instance must open the fleet breaker again and count one more open. A success after failures that stayed below the local threshold must send no store write.
This commit is contained in:
@@ -104,3 +104,49 @@ func TestSharedDiscoveryBreakerCountsPerInstance(t *testing.T) {
|
|||||||
t.Fatal("B healthy after A reached the threshold on its own")
|
t.Fatal("B healthy after A reached the threshold on its own")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSharedDiscoveryHalfOpenFailureRetripsFleet(t *testing.T) {
|
||||||
|
a, b, store, clk, _ := sharedGatewayPair(t, nil)
|
||||||
|
boom := errors.New("discovery down")
|
||||||
|
st := a.registry.states["alpha"]
|
||||||
|
for i := 0; i < defaultBreakerFailureThreshold; i++ {
|
||||||
|
a.registry.finishRefresh(st, clk.now(), nil, boom)
|
||||||
|
}
|
||||||
|
a.sharedState.refresh()
|
||||||
|
opens := store.writesTo(":opens")
|
||||||
|
if opens != 1 {
|
||||||
|
t.Fatalf("opens increments after the first trip = %d, want 1", opens)
|
||||||
|
}
|
||||||
|
clk.advance(st.breakerOpenMax + time.Second)
|
||||||
|
b.sharedState.refresh()
|
||||||
|
if !b.registry.discoveryHealthy("alpha") {
|
||||||
|
t.Fatal("B unhealthy after the fleet open window elapsed")
|
||||||
|
}
|
||||||
|
st.mu.Lock()
|
||||||
|
st.health = breakerHalfOpen
|
||||||
|
st.mu.Unlock()
|
||||||
|
a.registry.finishRefresh(st, clk.now(), nil, boom)
|
||||||
|
a.sharedState.refresh()
|
||||||
|
if got := store.writesTo(":opens"); got != opens+1 {
|
||||||
|
t.Fatalf("opens increments after a failed half-open probe = %d, want %d", got, opens+1)
|
||||||
|
}
|
||||||
|
b.sharedState.refresh()
|
||||||
|
if b.registry.discoveryHealthy("alpha") {
|
||||||
|
t.Fatal("B healthy after A's half-open probe failed, want the fleet breaker open again")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSharedDiscoverySuccessAfterUnsharedFailuresWritesNothing(t *testing.T) {
|
||||||
|
a, _, store, clk, _ := sharedGatewayPair(t, nil)
|
||||||
|
st := a.registry.states["alpha"]
|
||||||
|
for i := 0; i < defaultBreakerFailureThreshold-1; i++ {
|
||||||
|
a.registry.finishRefresh(st, clk.now(), nil, errors.New("discovery down"))
|
||||||
|
}
|
||||||
|
a.sharedState.refresh()
|
||||||
|
before := len(store.writes)
|
||||||
|
a.registry.finishRefresh(st, clk.now(), []string{"m"}, nil)
|
||||||
|
a.sharedState.refresh()
|
||||||
|
if got := len(store.writes); got != before {
|
||||||
|
t.Fatalf("store writes after a success that followed only unshared failures = %d, want %d", got-before, 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user