package main import ( "testing" "time" "github.com/novox/mesh-controller/internal/inventory" ) // novox/hq issue 213: for the moment a machine hands its controller over, the container and the // process both run the plan timer on one store. Only the one holding the plans moves them; the other // leaves them alone, and moves them once they are let go. func TestAControllerLeavesThePlansToTheOneHoldingThem(t *testing.T) { open := aMesh(t) ctx := t.Context() now := time.Now().UTC() // Every tier done: the next step is the plan's last, and needs nothing but the store. plan := inventory.Plan{ID: "plan-213", Repository: "r", Commit: "abc", Created: now, Updated: now, State: inventory.PlanRolling, Tier: 1, Tiers: [][]string{{"app"}}, Modules: map[string]*inventory.PlanModule{"app": {State: "built"}}} if err := open.inventory.SavePlan(ctx, &plan); err != nil { t.Fatal(err) } // The other controller: its own connections to the same store, holding the plans. other, err := inventory.Open(ctx) if err != nil { t.Fatal(err) } t.Cleanup(other.Close) release, err := other.HoldPlans(ctx, false) if err != nil { t.Fatal(err) } t.Cleanup(release) // before the close above: a pool waits for a connection still held advancePlans(ctx, open) if p, err := open.inventory.PlanByID(ctx, "plan-213"); err != nil || !p.Open() { t.Fatalf("a controller moved a plan another held: %+v %v", p, err) } release() advancePlans(ctx, open) if p, err := open.inventory.PlanByID(ctx, "plan-213"); err != nil || p.State != inventory.PlanDone { t.Fatalf("the plan did not move once it was let go: %+v %v", p, err) } }