64 lines
2.1 KiB
Go
64 lines
2.1 KiB
Go
//go:build integration
|
|
|
|
package main
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/novox/mesh-controller/internal/inventory"
|
|
"github.com/novox/mesh-controller/internal/link"
|
|
)
|
|
|
|
func TestARebuildInTheWaitIsNotTheWalksBuild(t *testing.T) {
|
|
open := aMesh(t)
|
|
ctx := t.Context()
|
|
asked := asksRecorded(t)
|
|
twoTiers(t, open)
|
|
created := time.Now().UTC().Add(-10 * time.Minute)
|
|
plan := inventory.Plan{ID: "plan-754", Repository: "novox/a", Branch: "main", Commit: "c0ffee", Created: created,
|
|
State: inventory.PlanBuilding, Tiers: [][]string{{"a", "b"}}, Modules: map[string]*inventory.PlanModule{},
|
|
Delivery: &inventory.PlanDelivery{Awaits: "mesh-delivery"}}
|
|
if err := open.inventory.SavePlan(ctx, &plan); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
// A rebuild of a, beside the waiting walk: not joined, and its outcome not taken.
|
|
joined, said, err := joinAPlan(ctx, open, "a")
|
|
if err != nil || joined || said == "" {
|
|
t.Fatalf("a rebuild joined a waiting walk: %v %q %v", joined, said, err)
|
|
}
|
|
planBuilt(ctx, open, "a", "c0ffee", "", time.Now().UTC(), "build-rebuild")
|
|
p, _ := open.inventory.PlanByID(ctx, plan.ID)
|
|
if s := p.Modules["a"]; s != nil && s.State != "" {
|
|
t.Fatalf("the waiting walk took a rebuild as its build: %+v", s)
|
|
}
|
|
if len(*asked) != 0 {
|
|
t.Fatalf("a waiting walk asked %v", *asked)
|
|
}
|
|
|
|
// Let go: both are asked, and their outcomes complete the tier.
|
|
if _, err := letGo(ctx, open.inventory, plan.ID, "operator", "test"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
advancePlans(ctx, open)
|
|
p, _ = open.inventory.PlanByID(ctx, plan.ID)
|
|
for _, m := range []string{"a", "b"} {
|
|
if s := p.Modules[m]; s == nil || s.State != "asked" || s.Build == "" {
|
|
t.Fatalf("let go, %s is %+v", m, s)
|
|
}
|
|
}
|
|
if len(*asked) != 2 {
|
|
t.Fatalf("asked %v", *asked)
|
|
}
|
|
for _, m := range []string{"a", "b"} {
|
|
id := p.Modules[m].Build
|
|
at, _ := link.BuildAskedAt(id)
|
|
planBuilt(ctx, open, m, "c0ffee", "", at, id)
|
|
}
|
|
advancePlans(ctx, open)
|
|
if p, _ = open.inventory.PlanByID(ctx, plan.ID); p.Open() && p.Tier == 0 {
|
|
t.Fatalf("the walk did not get past its tier: %s at %d, %q", p.State, p.Tier, p.Note)
|
|
}
|
|
}
|