| 1 | package activator |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "errors" |
| 6 | "testing" |
| 7 | |
| 8 | "github.com/carlosframework/platform/internal/hostbox" |
| 9 | "github.com/carlosframework/platform/internal/hostclaim" |
| 10 | "github.com/carlosframework/platform/internal/hostwrite" |
| 11 | "github.com/carlosframework/platform/internal/registry" |
| 12 | ) |
| 13 | |
| 14 | func TestClaimWakeRefusesQueuedIncarnationBeforeAdmission(t *testing.T) { |
| 15 | admitted := false |
| 16 | runtime := &ClaimRuntime{ |
| 17 | Box: "box", |
| 18 | Read: func(context.Context, string) (hostclaim.Observed, error) { |
| 19 | return hostclaim.Observed{Claim: &hostclaim.Claim{Holder: &hostclaim.Holder{Incarnation: "replacement"}, Op: hostclaim.Op{Kind: hostclaim.KindServing, Exec: "box"}}}, nil |
| 20 | }, |
| 21 | StopForeign: func(context.Context, string) error { return nil }, |
| 22 | Prerequisites: func(context.Context, registry.Route, hostclaim.Observed, startPolicy) error { |
| 23 | admitted = true |
| 24 | return errors.New("unexpected prerequisites") |
| 25 | }, |
| 26 | Admit: func(context.Context, registry.Route, hostclaim.Observed, startPolicy) (hostclaim.Observed, error) { |
| 27 | admitted = true |
| 28 | return hostclaim.Observed{}, errors.New("unexpected admission") |
| 29 | }, |
| 30 | } |
| 31 | service := &Service{cfg: Config{HostWrites: hostwrite.Config{Enabled: true}, Claims: runtime}} |
| 32 | _, err := service.doClaimWake(context.Background(), &actEntry{host: "x.example", route: registry.Route{Host: "x.example", WakeIncarnation: "retired"}}) |
| 33 | if !errors.Is(err, hostbox.ErrChanged) || admitted { |
| 34 | t.Fatalf("old wake reached replacement: %v admitted=%v", err, admitted) |
| 35 | } |
| 36 | } |
| 37 | |