71 lines
2.8 KiB
Go
71 lines
2.8 KiB
Go
//go:build integration
|
|
|
|
package main
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/novox/mesh-controller/internal/inventory"
|
|
)
|
|
|
|
func TestASendHeldForTheBusStepIsFoundFromTheWalksItHolds(t *testing.T) {
|
|
now := time.Date(2026, 10, 8, 18, 30, 0, 0, time.UTC)
|
|
b := aBusOnAnchor()
|
|
walk := func(id, repo, note string, updated time.Time) inventory.Plan {
|
|
return inventory.Plan{ID: id, Repository: repo, Commit: "c0ffee001122", State: inventory.PlanRolling, Tier: 0,
|
|
Tiers: [][]string{{"mesh-host"}}, Modules: map[string]*inventory.PlanModule{"mesh-host": {}}, Note: note,
|
|
Updated: updated}
|
|
}
|
|
for _, c := range []struct {
|
|
name string
|
|
bus busPending
|
|
plans []inventory.Plan
|
|
first map[string]time.Time
|
|
want []string
|
|
since time.Time
|
|
}{
|
|
{"a walk refused for the bus", b,
|
|
[]inventory.Plan{walk("plan-1", "novox/mesh-host", refusedNote(b, 0), now.Add(-27*time.Minute))}, nil,
|
|
[]string{"plan-1"}, now.Add(-27 * time.Minute)},
|
|
{"refused earlier than its last save, as this controller saw it", b,
|
|
[]inventory.Plan{walk("plan-1", "novox/mesh-host", refusedNote(b, 0), now.Add(-5*time.Minute))},
|
|
map[string]time.Time{"plan-1": now.Add(-28 * time.Minute)}, []string{"plan-1"}, now.Add(-28 * time.Minute)},
|
|
{"a walk refused for another reason", b,
|
|
[]inventory.Plan{walk("plan-1", "novox/mesh-host", "tier 0: the build seat is paused — tried again", now)}, nil,
|
|
nil, time.Time{}},
|
|
{"refused for an older bus build than the one held now", func() busPending { o := b; o.to = "99999999cccc"; return o }(),
|
|
[]inventory.Plan{walk("plan-1", "novox/mesh-host", refusedNote(b, 0), now)}, nil, nil, time.Time{}},
|
|
{"the bus already runs the build held: its step started", func() busPending {
|
|
o := aBusOnAnchor()
|
|
o.from = map[string]string{"anchor": o.to}
|
|
return o
|
|
}(), []inventory.Plan{walk("plan-1", "novox/mesh-host", refusedNote(b, 0), now)}, nil, nil, time.Time{}},
|
|
{"a walk waiting for its delivery's word asks no send", b, func() []inventory.Plan {
|
|
p := walk("plan-1", "novox/mesh-host", refusedNote(b, 0), now)
|
|
p.Delivery = &inventory.PlanDelivery{Awaits: "mesh-delivery"}
|
|
return []inventory.Plan{p}
|
|
}(), nil, nil, time.Time{}},
|
|
} {
|
|
t.Run(c.name, func(t *testing.T) {
|
|
got := busWaitsOf(c.plans, c.bus, func(id string) time.Time { return c.first[id] })
|
|
var ids []string
|
|
for _, w := range got.waits {
|
|
ids = append(ids, w.plan)
|
|
}
|
|
if strings.Join(ids, ",") != strings.Join(c.want, ",") {
|
|
t.Fatalf("held for the bus: %v, want %v", ids, c.want)
|
|
}
|
|
if len(c.want) > 0 {
|
|
if !got.waits[0].since.Equal(c.since) {
|
|
t.Errorf("waiting since %s, want %s", got.waits[0].since, c.since)
|
|
}
|
|
if strings.Join(got.machines, ",") != "anchor" || got.to != b.to || got.module != "nats" {
|
|
t.Errorf("behind %+v", got)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|