| 1 | //go:build unix |
| 2 | |
| 3 | package hostguard |
| 4 | |
| 5 | import ( |
| 6 | "context" |
| 7 | "testing" |
| 8 | "time" |
| 9 | ) |
| 10 | |
| 11 | func TestPlan14ColdPredecessorAfterRepeatedRootStop(t *testing.T) { |
| 12 | f, target, captured := fenceFixture(t) |
| 13 | f.g.Root = NewRootAuthority(&rootTestStore{dir: t.TempDir()}) |
| 14 | f.obs.Claim.Holder.Account, f.obs.Claim.Holder.App = "bab", "app" |
| 15 | in := RootInstallation{Host: target.Host, Incarnation: target.Incarnation, Stamp: target.Stamp, Account: "bab", App: "app", Record: "record", Box: target.Box, Enrollment: target.Enrollment, Migration: 1} |
| 16 | if err := f.g.EstablishRoot(t.Context(), in, allow); err != nil { |
| 17 | t.Fatal(err) |
| 18 | } |
| 19 | verify := func(context.Context, FenceTarget, []byte, time.Time) error { return nil } |
| 20 | for i := 0; i < 2; i++ { |
| 21 | if i == 1 { |
| 22 | target.ControllerID = "replacement" |
| 23 | target.FenceID = "replacement-fence" |
| 24 | } |
| 25 | if _, err := f.g.BeginFence(t.Context(), target); err != nil { |
| 26 | t.Fatal(err) |
| 27 | } |
| 28 | if i == 1 { |
| 29 | if _, err := f.g.CompletedColdPredecessor(t.Context(), target.Host, captured, target.Session, target.Op, target.Phase); err == nil { |
| 30 | t.Fatal("pending stop accepted") |
| 31 | } |
| 32 | } |
| 33 | if err := f.g.CompleteFence(t.Context(), target, []byte(target.FenceID), time.Now(), verify); err != nil { |
| 34 | t.Fatal(err) |
| 35 | } |
| 36 | } |
| 37 | r, err := f.g.CompletedColdPredecessor(t.Context(), target.Host, captured, target.Session, target.Op, target.Phase) |
| 38 | if err != nil || r.Target != target { |
| 39 | t.Fatal("current completed fence not selected", r.Target, err) |
| 40 | } |
| 41 | if _, err := f.g.CompletedColdPredecessor(t.Context(), target.Host, captured, target.Session+1, target.Op, target.Phase); err == nil { |
| 42 | t.Fatal("foreign session accepted") |
| 43 | } |
| 44 | } |
| 45 | |