package activator import ( "context" "errors" "testing" "github.com/carlosframework/platform/internal/hostbox" "github.com/carlosframework/platform/internal/hostclaim" "github.com/carlosframework/platform/internal/hostwrite" "github.com/carlosframework/platform/internal/registry" ) func TestClaimWakeRefusesQueuedIncarnationBeforeAdmission(t *testing.T) { admitted := false runtime := &ClaimRuntime{ Box: "box", Read: func(context.Context, string) (hostclaim.Observed, error) { return hostclaim.Observed{Claim: &hostclaim.Claim{Holder: &hostclaim.Holder{Incarnation: "replacement"}, Op: hostclaim.Op{Kind: hostclaim.KindServing, Exec: "box"}}}, nil }, StopForeign: func(context.Context, string) error { return nil }, Prerequisites: func(context.Context, registry.Route, hostclaim.Observed, startPolicy) error { admitted = true return errors.New("unexpected prerequisites") }, Admit: func(context.Context, registry.Route, hostclaim.Observed, startPolicy) (hostclaim.Observed, error) { admitted = true return hostclaim.Observed{}, errors.New("unexpected admission") }, } service := &Service{cfg: Config{HostWrites: hostwrite.Config{Enabled: true}, Claims: runtime}} _, err := service.doClaimWake(context.Background(), &actEntry{host: "x.example", route: registry.Route{Host: "x.example", WakeIncarnation: "retired"}}) if !errors.Is(err, hostbox.ErrChanged) || admitted { t.Fatalf("old wake reached replacement: %v admitted=%v", err, admitted) } }