A3c entries-kept-while-named: a catalog revision taken in releases only the entries no want or running names; the tests wait on events, not the clock

Builds: design 47 H2 H-A-757 (amends H-A-682 (2)), H-A-708 (3)
This commit is contained in:
2026-11-25 19:08:14 +01:00
parent 63b44f8c37
commit 530f6c9204
6 changed files with 73 additions and 33 deletions
@@ -158,9 +158,11 @@ func TestTheCompositionStepComposesEachMachineThroughTheBuildSeat(t *testing.T)
outage := b.journal.mark()
putStep(b.ctx, t, b.js, "step-ask-1", meshwants.StepRun{Pipeline: "main.3.m", Step: meshwants.StepRunStepComposition, Module: "m", Branch: trunkBranch,
Revision: 3, Commit: engineCommit, Fingerprint: "src2:m1"})
// The kept call's own journal line goes to the process's standard error, so the outage is a few seconds of the clock, over which
// the step must go no further.
time.Sleep(3 * time.Second)
select { // the read met the stopped holder, and the step has gone no further
case <-b.cat.met:
case <-time.After(30 * time.Second):
t.Fatal("no read reached the stopped seat mesh-catalog")
}
if b.journal.has(outage, "the composition step of m says fetch") {
t.Fatal("the step went on while the seat mesh-catalog's holder was stopped")
}
@@ -54,11 +54,13 @@ func (h *halves) follow() error {
h.changed(branch, module, entry, deleted)
}
b.Adopted = h.adopted
// An entry read by fingerprint is kept until the next catalog revision taken in (design 47 H2 H-A-682 (2)): each revision
// held releases them, and a want at an older fingerprint asks its entry again.
// An entry read by fingerprint never changes: each catalog revision taken in releases only the entries that no want and no
// `running` the assigner holds names any more (design 47 H2 H-A-757, amending H-A-682 (2)).
b.Held = func(string, meshcatalog.CatalogRevision) {
for _, r := range b.Entries.Rows() {
b.Entries.Release(r.Fingerprint)
if !h.w.namesFingerprint(r.Fingerprint) {
b.Entries.Release(r.Fingerprint)
}
}
}
// The one handler of registration-changed is the follower's (H-A-270 (3)): the pipeline ends are told each change from it,
@@ -4,7 +4,10 @@ import (
"context"
"encoding/json"
"errors"
mwc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshwantsclient"
"mesh-delivery-assigner/internal/buckets"
"slices"
"strings"
"testing"
"time"
@@ -107,7 +110,7 @@ func TestAModulesWatchedBranchesAreItsRegistrations(t *testing.T) {
}
// H-A-682 (2): the entries read by fingerprint are kept until the next catalog revision the assigner takes in, and each revision
// held releases them.
// held releases those no want or running names (H-A-757).
func TestACatalogRevisionTakenInReleasesTheEntriesKept(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel()
@@ -124,14 +127,20 @@ func TestACatalogRevisionTakenInReleasesTheEntriesKept(t *testing.T) {
}
answered := make(chan struct{}, 1)
h.branches.Entries.Changed = func(mcc.EntryRow) { answered <- struct{}{} }
h.branches.Entries.Need(ctx, "src2:old")
select {
case <-answered:
case <-ctx.Done():
t.Fatal("the entry is never answered")
old := mcc.SourcePrefix2 + strings.Repeat("a", 64)
for _, fp := range []string{old, "src2:unnamed"} {
h.branches.Entries.Need(ctx, fp)
select {
case <-answered:
case <-ctx.Done():
t.Fatal("the entry is never answered")
}
}
raw, _ := mwc.EncodeWant(mwc.Want{Fp: old, Version: "1.0.0"})
key, _ := mwc.WantKey("g14", "web")
h.w.putEntry(buckets.Wants(), key, raw, 1, time.Now())
h.branches.Held("main", seat.CatalogRevision{Branch: "main", Revision: 2})
if rows := h.branches.Entries.Rows(); len(rows) != 0 {
t.Errorf("a catalog revision taken in leaves the entries kept: %+v", rows)
if rows := h.branches.Entries.Rows(); len(rows) != 1 || rows[0].Fingerprint != old {
t.Errorf("a catalog revision taken in keeps %+v, want the entry a want names and releases the one nothing names", rows)
}
}
@@ -21,6 +21,7 @@ import (
"slices"
"strings"
"sync"
"sync/atomic"
"testing"
"time"
@@ -100,6 +101,8 @@ type catalogBed struct {
at map[string]map[int64][]meshcatalog.CatalogEntry
// stop makes the seat's holder unheard, as a holder stopped is (no responders); serve makes it heard again (serveCatalog).
stop, serve func()
// met says a call reached the holder while it was stopped.
met chan struct{}
}
// journal is a program's journal as the bed hears it: a test awaits a line in it (await) where the line is the only sign
@@ -1858,27 +1861,30 @@ func serveCatalog(t *testing.T, b *bed, nc *nats.Conn) {
}
_ = m.Respond([]byte(`{"error":"no catalog entry has the fingerprint ` + in.Fingerprint + `","node":"n0"}`))
}
var subs []*nats.Subscription
b.cat.serve = func() {
for subject, handler := range map[string]nats.MsgHandler{"mesh.seat.mesh-catalog.tool.revision": answer, "mesh.seat.mesh-catalog.call.revision.*": answer,
"mesh.seat.mesh-catalog.tool.revision.*": answer, "mesh.seat.mesh-catalog.tool.entry": entry, "mesh.seat.mesh-catalog.call.entry.*": entry} {
sub, err := nc.Subscribe(subject, handler)
if err != nil {
t.Fatal(err)
// A holder stopped answers each call as the bus does a subject nobody serves, no responders, and says it met one (b.cat.met).
var down atomic.Bool
b.cat.met = make(chan struct{}, 16)
b.cat.stop = func() { down.Store(true) }
b.cat.serve = func() { down.Store(false) }
for subject, handler := range map[string]nats.MsgHandler{"mesh.seat.mesh-catalog.tool.revision": answer, "mesh.seat.mesh-catalog.call.revision.*": answer,
"mesh.seat.mesh-catalog.tool.revision.*": answer, "mesh.seat.mesh-catalog.tool.entry": entry, "mesh.seat.mesh-catalog.call.entry.*": entry} {
sub, err := nc.Subscribe(subject, func(m *nats.Msg) {
if down.Load() {
select {
case b.cat.met <- struct{}{}:
default:
}
_ = m.RespondMsg(&nats.Msg{Header: nats.Header{"Status": []string{"503"}}})
return
}
subs = append(subs, sub)
handler(m)
})
if err != nil {
t.Fatal(err)
}
subscribed(t, nc)
t.Cleanup(func() { _ = sub.Unsubscribe() })
}
b.cat.stop = func() {
for _, sub := range subs {
_ = sub.Unsubscribe()
}
subs = nil
_ = nc.Flush()
}
b.cat.serve()
t.Cleanup(b.cat.stop)
subscribed(t, nc)
}
// A-181: the assigner reads the builder's stream of build ends whole at its start (the last of each fingerprint, a failed one's error
@@ -13,6 +13,7 @@ import (
"mesh-delivery-assigner/internal/puts"
"os"
"path/filepath"
"runtime"
"slices"
"strings"
"testing"
@@ -1105,7 +1106,7 @@ func TestTheWhyOfAWantAwaitingItsEntryNamesTheAsk(t *testing.T) {
if time.Now().After(deadline) {
t.Fatal("the ask never failed")
}
time.Sleep(time.Millisecond) // the ask runs on its own goroutine
runtime.Gosched() // the ask runs on its own goroutine
}
held := mwc.Want{Fp: fp, Hold: true, Words: mwc.HoldAwaitsEntryPrefix + fp}
p.sayWhy(context.Background(), "m", []string{"ace"}, wantWhy{Branch: "main", Fp: fp, Step: whyPassed}, nil, &assign.Outcome{Wants: map[string]mwc.Want{"ace": held}})
@@ -362,6 +362,26 @@ func (w *world) online() map[string]bool {
return out
}
// namesFingerprint says whether a want the assigner wrote or a `running` it holds names fp: the entry at fp is still read by it
// (design 47 H2 H-A-757).
func (w *world) namesFingerprint(fp string) bool {
for _, nodes := range w.wantsOf() {
for _, want := range nodes {
if want.Fp == fp {
return true
}
}
}
w.mu.Lock()
defer w.mu.Unlock()
for _, r := range w.running {
if r.Fingerprint == fp {
return true
}
}
return false
}
// wantsOf is the wants the assigner wrote, by module then node.
func (w *world) wantsOf() map[string]map[string]mwc.Want {
out := map[string]map[string]mwc.Want{}