Some output tweaks; and some additional transition events upon resume (paused->unknown->{up|down})
This commit is contained in:
@@ -23,12 +23,14 @@ func TestInitialState(t *testing.T) {
|
||||
if len(b.Transitions) != 0 {
|
||||
t.Errorf("initial transitions: got %d, want 0", len(b.Transitions))
|
||||
}
|
||||
if b.Counter.Health != 0 {
|
||||
t.Errorf("initial counter health: got %d, want 0", b.Counter.Health)
|
||||
// Counter pre-loaded to Rise-1 so first probe resolves state immediately.
|
||||
if want := b.Counter.Rise - 1; b.Counter.Health != want {
|
||||
t.Errorf("initial counter health: got %d, want %d (rise-1)", b.Counter.Health, want)
|
||||
}
|
||||
}
|
||||
|
||||
// TestRiseToUp: rise=2 passes from Down/Unknown → Up.
|
||||
// TestRiseToUp: from Unknown/Down with counter pre-loaded to Rise-1, a single
|
||||
// pass is enough to reach Up.
|
||||
func TestRiseToUp(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
@@ -39,18 +41,11 @@ func TestRiseToUp(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
b := newBackend()
|
||||
b := newBackend() // rise=2 → Health starts at Rise-1=1
|
||||
b.State = tt.initialState
|
||||
// First pass: counter=1, still in DOWN range (rise=2), no transition.
|
||||
if b.Record(pass(), 5) {
|
||||
t.Error("should not transition after 1 pass (rise=2)")
|
||||
}
|
||||
if b.State != tt.initialState {
|
||||
t.Errorf("state changed early: got %s", b.State)
|
||||
}
|
||||
// Second pass: counter=2=rise, transitions to Up.
|
||||
// Counter is already at Rise-1; one pass reaches Rise → Up.
|
||||
if !b.Record(pass(), 5) {
|
||||
t.Error("should transition to Up after 2 passes")
|
||||
t.Error("should transition to Up after 1 pass (counter pre-loaded to rise-1)")
|
||||
}
|
||||
if b.State != StateUp {
|
||||
t.Errorf("state: got %s, want up", b.State)
|
||||
|
||||
Reference in New Issue
Block a user