package main import ( "context" "errors" "testing" "github.com/novox/mesh-controller/internal/lease" ) // Two controllers at once (novox/hq to-be 45 §6, issue 204; the half of replay R1 that lives here): two // serving controllers over one store and one bus. The second waits while the first holds the lease; on // a handover it takes it at a higher epoch, the record says which held what and how each ended; and the // one that lost it acts no more — no declaration composed, no plan and no condition written — the // moment it lost it. // // MESH_TEST_POSTGRES=… go test ./cmd/mesh-controller/ -run Controllers (each test on a bus of its own: internal/testbus) // aBusForTheLease is the test bus with the controller's lease bucket new. // A controller whose bus refuses it the lease's key, with nobody holding it, serves without the lease: // it acts with no epoch — refused by no node-engine — says so, and takes the lease once it can. func TestAControllerTheBusRefusesTheLeaseServesUnleasedAndSaysSo(t *testing.T) { a := &actor{serving: true, unleased: "the bus refused the lease's key"} if epoch, err := a.epoch(context.Background()); err != nil || epoch != 0 { t.Fatalf("an unleased controller answers %d, %v: it acts, claiming no epoch", epoch, err) } if st := a.standing(); st.Unleased == "" || st.Held { t.Fatalf("its standing says %+v", st) } // One that neither holds nor is unleased — still waiting — acts on nothing. waiting := &actor{serving: true} if _, err := waiting.epoch(context.Background()); !errors.Is(err, lease.ErrNotHeld) { t.Fatalf("a controller waiting for the lease may act: %v", err) } }