116 lines
6.9 KiB
Go
116 lines
6.9 KiB
Go
package index
|
|
|
|
import (
|
|
"context"
|
|
"slices"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
mcc "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient"
|
|
"git.novox.be/novox/mesh-delivery/contracts/go/clients/meshcatalogclient"
|
|
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
|
)
|
|
|
|
// fakeBounds is the state hold-bounds: the end each key was armed with, a standing key keeping its end.
|
|
type fakeBounds map[string]time.Time
|
|
|
|
func (b fakeBounds) Arm(_ context.Context, key string, ends time.Time) error {
|
|
if _, standing := b[key]; !standing {
|
|
b[key] = ends
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (b fakeBounds) Disarm(_ context.Context, key string) error { delete(b, key); return nil }
|
|
|
|
// ADR 0632 §2, ADR 0624 §1, a case of TestAMergedManifestIsKeptOnceByItsDigestAndNamedByTheModule. The store holder's
|
|
// new manifest, which every node-engine reads to find the store, keeps the entry at the old manifest while one counted
|
|
// node states only the baseline reads (the event manifest-reads-changed not yet heard of it, and the hold asked again by
|
|
// a person), and moves once every counted node states form:seat-reach. docker, whose manifest stays the same while its
|
|
// template newly names the image seat's reach (the needs the forge bridge carries), is held the same way. A hold's bound
|
|
// is a key of hold-bounds; past it the finding manifest-held names n2, cleared when the hold moves; a move by a person's
|
|
// word names the node it strands.
|
|
func storeHoldersNewManifestWaitsForEveryCountedEngine(t *testing.T) {
|
|
ctx := context.Background()
|
|
const dir, dockerDir = "modules/distribution", "modules/docker"
|
|
old := `{"module":"distribution","version":"1","listens":[{"name":"registry","port":5000,"from":"mesh"}]}`
|
|
next := `{"module":"distribution","version":"1","claims":[{"name":"container-image-registry","scope":"mesh"}],` +
|
|
`"listens":[{"name":"registry","port":5000,"from":"mesh"}]}`
|
|
docker := `{"module":"docker","version":"1","resources":[{"id":"daemon","type":"file","path":"/etc/docker/daemon.json","template":"files/daemon.json"}]}`
|
|
dockerNeeds, _ := catalogue.ModuleNeeds([]byte(docker), map[string]string{"files/daemon.json": `"${seat:container-image-registry:reach}"`})
|
|
if needs, _ := catalogue.ManifestNeeds([]byte(next)); !slices.Contains(needs, "form:seat-reach") || !slices.Contains(dockerNeeds, "form:seat-reach") {
|
|
t.Fatalf("the new manifest needs %v and docker's %v, want form:seat-reach in both (mesh-sdk ecdbf1a, ModuleNeeds)", needs, dockerNeeds)
|
|
}
|
|
ix, mods, _ := manifestsIndexer(t)
|
|
holds, findings, bounds := newMem(), newMem(), fakeBounds{}
|
|
stated := map[string][]string{"n1": catalogue.ManifestReads(), "n2": nil} // n2: an engine before the statement, the baseline
|
|
var asked []string
|
|
clock := time.Date(2026, 11, 4, 21, 0, 0, 0, time.UTC)
|
|
ix.Holds, ix.Findings, ix.HoldBounds, ix.Now = holds, findings, bounds, func() time.Time { return clock }
|
|
ix.Counted = func() (map[string][]string, bool) { return stated, true }
|
|
ix.AskEngines = func(nodes []string, _ string) { asked = append(asked, nodes...) }
|
|
heldKey := mcc.Key(mcc.ScopeModule, findingID("hold", "distribution"), HoldStandingKind)
|
|
|
|
first := withManifests(mergedMsg(catalogueRepo, map[string]string{dir: "tree1", dockerDir: "d1"}), map[string]string{dir: old, dockerDir: docker}, nil)
|
|
if err := ix.Apply(ctx, first); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
kept, _ := moduleOf(t, mods, "distribution")
|
|
keptDocker, _ := moduleOf(t, mods, "docker")
|
|
if kept.Manifest != meshcatalogclient.ManifestDigest([]byte(old)) || len(holds.vals) != 0 {
|
|
t.Fatalf("after the first merge modules.distribution names %s with %d holds, want the old manifest and none", kept.Manifest, len(holds.vals))
|
|
}
|
|
second := withManifests(mergedMsg(catalogueRepo, map[string]string{dir: "tree2", dockerDir: "d2"}), map[string]string{dir: next, dockerDir: docker}, nil)
|
|
second.Needs = map[string][]string{dockerDir: dockerNeeds}
|
|
second.Merge = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
|
|
if err := ix.Apply(ctx, second); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
stays := func(when string) {
|
|
t.Helper()
|
|
m, _ := moduleOf(t, mods, "distribution")
|
|
if m.Manifest != kept.Manifest || m.Fp2 != kept.Fp2 || m.Commit != kept.Commit || m.Inputs2 == nil || m.Inputs2.Tree != "tree1" {
|
|
t.Fatalf("%s modules.distribution = manifest %s fp2 %q commit %s, want the old entry kept whole (%s, %q, %s)",
|
|
when, m.Manifest, m.Fp2, m.Commit, kept.Manifest, kept.Fp2, kept.Commit)
|
|
}
|
|
h, err := DecodeHold(holds.vals["distribution"])
|
|
if err != nil || h.Manifest != meshcatalogclient.ManifestDigest([]byte(next)) || h.Kept != kept.Manifest || !slices.Equal(h.Lacking["n2"], []string{"form:seat-reach"}) || len(h.Lacking) != 1 {
|
|
t.Fatalf("%s holds.distribution = %+v (%v), want the new manifest held, n2 alone lacking form:seat-reach", when, h, err)
|
|
}
|
|
}
|
|
stays("with n2 stating only the baseline,")
|
|
if d, _ := moduleOf(t, mods, "docker"); d.Inputs2 == nil || d.Inputs2.Tree != keptDocker.Inputs2.Tree || holds.vals["docker"] == nil {
|
|
t.Fatalf("docker's template naming the seat's reach: modules.docker at tree %v, holds %v; want its old entry kept and a hold", d.Inputs2, holds.vals["docker"])
|
|
}
|
|
if r := ix.HoldAgain(ctx, "distribution", false, "op@shanks"); !r.Held || r.Stored || !slices.Equal(asked, []string{"n2"}) {
|
|
t.Fatalf("asked again: %+v, engines asked %v; want it held and n2's engine asked again", r, asked)
|
|
}
|
|
stays("asked again with n2 still stating only the baseline,")
|
|
if len(findings.vals) != 0 || !bounds["distribution"].Equal(clock.Add(HoldBound)) {
|
|
t.Fatalf("within its bound: findings %v, bounds %v; want none and hold-bounds.distribution ending at %v", findings.vals, bounds, clock.Add(HoldBound))
|
|
}
|
|
clock = clock.Add(HoldBound)
|
|
if err := ix.MoveHolds(ctx); err != nil { // what the key's expiry asks (HoldBoundEnded, in the background)
|
|
t.Fatal(err)
|
|
}
|
|
stays("past its bound,")
|
|
f, err := mcc.DecodeFinding(findings.vals[heldKey])
|
|
if err != nil || f.Kind != HoldStandingKind || !strings.Contains(f.Summary, "n2 lacks form:seat-reach") {
|
|
t.Fatalf("past its bound the finding %s = %+v (%v), want manifest-held naming n2", heldKey, f, err)
|
|
}
|
|
|
|
if r := ix.HoldAgain(ctx, "docker", true, "op@shanks"); !r.Stored || !strings.Contains(r.Answer, "strands n2") {
|
|
t.Fatalf("docker moved by hand: %+v, want it moved and its answer naming n2 stranded", r)
|
|
}
|
|
stated["n2"] = catalogue.ManifestReads() // n2's engine states the reading (manifest-reads-changed)
|
|
if err := ix.MoveHolds(ctx); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
m, _ := moduleOf(t, mods, "distribution")
|
|
if m.Manifest != meshcatalogclient.ManifestDigest([]byte(next)) || m.Commit != second.Merge || m.Inputs2 == nil || m.Inputs2.Tree != "tree2" || len(holds.vals) != 0 || findings.vals[heldKey] != nil || len(bounds) != 0 {
|
|
t.Fatalf("once every counted engine states form:seat-reach modules.distribution = manifest %s commit %s, %d holds, finding %s, bounds %v; want the new entry and none",
|
|
m.Manifest, m.Commit, len(holds.vals), findings.vals[heldKey], bounds)
|
|
}
|
|
}
|