44 lines
1.8 KiB
Go
44 lines
1.8 KiB
Go
package activitypool
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"testing"
|
|
"time"
|
|
|
|
healthDomain "proxy-pool/internal/domain/health"
|
|
proxyDomain "proxy-pool/internal/domain/proxy"
|
|
)
|
|
|
|
func TestMemoryPoolKeepsTargetHealthOutsideGlobalProxyState(t *testing.T) {
|
|
now := time.Date(2026, 7, 31, 12, 0, 0, 0, time.UTC)
|
|
pool := seededHealthPool(t, now)
|
|
before := pool.Snapshot(now)
|
|
if len(before) != 1 || before[0].State != proxyDomain.StateFetched {
|
|
t.Fatalf("before = %+v", before)
|
|
}
|
|
command := TargetHealthCommand{Observation: healthDomain.Observation{
|
|
TaskID: "target-task-1", ProxyID: "proxy-a", Level: healthDomain.LevelTarget,
|
|
RoutingName: "route-a", TargetURL: "https://target.example/check", Success: false,
|
|
FailureClass: "target_403", Latency: 20 * time.Millisecond, ObservedAt: now.Add(time.Second),
|
|
}, MaxConsecutiveFailures: 2}
|
|
first, err := pool.ApplyTargetObservation(context.Background(), command)
|
|
if err != nil || first.Status != healthDomain.TargetSuspect || first.ConsecutiveFailures != 1 {
|
|
t.Fatalf("ApplyTargetObservation(first) = %+v, %v", first, err)
|
|
}
|
|
after := pool.Snapshot(now.Add(time.Second))
|
|
if len(after) != 1 || after[0].State != before[0].State || after[0].GlobalHealth != before[0].GlobalHealth {
|
|
t.Fatalf("target observation changed global entry: before=%+v after=%+v", before[0], after[0])
|
|
}
|
|
replayed, err := pool.ApplyTargetObservation(context.Background(), command)
|
|
if err != nil || replayed != first {
|
|
t.Fatalf("ApplyTargetObservation(replay) = %+v, %v", replayed, err)
|
|
}
|
|
conflicting := command
|
|
conflicting.Observation.Success = true
|
|
conflicting.Observation.FailureClass = ""
|
|
if _, err := pool.ApplyTargetObservation(context.Background(), conflicting); !errors.Is(err, healthDomain.ErrConflictingObservation) {
|
|
t.Fatalf("ApplyTargetObservation(conflict) error = %v, want ErrConflictingObservation", err)
|
|
}
|
|
}
|