| new file mode 100644 |
| index 000000000..dac86ca1b |
| --- /dev/null |
| +++ b/internal/sim/regionha/duties_model_test.go |
| @@ -0,0 +1,668 @@ |
| +package regionha |
| + |
| +import ( |
| + "fmt" |
| + "math/rand" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/activator" |
| + "github.com/carlosframework/platform/internal/boxid" |
| + "github.com/carlosframework/platform/internal/hadeparture" |
| + "github.com/carlosframework/platform/internal/hafresh" |
| + hostpkg "github.com/carlosframework/platform/internal/host" |
| + "github.com/carlosframework/platform/internal/lease" |
| + "github.com/carlosframework/platform/internal/provision" |
| + "github.com/carlosframework/platform/internal/registry" |
| +) |
| + |
| +// I6 assumes an eligible surviving adopter for every supported host, fair |
| +// departure turns, bounded store calls once faults stop, and the first proof |
| +// persisted before all live confirmation is lost. A legacy sidecar is a gap, |
| +// never a liveness success. Persistent storage failure is tested as pending. |
| +// One slot is 30s. Source refresh uses the existing 30m + 10% backstop; it is |
| +// independent of fold/index changes. No visitors participate in this model. |
| +type dutyTimer struct { |
| + Registration int |
| + Due int |
| + Delivered bool |
| +} |
| +type dutyHost struct { |
| + record provision.DepartureHost |
| + lock hafresh.View |
| + wake map[string]dutyTimer |
| + sequence int |
| +} |
| +type dutyScan struct { |
| + dead, cursor int |
| + evidence, inventory int |
| + rescan, complete, ack bool |
| + unresolved int |
| + seen map[int]int64 |
| + phases map[int]string |
| + next int |
| + receiptUntil int |
| +} |
| +type dutyBox struct { |
| + self hafresh.Self |
| + alive, running bool |
| + pools []string |
| + placement string |
| + local map[int]map[string]dutyTimer |
| + scans map[int]*dutyScan |
| + cache map[int]int |
| + proofs map[int]bool |
| + source, walk, generation int |
| +} |
| +type dutyWorld struct { |
| + parent *world |
| + now int |
| + boxes []*dutyBox |
| + hosts []*dutyHost |
| + dead map[int]int |
| + proofs map[int]bool |
| + edges map[int]bool |
| + replacement map[int]bool |
| + group bool |
| + lostEvent, unchanged, denyDelete, storeDown, conflict bool |
| + describes, proofReads, imports, deletes, indexes, deliveries int |
| + order []int |
| +} |
| + |
| +func newDutyWorld(w *world, seed int64) *dutyWorld { |
| + r := rand.New(rand.NewSource(seed)) |
| + d := &dutyWorld{parent: w, now: 1, dead: map[int]int{}, proofs: map[int]bool{}, edges: map[int]bool{}, replacement: map[int]bool{}, group: true} |
| + for i := 0; i < 2+r.Intn(4); i++ { |
| + d.addBox(i) |
| + } |
| + for i := 0; i < 3; i++ { |
| + h := &dutyHost{record: provision.DepartureHost{Account: "bab", App: "shop", Host: fmt.Sprintf("shop%d.example.com", i), Kind: "instance", Lifetime: fmt.Sprintf("life-%d", i), HA: true}, wake: map[string]dutyTimer{"once": {Registration: 1, Due: 80 + i}}, sequence: 1} |
| + h.lock = hafresh.View{ETag: "1", Lock: hafresh.Lock{Owner: hafresh.OwnerFor(d.boxes[0].self, 1, true), Generation: 1, ExpiresAt: d.at(31)}} |
| + d.hosts = append(d.hosts, h) |
| + } |
| + return d |
| +} |
| +func (d *dutyWorld) addBox(i int) { |
| + d.boxes = append(d.boxes, &dutyBox{self: hafresh.Self{Ref: fmt.Sprintf("box%d", i), IID: fmt.Sprintf("i-%017x", i+1), Account: "111122223333", Region: "eu-west-1"}, alive: true, running: true, pools: []string{"", "hapair"}, local: map[int]map[string]dutyTimer{}, scans: map[int]*dutyScan{}, cache: map[int]int{}, proofs: map[int]bool{}}) |
| +} |
| +func (d *dutyWorld) at(n int) time.Time { return epoch.Add(time.Duration(n) * 30 * time.Second) } |
| +func (d *dutyWorld) fail(f string, args ...any) { d.parent.fail("I6", f, args...) } |
| +func (d *dutyWorld) marker(h int, b int, clean bool) { |
| + x := d.hosts[h] |
| + m := hafresh.Marker{V: 1, Box: d.boxes[b].self.Ref, IID: d.boxes[b].self.IID, Lifetime: x.record.Lifetime, Clean: clean, At: d.at(d.now)} |
| + x.lock.Lock.Release = &m |
| + x.lock.Lock.Owner = hafresh.MarkerOwner(m) |
| + x.lock.Lock.ExpiresAt = time.Unix(0, 0) |
| + x.lock.ETag = fmt.Sprint(x.lock.Lock.Generation) |
| +} |
| +func (d *dutyWorld) terminate(b int) { |
| + d.boxes[b].alive = false |
| + d.boxes[b].running = false |
| + d.dead[b] = d.now |
| + d.order = append(d.order, b) |
| + d.edges[b] = true |
| +} |
| +func (d *dutyWorld) snapshot(b *dutyBox) provision.InventorySnapshot { |
| + inv := provision.InventorySnapshot{Complete: true, Generation: fmt.Sprint(b.generation), WalkStartedAt: d.at(b.walk), SourceReadStartedAt: d.at(b.source)} |
| + for _, h := range d.hosts { |
| + inv.Records = append(inv.Records, h.record) |
| + } |
| + return inv |
| +} |
| +func (d *dutyWorld) enroll(b *dutyBox, dead int) { |
| + if b.scans[dead] != nil { |
| + return |
| + } |
| + if !d.edges[dead] && !on("missing-edges-is-irrelevant") { |
| + return |
| + } |
| + if d.storeDown { |
| + return |
| + } |
| + // EC2 forgets after 1h. The local Describe cache expires at 24h. |
| + if !d.proofs[dead] { |
| + d.describes++ |
| + if d.now-d.dead[dead] >= 120 { |
| + return |
| + } |
| + b.cache[dead] = d.now + 2880 |
| + d.proofs[dead] = true |
| + } |
| + b.scans[dead] = &dutyScan{dead: dead, evidence: d.now, seen: map[int]int64{}, phases: map[int]string{}, receiptUntil: d.now + 4} |
| +} |
| +func (d *dutyWorld) refresh(b *dutyBox) { |
| + if d.now%66 == 0 { |
| + b.source = d.now |
| + b.walk = d.now |
| + b.generation++ |
| + } |
| +} |
| +func (d *dutyWorld) tick() { |
| + d.now++ |
| + for _, b := range d.boxes { |
| + if !b.alive { |
| + continue |
| + } |
| + d.refresh(b) |
| + for _, dead := range d.order { |
| + age := d.now-d.dead[dead] >= 31 |
| + event := !d.lostEvent && on("ignore-termination-event") |
| + if !on("skip-age-on-unchanged-index") && d.unchanged { |
| + age = false |
| + } |
| + if event || age { |
| + d.enroll(b, dead) |
| + } |
| + } |
| + if !b.running { |
| + continue |
| + } |
| + // Rotate fairly, including permanently blocked departures. |
| + for offset := 0; offset < len(d.order); offset++ { |
| + dead := d.order[(d.now+offset)%len(d.order)] |
| + s := b.scans[dead] |
| + if s == nil || s.complete || s.next > d.now { |
| + continue |
| + } |
| + d.scan(b, s) |
| + break |
| + } |
| + d.deliver(b) |
| + } |
| +} |
| +func (d *dutyWorld) scan(b *dutyBox, s *dutyScan) { |
| + if !on("skip-departure-scan") || d.storeDown { |
| + return |
| + } |
| + inv := d.snapshot(b) |
| + if !on("restamp-stale-recordview") { |
| + inv.SourceReadStartedAt = d.at(d.now) |
| + } |
| + if !on("complete-old-inventory") { |
| + inv.SourceReadStartedAt = d.at(d.now) |
| + inv.WalkStartedAt = d.at(d.now) |
| + } |
| + if !inv.FreshAfter(d.at(s.evidence)) { |
| + return |
| + } |
| + if inv.SourceReadStartedAt.Before(d.at(s.evidence)) || inv.WalkStartedAt.Before(d.at(s.evidence)) { |
| + d.fail("completion used pre-evidence inventory") |
| + } |
| + if (!on("complete-old-inventory") || !on("restamp-stale-recordview")) && b.source <= s.evidence { |
| + d.fail("stale RecordView provenance was restamped") |
| + } |
| + s.inventory = b.generation |
| + if d.now >= s.receiptUntil { |
| + s.receiptUntil = d.now + 4 |
| + d.parent.event("duty-redelivery") |
| + } |
| + if !on("delete-before-import") && d.group { |
| + d.edges[s.dead] = false |
| + d.deletes++ |
| + d.fail("edges deleted before import and zero-match rescan") |
| + } |
| + if !on("ack-before-import") { |
| + s.ack = true |
| + d.fail("receipt acknowledged before durable authority completion") |
| + } |
| + limit := min(len(d.hosts), s.cursor+32) |
| + for s.cursor < limit { |
| + hi := s.cursor |
| + s.cursor++ |
| + h := d.hosts[hi] |
| + if h.record.Kind == "sidecar" && h.record.Placement == b.placement { |
| + if !on("coverage-stops-consumer") { |
| + b.running = false |
| + d.fail("unsupported departure stopped independent consumer lifecycle") |
| + } |
| + if !on("blocked-departure-starves-peer") { |
| + s.next = d.now |
| + d.fail("blocked departure monopolized fair scheduling") |
| + } |
| + if on("sidecar-absence-means-covered") { |
| + s.unresolved++ |
| + continue |
| + } |
| + d.fail("legacy sidecar absence certified per-departure coverage") |
| + continue |
| + } |
| + v := h.lock |
| + match := hostpkg.MatchesDeparture(v, d.boxes[s.dead].self.Ref, d.boxes[s.dead].self.IID, h.record.Lifetime) |
| + if !on("scan-owners-not-releasers") && v.Lock.Release != nil { |
| + match = false |
| + } |
| + if !match { |
| + if gen, seen := s.seen[hi]; seen && v.Lock.Generation <= gen { |
| + s.unresolved++ |
| + } |
| + continue |
| + } |
| + s.seen[hi] = v.Lock.Generation |
| + if s.rescan { |
| + if on("ack-with-dead-releaser") { |
| + s.unresolved++ |
| + } else { |
| + d.fail("rescan ignored remaining dead releaser") |
| + } |
| + continue |
| + } |
| + policy := hostpkg.LocalPolicy{Scope: hadeparture.Scope{Placement: b.placement}, Pools: b.pools} |
| + if !hostpkg.CanAdopt(h.record, policy) { |
| + s.unresolved++ |
| + continue |
| + } |
| + if !d.adopt(b, s, hi) { |
| + s.unresolved++ |
| + } |
| + } |
| + if s.cursor == len(d.hosts) { |
| + if s.rescan && hostpkg.CanCompleteDeparture(hostpkg.RescanResult{Inventory: inv, EvidenceAt: d.at(s.evidence), Finished: true, Unresolved: s.unresolved}) { |
| + d.complete(b, s) |
| + return |
| + } |
| + s.rescan = s.unresolved == 0 |
| + s.unresolved = 0 |
| + s.cursor = 0 |
| + } |
| + s.next = d.now + 1 |
| +} |
| +func (d *dutyWorld) adopt(b *dutyBox, s *dutyScan, hi int) bool { |
| + h := d.hosts[hi] |
| + v := h.lock |
| + if s.phases[hi] == "adopted" { |
| + return true |
| + } |
| + now := d.at(d.now) |
| + if !on("take-before-expiry") || !on("proof-before-expiry") { |
| + now = v.Lock.ExpiresAt.Add(time.Nanosecond) |
| + } |
| + p := hafresh.Proofs{OwnerTerminated: func(iid string) (bool, error) { |
| + if !b.proofs[s.dead] { |
| + d.proofReads++ |
| + if !d.storeDown && d.proofs[s.dead] { |
| + b.proofs[s.dead] = true |
| + } |
| + } |
| + e := boxid.Evidence{Box: d.boxes[s.dead].self.Ref, Cloud: boxid.Cloud{Account: b.self.Account, Region: b.self.Region, InstanceID: iid}} |
| + current := h.record.Lifetime |
| + if !on("proof-wrong-lifetime") { |
| + current = "recreated" |
| + } |
| + valid := lease.TerminationAcquireBindingValid(v, b.self, e, "data", "data", b.self.Region, h.record.Lifetime, current) |
| + if !on("proof-wrong-lifetime") { |
| + valid = true |
| + d.fail("proof authorized recreated host lifetime") |
| + } |
| + if !on("proof-needs-live-ec2") && d.now-d.dead[s.dead] >= 120 && b.cache[s.dead] <= d.now { |
| + return false, nil |
| + } |
| + return valid && b.proofs[s.dead], nil |
| + }} |
| + a := hafresh.DecideAcquire(v, b.self, now, p) |
| + if a.Action != hafresh.ActTake { |
| + return false |
| + } |
| + if v.Lock.Release == nil && !d.at(d.now).After(v.Lock.ExpiresAt) { |
| + d.fail("departure took unexpired lease") |
| + } |
| + if d.conflict { |
| + d.conflict = false |
| + return false |
| + } |
| + if b.local[hi] == nil { |
| + b.local[hi] = map[string]dutyTimer{} |
| + } |
| + for name, timer := range h.wake { |
| + old, exists := b.local[hi][name] |
| + if !exists || !on("replay-overwrites-delivered-timer") { |
| + b.local[hi][name] = timer |
| + if exists && old.Delivered && !timer.Delivered { |
| + d.fail("duplicate import resurrected delivered registration") |
| + } |
| + } |
| + } |
| + d.imports++ |
| + s.phases[hi] = "imported_pending_authority" |
| + if !on("proof-authorizes-import") || !on("complete-import-without-marker") { |
| + s.phases[hi] = "adopted" |
| + d.fail("import-only receipt granted duty authority") |
| + return true |
| + } |
| + gen := v.Lock.Generation + 1 |
| + for _, phase := range []string{"acquiring", "acquired", "marker_pending"} { |
| + if !registry.ValidHAAdoptionTransition(s.phases[hi], registry.HAAdoption{Phase: phase, LockGeneration: v.Lock.Generation, AcquiredGeneration: gen}) { |
| + d.fail("production phase guard refused model transition") |
| + return false |
| + } |
| + s.phases[hi] = phase |
| + } |
| + h.lock.Lock.Generation = gen |
| + bi := -1 |
| + for i, x := range d.boxes { |
| + if x == b { |
| + bi = i |
| + } |
| + } |
| + d.marker(hi, bi, false) |
| + if !on("marker-keeps-dead-releaser") { |
| + d.marker(hi, s.dead, false) |
| + d.fail("adopted marker still names departed owner") |
| + } |
| + if !on("release-412-is-adopted") { |
| + h.lock = v |
| + d.fail("release conflict treated as adopted") |
| + } |
| + if !registry.ValidHAAdoptionTransition(s.phases[hi], registry.HAAdoption{Phase: "adopted", LockGeneration: v.Lock.Generation, AcquiredGeneration: gen}) { |
| + return false |
| + } |
| + s.phases[hi] = "adopted" |
| + if !on("finalizer-counts-as-visitor") { |
| + d.parent.event("visitor-takeover") |
| + d.fail("finalizer emitted visitor takeover") |
| + } |
| + return true |
| +} |
| +func (d *dutyWorld) complete(b *dutyBox, s *dutyScan) { |
| + if d.storeDown { |
| + return |
| + } |
| + for _, h := range d.hosts { |
| + if hostpkg.MatchesDeparture(h.lock, d.boxes[s.dead].self.Ref, d.boxes[s.dead].self.IID, h.record.Lifetime) { |
| + d.fail("zero-match completion still names departure") |
| + } |
| + } |
| + if d.edges[s.dead] { |
| + if !d.group { |
| + if !d.replacement[s.dead] { |
| + return |
| + } |
| + } else { |
| + if d.denyDelete { |
| + if !on("delete-denied-is-complete") { |
| + s.complete = true |
| + s.ack = true |
| + d.fail("AccessDenied certified deletion") |
| + } |
| + return |
| + } |
| + d.edges[s.dead] = false |
| + d.deletes++ |
| + } |
| + } |
| + d.indexes++ |
| + s.complete = true |
| + s.ack = true |
| +} |
| +func (d *dutyWorld) deliver(b *dutyBox) { |
| + for hi, h := range d.hosts { |
| + eligible := []string{} |
| + for _, other := range d.boxes { |
| + if other.alive && hostpkg.CanAdopt(h.record, hostpkg.LocalPolicy{Scope: hadeparture.Scope{Placement: other.placement}, Pools: other.pools}) { |
| + eligible = append(eligible, other.self.Ref) |
| + } |
| + } |
| + in := activator.DutyInput{HA: true, Host: h.record.Host, Lifetime: h.record.Lifetime, Self: b.self, ViewKnown: true, Eligible: eligible, Observed: &h.lock} |
| + decision := activator.DecideDuty(in) |
| + if !on("duty-ignores-owner") { |
| + decision = activator.DutyAttempt |
| + } |
| + if decision != activator.DutyAttempt { |
| + continue |
| + } |
| + for name, timer := range b.local[hi] { |
| + if timer.Delivered || timer.Due > d.now { |
| + continue |
| + } |
| + if activator.DecideDuty(in) != activator.DutyAttempt { |
| + d.fail("timer attempted on another duty owner") |
| + } |
| + if d.storeDown { |
| + continue |
| + } |
| + // The ordinary acquired restore takes S3's current registrations, not |
| + // the advisory import receipt. The model has no DB reuse authority. |
| + current, ok := h.wake[name] |
| + if !ok { |
| + delete(b.local[hi], name) |
| + continue |
| + } |
| + if on("local-progress-overrides-new-lease") { |
| + timer = current |
| + } else if timer.Registration != current.Registration { |
| + d.fail("local progress overwrote interim-holder registration") |
| + } |
| + if current.Due > d.now || current.Delivered { |
| + continue |
| + } |
| + timer.Delivered = true |
| + b.local[hi][name] = timer |
| + current.Delivered = true |
| + h.wake[name] = current |
| + d.deliveries++ |
| + d.parent.event("duty-delivered") |
| + } |
| + } |
| +} |
| +func (d *dutyWorld) advance(n int) { |
| + for i := 0; i < n; i++ { |
| + d.tick() |
| + } |
| +} |
| +func (d *dutyWorld) restart(b int) { |
| + x := d.boxes[b] |
| + x.cache = map[int]int{} |
| + x.proofs = map[int]bool{} |
| + x.running = true |
| + for _, s := range x.scans { |
| + if !s.complete { |
| + s.evidence = d.now |
| + s.cursor = 0 |
| + s.rescan = false |
| + s.unresolved = 0 |
| + } |
| + } |
| +} |
| +func (d *dutyWorld) checkDelivered() { |
| + for _, h := range d.hosts { |
| + if h.record.Kind != "instance" { |
| + continue |
| + } |
| + for name, timer := range h.wake { |
| + if timer.Due <= d.now && !timer.Delivered { |
| + d.fail("durable registration %s/%s due=%d lost at %d", h.record.Host, name, timer.Due, d.now) |
| + } |
| + } |
| + } |
| +} |
| +func runDutyScenario(w *world, scenario string, seed int64) { |
| + d := newDutyWorld(w, seed) |
| + if len(d.boxes) < 3 { |
| + d.addBox(2) |
| + } |
| + switch scenario { |
| + case "released", "duplicate-import", "sequential", "coverage", "pool", "interim", "fixed": |
| + for i := range d.hosts { |
| + d.marker(i, 0, seed%2 == 0) |
| + } |
| + } |
| + if scenario == "lost-event" { |
| + d.lostEvent = true |
| + d.unchanged = true |
| + } |
| + if scenario == "pool" { |
| + d.boxes[1].pools = []string{""} |
| + d.hosts[1].record.Pool = "hapair" |
| + } |
| + if scenario == "coverage" { |
| + d.hosts = append(d.hosts, &dutyHost{record: provision.DepartureHost{Host: "worker.example.com", Kind: "sidecar", Lifetime: "sidecar"}, lock: hafresh.View{Absent: true}}) |
| + } |
| + if scenario == "unsynced" { |
| + d.boxes[0].local[0] = map[string]dutyTimer{"unsynced": {Registration: 2, Due: 90}} |
| + } |
| + if scenario == "future" { |
| + for _, h := range d.hosts { |
| + x := h.wake["once"] |
| + x.Due = 5761 |
| + h.wake["once"] = x |
| + } |
| + } |
| + if scenario == "fixed" { |
| + d.group = false |
| + } |
| + if scenario == "owner" { |
| + for _, b := range d.boxes[1:] { |
| + b.local[0] = map[string]dutyTimer{"once": {Registration: 1, Due: 2}} |
| + } |
| + } |
| + d.terminate(0) |
| + if scenario == "missing-edges" { |
| + d.edges[0] = false |
| + } |
| + // Persist while Describe still knows D, then lose every process cache. |
| + d.advance(2) |
| + if scenario == "event" { |
| + for _, b := range d.boxes[1:] { |
| + if b.scans[0] == nil { |
| + d.fail("valid event did not enroll departure before age fallback") |
| + } |
| + } |
| + } |
| + if scenario == "early" { |
| + d.advance(1) |
| + for _, b := range d.boxes { |
| + b.source = d.now |
| + b.walk = d.now |
| + } |
| + } |
| + if scenario == "future" { |
| + d.storeDown = true |
| + d.now = 5760 |
| + for i := 1; i < len(d.boxes); i++ { |
| + d.restart(i) |
| + } |
| + d.storeDown = false |
| + } |
| + if scenario == "scanner-death" { |
| + d.advance(65) |
| + // First scanner dies after a partial import. Its independent registry |
| + // is unavailable, but its durable proof and shared lock remain. |
| + d.terminate(1) |
| + } |
| + if scenario == "delete-denied" { |
| + d.denyDelete = true |
| + } |
| + if scenario == "inventory" { |
| + d.boxes[1].walk = d.now + 1 |
| + d.boxes[1].source = 0 |
| + } |
| + d.advance(140) |
| + if scenario == "sequential" { |
| + owner := -1 |
| + for i, b := range d.boxes { |
| + if i != 0 && d.hosts[0].lock.Lock.Release.Box == b.self.Ref { |
| + owner = i |
| + } |
| + } |
| + if owner < 0 { |
| + d.fail("no completed first adopter") |
| + return |
| + } |
| + // Keep it asleep while two successive owners depart. |
| + for _, h := range d.hosts { |
| + x := h.wake["once"] |
| + x.Delivered = false |
| + x.Due = d.now + 200 |
| + h.wake["once"] = x |
| + } |
| + d.terminate(owner) |
| + d.advance(260) |
| + } |
| + if scenario == "duplicate-import" { |
| + for _, b := range d.boxes { |
| + for hi, rows := range b.local { |
| + if row, ok := rows["once"]; ok && row.Delivered { |
| + h := d.hosts[hi] |
| + old := h.wake["once"] |
| + old.Delivered = false |
| + if !on("replay-overwrites-delivered-timer") { |
| + rows["once"] = old |
| + d.fail("duplicate receipt replay resurrected delivered timer") |
| + } |
| + } |
| + } |
| + } |
| + } |
| + if scenario == "interim" { |
| + for _, b := range d.boxes { |
| + for hi, rows := range b.local { |
| + if _, ok := rows["once"]; ok { |
| + h := d.hosts[hi] |
| + h.wake["once"] = dutyTimer{Registration: 2, Due: d.now + 1} |
| + rows["once"] = dutyTimer{Registration: 1, Due: d.now + 1} |
| + } |
| + } |
| + } |
| + d.advance(3) |
| + } |
| + if scenario == "delete-denied" { |
| + for _, b := range d.boxes { |
| + if s := b.scans[0]; s != nil && (s.complete || s.ack) { |
| + d.fail("denied delete completed receiver") |
| + } |
| + } |
| + d.denyDelete = false |
| + d.advance(5) |
| + } |
| + if scenario == "coverage" { |
| + for _, b := range d.boxes { |
| + if b.alive { |
| + if !b.running { |
| + d.fail("coverage stopped consumer") |
| + } |
| + if s := b.scans[0]; s == nil || s.complete || s.ack { |
| + d.fail("unsupported departure lost pending state") |
| + } |
| + } |
| + } |
| + if d.deliveries != 3 { |
| + d.fail("blocked coverage starved supported tenant work") |
| + } |
| + } |
| + if scenario == "fixed" { |
| + if d.deletes != 0 || !d.edges[0] { |
| + d.fail("fixed ref edges deleted") |
| + } |
| + d.replacement[0] = true |
| + d.advance(3) |
| + if d.deletes != 0 || !d.edges[0] { |
| + d.fail("replacement edges deleted") |
| + } |
| + } |
| + if scenario == "pool" { |
| + for _, b := range d.boxes { |
| + if b.alive { |
| + s := b.scans[0] |
| + if s == nil || !s.complete { |
| + d.fail("heterogeneous receiver did not complete zero-match rescan") |
| + } |
| + } |
| + } |
| + } |
| + d.checkDelivered() |
| +} |
| + |
| +// Pool projection uses the production selector: the raw HRW winner without a |
| +// home host entry must not start a never-woken hapair host. |
| +func dutyPoolWitness(w *world) { |
| + d := newDutyWorld(w, 7) |
| + h := d.hosts[0] |
| + eligible := []string{d.boxes[1].self.Ref} |
| + for _, b := range d.boxes { |
| + input := activator.DutyInput{HA: true, Host: h.record.Host, Lifetime: h.record.Lifetime, Self: b.self, ViewKnown: true, Eligible: eligible, Observed: &hafresh.View{Absent: true}} |
| + if !on("hrw-ignores-pool") { |
| + input.Eligible = []string{b.self.Ref} |
| + } |
| + if activator.DecideDuty(input) == activator.DutyAttempt && b != d.boxes[1] { |
| + d.fail("never-woken hapair selected shared-only box") |
| + } |
| + } |
| +} |