74 lines
3.5 KiB
Go
74 lines
3.5 KiB
Go
package main
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
sdk "git.novox.be/novox/mesh-sdk/go/delivery"
|
|
)
|
|
|
|
// 1280 (novox/hq ADR 0556 clause 4): `deliveries` and `show` say for a merged delivery whether it is on the machines, derived
|
|
// when asked from the view's reach and the gate's own order of merges: at or before the reached head it is, after it not yet
|
|
// and why; a repository the view has no reach of, or a reached head the gate holds no merge of, is not known. Nothing records it.
|
|
func TestAMergedDeliverySaysWhetherItIsOnTheMachines(t *testing.T) {
|
|
w := newWorld(t)
|
|
at := w.now.Add(-3 * time.Hour)
|
|
merge := func(commit string, n int) *Delivery {
|
|
d := &Delivery{ID: "novox/web@" + commit[:12], Repository: "novox/web", Commit: commit[:12], Number: n, State: Merged,
|
|
Since: at, MergedAs: strings.Repeat(commit[:1], 40), MergedAt: at.Add(time.Duration(n) * time.Minute)}
|
|
w.h.mu.Lock()
|
|
w.h.keep(d)
|
|
w.h.mu.Unlock()
|
|
return d
|
|
}
|
|
first, second, third := merge("111111111111", 1), merge("222222222222", 2), merge("333333333333", 3)
|
|
reach := func(r sdk.Reach) {
|
|
key, _ := sdk.RepositoryKey(r.Repository)
|
|
raw, err := sdk.EncodeReach(r)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
w.h.ReachChanged(key, raw, false)
|
|
}
|
|
machines := func(d *Delivery) string { w.h.mu.Lock(); defer w.h.mu.Unlock(); return w.h.machines(d) }
|
|
if got := machines(first); !strings.HasPrefix(got, notKnownWhere) {
|
|
t.Errorf("with no reach: %q", got)
|
|
}
|
|
reach(sdk.Reach{Repository: "novox/web", Reached: second.MergedAs, ReachedSrc: 7, Holds: []string{"web on g14 runs the build of 2222, not yet that of 3333"}})
|
|
for d, want := range map[*Delivery]string{first: onMachines, second: onMachines, third: notYetOn + "web on g14"} {
|
|
if got := machines(d); !strings.HasPrefix(got, want) {
|
|
t.Errorf("%s: %q, want %q", d.ID, got, want)
|
|
}
|
|
}
|
|
reach(sdk.Reach{Repository: "novox/web", Reached: strings.Repeat("9", 40), ReachedSrc: 8})
|
|
if got := machines(first); !strings.Contains(got, "no merge this gate holds") {
|
|
t.Errorf("a reached head the gate holds no merge of: %q", got)
|
|
}
|
|
reach(sdk.Reach{Repository: "novox/web", Holds: []string{"web on ace runs nothing yet"}})
|
|
if got := machines(first); got != notYetOn+"web on ace runs nothing yet" {
|
|
t.Errorf("no reached head: %q", got)
|
|
}
|
|
// A module a node wants and runs nothing countable of holds no head back, and a merge that changed it is not yet there.
|
|
reach(sdk.Reach{Repository: "novox/web", Reached: third.MergedAs, ReachedSrc: 9, Modules: map[string]sdk.ModuleReach{
|
|
"web": {FP: "src2:x", Nodes: 1, Waiting: "web on g14 runs nothing yet", Changes: []sdk.Change{{Commit: second.MergedAs, FP: "src2:x"}}}}})
|
|
for d, want := range map[*Delivery]string{first: onMachines, second: notYetOn + "web on g14 runs nothing yet", third: onMachines} {
|
|
if got := machines(d); got != want {
|
|
t.Errorf("with a module running nowhere countable, %s: %q, want %q", d.ID, got, want)
|
|
}
|
|
}
|
|
// The verbs say it; a delivery not merged says nothing of the machines.
|
|
reach(sdk.Reach{Repository: "novox/web", Reached: third.MergedAs, ReachedSrc: 9})
|
|
lines := w.h.Deliveries("", "novox/web", "", true)
|
|
if len(lines) != 3 || lines[0].Machines != onMachines {
|
|
t.Errorf("deliveries = %+v", lines)
|
|
}
|
|
shown, err := w.h.Show(third.ID)
|
|
if err != nil || shown.(map[string]any)["machines"] != onMachines {
|
|
t.Errorf("show = %v, %v", shown, err)
|
|
}
|
|
if got := machines(&Delivery{State: Held, MergedAs: "x", Repository: "novox/web"}); got != "" {
|
|
t.Errorf("a held delivery says %q of the machines", got)
|
|
}
|
|
}
|