Design 47 H: a passed pipeline whose movers' versions arrive late still writes its wants (H-A-270, H-A-273, H-A-277) #317
@@ -37,6 +37,10 @@ type halves struct {
|
||||
// settled is told once when the first watched branch's first view is answered, for the first pass to wait on.
|
||||
settled chan<- struct{}
|
||||
told bool
|
||||
|
||||
// regMu orders the registrations told to registered: the ones held when it is set, then each change (H-A-270 (3)).
|
||||
regMu sync.Mutex
|
||||
registered func(reg meshcatalog.Registration, gone bool)
|
||||
}
|
||||
|
||||
// follow makes the branch follower on the reader; the reader's start asks the first views.
|
||||
@@ -50,6 +54,15 @@ func (h *halves) follow() error {
|
||||
h.changed(branch, module, entry, deleted)
|
||||
}
|
||||
b.Adopted = h.adopted
|
||||
// The one handler of registration-changed is the follower's (H-A-270 (3)): the pipeline ends are told each change from it,
|
||||
// never from a second handler on the hub.
|
||||
reconcile := b.Registrations.Follower.Changed
|
||||
b.Registrations.Follower.Changed = func(module string, value json.RawMessage, gone bool, at time.Time) {
|
||||
if reconcile != nil {
|
||||
reconcile(module, value, gone, at)
|
||||
}
|
||||
h.tellRegistration(module, value, gone)
|
||||
}
|
||||
h.mu.Lock()
|
||||
h.branches = b
|
||||
h.mu.Unlock()
|
||||
@@ -215,3 +228,39 @@ func (h *halves) watchedOf(module string) []string {
|
||||
slices.SortStableFunc(out, func(x, y string) int { return strings.Compare(keys.EscapeName(x), keys.EscapeName(y)) })
|
||||
return out
|
||||
}
|
||||
|
||||
// tellRegistration tells registered of one registration the follower holds now, or of one removed.
|
||||
func (h *halves) tellRegistration(module string, value json.RawMessage, gone bool) {
|
||||
h.regMu.Lock()
|
||||
defer h.regMu.Unlock()
|
||||
if h.registered == nil {
|
||||
return
|
||||
}
|
||||
reg := meshcatalog.Registration{Module: module}
|
||||
if !gone {
|
||||
if err := json.Unmarshal(value, ®); err != nil {
|
||||
h.logf("the registration of %s does not read: %v", module, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
h.registered(reg, gone)
|
||||
}
|
||||
|
||||
// followRegistrations tells registered of every registration the branch follower holds and then of each change it takes
|
||||
// (design 47 G §353): the registrations are followed once, by the follower's one handler of registration-changed (H-A-270
|
||||
// (3)). It says false when no follower is made.
|
||||
func (h *halves) followRegistrations(registered func(meshcatalog.Registration, bool)) bool {
|
||||
h.mu.Lock()
|
||||
b := h.branches
|
||||
h.mu.Unlock()
|
||||
if b == nil || b.Registrations == nil {
|
||||
return false
|
||||
}
|
||||
h.regMu.Lock()
|
||||
defer h.regMu.Unlock()
|
||||
h.registered = registered
|
||||
for _, reg := range b.Registrations.All() {
|
||||
registered(reg, false)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -53,6 +53,7 @@ func TestAMeshThatNamesNoBranchSettlesTheAssignersFirstPass(t *testing.T) {
|
||||
|
||||
// Design 47 H-A-143, H-A-144, G §532: a module's watched branches are its registration's, in its order; once registrations are held a
|
||||
// module none names has none; before the first registrations the gate's source's branches stand in, in the source's order.
|
||||
// H-A-270 (3): the pipeline ends are told the registrations by the same follower, whether set before its first view or after.
|
||||
func TestAModulesWatchedBranchesAreItsRegistrations(t *testing.T) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||
defer cancel()
|
||||
@@ -81,11 +82,23 @@ func TestAModulesWatchedBranchesAreItsRegistrations(t *testing.T) {
|
||||
if err := h.follow(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var live, held []string
|
||||
if !h.followRegistrations(func(reg seat.Registration, gone bool) { live = append(live, reg.Module) }) {
|
||||
t.Fatal("no follower of the registrations")
|
||||
}
|
||||
for _, f := range reader.Followers()[:2] { // the registrations and the gate's source
|
||||
if err := f.Start(ctx); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
h.followRegistrations(func(reg seat.Registration, gone bool) { held = append(held, reg.Module) })
|
||||
var regs []string
|
||||
for _, r := range tc.regs {
|
||||
regs = append(regs, r.Module)
|
||||
}
|
||||
if !slices.Equal(live, regs) || !slices.Equal(held, regs) {
|
||||
t.Errorf("the ends were told %v at the first view and %v held, want %v", live, held, regs)
|
||||
}
|
||||
if got := h.watchedOf(tc.module); !slices.Equal(got, tc.want) {
|
||||
t.Errorf("the watched branches of %s are %v, want %v", tc.module, got, tc.want)
|
||||
}
|
||||
|
||||
@@ -880,6 +880,14 @@ func TestWantsAreWrittenAndNoDifferenceIs(t *testing.T) {
|
||||
if _, err := b.buckets[engineReadsBucket()].Get(b.ctx, "shanks"); err == nil {
|
||||
t.Error("the state engine-reads holds a key of shanks, whose engine said nothing")
|
||||
}
|
||||
// H-A-270 (3): registration-changed has one handler, the catalog half's follower, so the start's hub refuses no overlap.
|
||||
b.journal.await(t, 0, "the kept seat events heard", "the hub started", time.Second)
|
||||
b.journal.mu.Lock()
|
||||
overlap := strings.Contains(b.journal.text.String(), "a message has one taker")
|
||||
b.journal.mu.Unlock()
|
||||
if overlap {
|
||||
t.Error("the start's hub refused a handler that overlaps another: a message has one taker")
|
||||
}
|
||||
}
|
||||
|
||||
// subscribed returns once the server holds every subscription nc made: nats.go sends a SUB from its flusher, after
|
||||
|
||||
@@ -649,12 +649,12 @@ func follow(ctx context.Context, js jetstream.JetStream, nc process.Subscriber,
|
||||
p.ends = newPipelineEnds(kvEnds{ctx, kv}, wake, logger.Printf)
|
||||
p.ends.trunk = w.trunkName
|
||||
p.ends.runEnded = func(group string) error { return p.dropCandidate(ctx, group) }
|
||||
err := hearEnds(hub, p.ends)
|
||||
if err == nil && bus != nil {
|
||||
err = followRegistrations(ctx, hub, bus.Call, p.ends)
|
||||
if err := hearEnds(hub, p.ends); err != nil {
|
||||
logger.Printf("a pipeline's end is not heard, so the wants keep the trunk-only form until the assigner starts again: %v", err)
|
||||
}
|
||||
if err != nil {
|
||||
logger.Printf("a pipeline's end or a registration is not heard, so the wants keep the trunk-only form until the assigner starts again: %v", err)
|
||||
// The registrations come from the catalog half's one follower, its one handler of registration-changed (H-A-270 (3)).
|
||||
if iv == nil || iv.h == nil || !iv.h.followRegistrations(p.ends.registered) {
|
||||
logger.Printf("the registrations are not followed, so the wants keep the trunk-only form until the assigner starts again: the catalog half is not followed")
|
||||
}
|
||||
}
|
||||
hearReleases(ctx, js, w, wake, findings, logger.Printf) // version-released, machine-away and machine-back
|
||||
|
||||
@@ -14,7 +14,6 @@ import (
|
||||
|
||||
"github.com/nats-io/nats.go/jetstream"
|
||||
|
||||
mcc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||
mprc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshpipelinerunnerclient"
|
||||
mpcat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
mpr "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner"
|
||||
@@ -161,22 +160,33 @@ func newPipelineEnds(st endStore, wake func(), logf func(string, ...any)) *pipel
|
||||
|
||||
// take keeps, for each mover of a passed pipeline that released a version, that version as the newest of its module on the
|
||||
// pipeline's branch, by compare-and-set on a newer version (design 47 H §750): an older version, or the same one again, writes
|
||||
// nothing. It says whether any key changed.
|
||||
// nothing. A passed mover with no version yet is said in the journal and taken when the runner says the end again naming it
|
||||
// (H-A-270); it holds its tier in the pipeline's tier progress meanwhile (H-A-277 (1)). It says whether any key changed.
|
||||
func (e *pipelineEnds) take(p mpr.PipelineEnded) (bool, error) {
|
||||
if p.Outcome != mpr.PipelineEndedOutcomePassed || p.Run != "" {
|
||||
return false, nil
|
||||
}
|
||||
changed := false
|
||||
var kept []tierMover
|
||||
versioned := map[string]bool{}
|
||||
defer func() {
|
||||
if err := e.startTiers(p.Pipeline, p.Source, kept); err != nil {
|
||||
if err := e.startTiers(p.Pipeline, p.Source, kept, versioned); err != nil {
|
||||
e.logf("the tier progress of %s is not written: %v", p.Pipeline, err)
|
||||
}
|
||||
}()
|
||||
for _, m := range p.Movers {
|
||||
if m.Version == "" || m.Fingerprint == "" || !moverPassed(m) {
|
||||
if m.Fingerprint == "" || !moverPassed(m) {
|
||||
continue
|
||||
}
|
||||
if m.Version == "" {
|
||||
// The runner writes a mover's version at its release's version-released, and says this end again once it does
|
||||
// (H-A-270 (1), (2)): the skip is said, never silent.
|
||||
e.logf("%s: %s passed with no version yet: taken again when its version is written", p.Pipeline, m.Module)
|
||||
// It holds its tier in the progress until its version is written (H-A-277 (1)).
|
||||
kept = append(kept, tierMover{Module: m.Module, Fp: m.Fingerprint, Tier: max(m.Tier, 1), NoVersion: true})
|
||||
continue
|
||||
}
|
||||
versioned[m.Module] = true
|
||||
key := endKey(m.Module, p.Branch)
|
||||
for {
|
||||
raw, rev, err := e.st.get(key)
|
||||
@@ -372,32 +382,3 @@ func (e *pipelineEnds) registered(reg mpcat.Registration, gone bool) {
|
||||
}
|
||||
e.wake()
|
||||
}
|
||||
|
||||
// followRegistrations follows the registrations through the seat mesh-catalog (design 47 G §353): a first view of its verb
|
||||
// and each registration-changed on the hub. It returns when the hub's handler is registered; the first view is asked on its own
|
||||
// goroutine.
|
||||
func followRegistrations(ctx context.Context, hub *process.EventHub, call mcc.Call, e *pipelineEnds) error {
|
||||
regs := mcc.NewRegistrations(call)
|
||||
regs.Follower.Logf = e.logf
|
||||
regs.Follower.Changed = func(module string, value json.RawMessage, gone bool, _ time.Time) {
|
||||
reg := mpcat.Registration{Module: module}
|
||||
if !gone {
|
||||
_ = json.Unmarshal(value, ®)
|
||||
}
|
||||
e.registered(reg, gone)
|
||||
}
|
||||
if err := hub.Handle(mpcat.SubjectRegistrationChanged, func(m jetstream.Msg) {
|
||||
if err := regs.Hear(ctx, m.Data()); err != nil {
|
||||
e.logf("%s: %v", m.Subject(), err)
|
||||
}
|
||||
_ = m.Ack()
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
go func() {
|
||||
if err := regs.Start(ctx); err != nil && ctx.Err() == nil {
|
||||
e.logf("the first view of the registrations is not answered: %v", err)
|
||||
}
|
||||
}()
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -141,7 +141,8 @@ func TestThePassedVersionIsKept(t *testing.T) {
|
||||
|
||||
// A6/AC1, A5/AC1 (design 47 H §750): a pass writes, on every node the module is assigned to, the want naming the newest version
|
||||
// released on its branch whose pipeline passed, with the pipeline and the rank; with none passed it writes none. No grant,
|
||||
// canary, provider or composition is asked for.
|
||||
// canary, provider or composition is asked for. H-A-270 (1): a passed end whose mover names no version yet writes no want and
|
||||
// says so in the journal; the same end said again naming the version writes it.
|
||||
func TestAPassWritesTheWantOfThePassedVersion(t *testing.T) {
|
||||
fp := meshcatalogclient.SourcePrefix2 + strings.Repeat("a", 64)
|
||||
for _, passed := range []bool{false, true} {
|
||||
@@ -154,9 +155,15 @@ func TestAPassWritesTheWantOfThePassedVersion(t *testing.T) {
|
||||
p.w.manifests[mdigest] = parsed{module: "web", manifest: catalogue.Manifest{Module: "web", Requires: []string{"database"}}}
|
||||
placeOn(t, p.w, "g14", "web")
|
||||
placeOn(t, p.w, "ace", "web")
|
||||
p.ends = newPipelineEnds(newMemEnds(), func() {}, t.Logf)
|
||||
var journal []string
|
||||
p.ends = newPipelineEnds(newMemEnds(), func() {}, func(f string, a ...any) { journal = append(journal, fmt.Sprintf(f, a...)) })
|
||||
p.ends.trunk = p.w.trunkName
|
||||
if passed {
|
||||
_, _ = p.ends.take(ended(trunkBranch, 5, mpr.PipelineEndedOutcomePassed, mover("web", fp, "", 2, mpr.StepResultOutcomePassed)))
|
||||
p.wants(context.Background())
|
||||
if len(wantsKV.values) != 0 || !slices.Contains(journal, trunkBranch+".5: web passed with no version yet: taken again when its version is written") {
|
||||
t.Errorf("an end naming no version wrote %d wants and said %q", len(wantsKV.values), journal)
|
||||
}
|
||||
_, _ = p.ends.take(ended(trunkBranch, 5, mpr.PipelineEndedOutcomePassed, mover("web", fp, "0.1.2", 2, mpr.StepResultOutcomePassed)))
|
||||
}
|
||||
p.wants(context.Background())
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -40,6 +41,8 @@ type tierMover struct {
|
||||
Module string `json:"module"`
|
||||
Fp string `json:"fp"`
|
||||
Tier int64 `json:"tier"`
|
||||
// NoVersion is a passed mover whose version is not yet written: its tier does not run until it is (H-A-277 (1)).
|
||||
NoVersion bool `json:"no-version,omitempty"`
|
||||
}
|
||||
|
||||
// tierProgress is a pipeline's tier progress (H-A-56): the tier whose wants are written, since when, the movers, and the source
|
||||
@@ -61,24 +64,53 @@ func isTierKey(key string) bool {
|
||||
return strings.HasPrefix(key, tierPrefix) && strings.Count(key, ".") == 2
|
||||
}
|
||||
|
||||
// startTiers writes the tier progress of a passed pipeline whose movers' versions are now kept, its first tier the lowest of
|
||||
// theirs, since now. A pipeline heard again writes nothing.
|
||||
func (e *pipelineEnds) startTiers(pipeline string, source int64, movers []tierMover) error {
|
||||
if len(movers) == 0 {
|
||||
return nil
|
||||
}
|
||||
first := movers[0].Tier
|
||||
for _, m := range movers {
|
||||
first = min(first, m.Tier)
|
||||
}
|
||||
value, err := json.Marshal(tierProgress{Tier: first, Since: e.clock().UTC(), Movers: movers, Source: source})
|
||||
if err != nil {
|
||||
// startTiers writes the tier progress of a passed pipeline, holding every passed mover, versioned or not, its first tier the
|
||||
// lowest of theirs, since now (H-A-277 (1)). A pipeline heard again adds to the progress that stands each mover it does not hold,
|
||||
// at the mover's tier, and marks versioned each held mover whose version is now written (H-A-270, H-A-273): its want is written
|
||||
// when the progress reaches its tier, or at once when that tier ran already, never out of tier order.
|
||||
func (e *pipelineEnds) startTiers(pipeline string, source int64, movers []tierMover, versioned map[string]bool) error {
|
||||
for {
|
||||
t, rev, ok := e.tiersOf(pipeline)
|
||||
if !ok {
|
||||
if len(movers) == 0 {
|
||||
return nil
|
||||
}
|
||||
first := movers[0].Tier
|
||||
for _, m := range movers {
|
||||
first = min(first, m.Tier)
|
||||
}
|
||||
t = tierProgress{Tier: first, Since: e.clock().UTC(), Source: source}
|
||||
}
|
||||
moved := false
|
||||
for i := range t.Movers {
|
||||
if t.Movers[i].NoVersion && versioned[t.Movers[i].Module] {
|
||||
t.Movers[i].NoVersion, moved = false, true
|
||||
}
|
||||
}
|
||||
for _, m := range movers {
|
||||
if !slices.ContainsFunc(t.Movers, func(h tierMover) bool { return h.Module == m.Module }) {
|
||||
t.Movers, moved = append(t.Movers, m), true
|
||||
}
|
||||
}
|
||||
if !moved {
|
||||
return nil
|
||||
}
|
||||
value, err := json.Marshal(t)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = e.st.swap(tierKey(pipeline), value, rev)
|
||||
if errors.Is(err, errSwapped) {
|
||||
if _, _, held := e.tiersOf(pipeline); !ok && !held {
|
||||
return nil // a key that stands but does not read is left as it is
|
||||
}
|
||||
continue
|
||||
}
|
||||
if err == nil && ok {
|
||||
e.logf("pipeline %s: a mover whose version came after its end is taken into the tier progress", pipeline)
|
||||
}
|
||||
return err
|
||||
}
|
||||
if err := e.st.swap(tierKey(pipeline), value, 0); err != nil && !errors.Is(err, errSwapped) {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e *pipelineEnds) clock() time.Time {
|
||||
@@ -196,6 +228,18 @@ func (p *passer) notRunning(n assign.Nodes, placedOn func(module, branch string)
|
||||
if m.Tier != tier {
|
||||
continue
|
||||
}
|
||||
if m.NoVersion {
|
||||
// A mover whose version is not yet written holds its tier, under the tier bound (H-A-277 (1)).
|
||||
machines := []string{}
|
||||
for _, node := range placedOn(m.Module, branch) {
|
||||
if online, known := n.Online[node]; !known || online {
|
||||
machines = append(machines, node)
|
||||
}
|
||||
}
|
||||
sort.Strings(machines)
|
||||
out = append(out, meshwants.NotRunning{Module: m.Module, Machines: machines})
|
||||
continue
|
||||
}
|
||||
if end, ok := p.ends.endOf(m.Module, branch); !ok || end.Pipeline != pipeline {
|
||||
continue // a later pipeline moved it
|
||||
}
|
||||
|
||||
@@ -125,3 +125,86 @@ func TestAPipelinesWantsAreWrittenTierByTier(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// H-A-270, H-A-273, H-A-277 (1): a pipeline's tier progress holds every passed mover, versioned or not, and a tier with a mover
|
||||
// whose version is not yet written does not run until it is: no later tier is wanted out of order. When the lowest tier's version
|
||||
// comes last, nothing is wanted before it; with db (1) and api (3) versioned and web (2) late, api is wanted only once web runs.
|
||||
func TestALateMoverHoldsItsTier(t *testing.T) {
|
||||
type step struct {
|
||||
versions map[string]string // a pipeline-ended taken, each mover's version ("": none yet)
|
||||
runs string // or: this module runs on g14
|
||||
wanted string // then: the modules wanted, in order of the list
|
||||
}
|
||||
for _, c := range []struct {
|
||||
name string
|
||||
steps []step
|
||||
}{
|
||||
{"the lowest tier's version comes last", []step{
|
||||
{versions: map[string]string{"db": "", "web": "0.1.2", "api": "0.3.0"}, wanted: ""},
|
||||
{versions: map[string]string{"db": "0.2.0", "web": "0.1.2", "api": "0.3.0"}, wanted: "db"},
|
||||
{runs: "db", wanted: "db,web"},
|
||||
{runs: "web", wanted: "db,web,api"},
|
||||
}},
|
||||
{"a middle tier's version comes late", []step{
|
||||
{versions: map[string]string{"db": "0.2.0", "web": "", "api": "0.3.0"}, wanted: "db"},
|
||||
{runs: "db", wanted: "db"},
|
||||
{versions: map[string]string{"db": "0.2.0", "web": "0.1.2", "api": "0.3.0"}, wanted: "db,web"},
|
||||
{runs: "web", wanted: "db,web,api"},
|
||||
}},
|
||||
} {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
fps := map[string]string{}
|
||||
tiers := map[string]int64{"db": 1, "web": 2, "api": 3}
|
||||
for i, m := range []string{"db", "web", "api"} {
|
||||
fps[m] = meshcatalogclient.SourcePrefix2 + strings.Repeat(string(rune('a'+i)), 64)
|
||||
}
|
||||
start := time.Date(2026, 11, 21, 4, 0, 0, 0, time.UTC)
|
||||
now := start
|
||||
wantsKV := &memKV{values: map[string][]byte{}}
|
||||
p := newPasser(kvSet{buckets.Wants(): wantsKV, buckets.Asks(): &memKV{values: map[string][]byte{}}}, start)
|
||||
p.now = func() time.Time { return now }
|
||||
p.say = func(oc.Condition) error { return nil }
|
||||
p.publishWants = func(string, any, string) error { return nil }
|
||||
for i, m := range []string{"db", "web", "api"} {
|
||||
digest := strings.Repeat(string(rune('1'+i)), 64)
|
||||
mod, _ := meshcatalogclient.EncodeModule(meshcatalog.ModulesByModuleValue{Fp2: fps[m], Manifest: digest, Repository: "novox/" + m, Commit: strings.Repeat("1", 40), Path: meshcatalogclient.RootPath})
|
||||
putModuleRaw(p.w, trunkBranch, m, mod)
|
||||
p.w.manifests[digest] = parsed{module: m, manifest: catalogue.Manifest{Module: m}}
|
||||
}
|
||||
placeOn(t, p.w, "g14", "db", "web", "api")
|
||||
p.w.mu.Lock()
|
||||
p.w.runningHeard = true
|
||||
p.w.mu.Unlock()
|
||||
p.ends = newPipelineEnds(newMemEnds(), func() {}, t.Logf)
|
||||
p.ends.trunk, p.ends.now = p.w.trunkName, func() time.Time { return now }
|
||||
for i, s := range c.steps {
|
||||
if s.versions != nil {
|
||||
var movers []mpr.MoverEnded
|
||||
for _, m := range []string{"db", "web", "api"} {
|
||||
movers = append(movers, mover(m, fps[m], s.versions[m], tiers[m], mpr.StepResultOutcomePassed))
|
||||
}
|
||||
if _, err := p.ends.take(ended(trunkBranch, 5, mpr.PipelineEndedOutcomePassed, movers...)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
} else {
|
||||
raw, _ := json.Marshal(nodeengine.Running{Node: "g14", Module: s.runs, Fingerprint: fps[s.runs]})
|
||||
if err := p.w.hearRunning("running.g14."+s.runs, raw); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
now = now.Add(time.Minute)
|
||||
p.wants(context.Background())
|
||||
var got []string
|
||||
for _, m := range []string{"db", "web", "api"} {
|
||||
key, _ := mwc.WantKey("g14", m)
|
||||
if _, ok := wantsKV.values[key]; ok {
|
||||
got = append(got, m)
|
||||
}
|
||||
}
|
||||
if strings.Join(got, ",") != s.wanted {
|
||||
t.Fatalf("step %d: wanted %v, want %q", i+1, got, s.wanted)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package pipeline
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
catalog "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner"
|
||||
@@ -108,8 +110,11 @@ func TestThePipelinePassesOnNothingToRunAndFailsOnOneMover(t *testing.T) {
|
||||
// R8 (design 47 H §746, H-A-52, H-A-62): a version-released writes its version into the mover of that module in the pipeline
|
||||
// of the source revision built, on the branch it was released for, so pipeline-ended names it; another branch's pipeline,
|
||||
// and a version heard again, write nothing.
|
||||
//
|
||||
// H-A-270 (2), H-A-277 (2), (3): a version written into a pipeline that ended passed says its pipeline-ended again, naming the
|
||||
// version; one still running, or ended failed, says nothing. A say that failed is said when the version is heard again.
|
||||
func TestAReleasedVersionIsTheMoversVersion(t *testing.T) {
|
||||
h, store, _, _ := twoMovers(t)
|
||||
h, store, bodies, order := twoMovers(t)
|
||||
other := store[pkey]
|
||||
other.p.Pipeline, other.p.Branch, other.p.Movers = "beta.5", "beta", append([]seat.Mover(nil), other.p.Movers...)
|
||||
store["beta.5"] = other
|
||||
@@ -120,9 +125,29 @@ func TestAReleasedVersionIsTheMoversVersion(t *testing.T) {
|
||||
again.p.Pipeline, again.p.Source, again.p.Movers = key, source, append([]seat.Mover(nil), again.p.Movers...)
|
||||
store[key] = again
|
||||
}
|
||||
at := time.Unix(1, 0)
|
||||
for key, outcome := range map[string]string{pkey: seat.PipelineOutcomePassed, "beta.5": seat.PipelineOutcomeFailed} {
|
||||
done := store[key]
|
||||
done.p.Ended, done.p.Outcome = &at, outcome
|
||||
store[key] = done
|
||||
}
|
||||
say := h.Say
|
||||
fail := true
|
||||
h.Say = func(subject string, body any) error {
|
||||
if fail {
|
||||
fail = false
|
||||
return errors.New("the bus is away")
|
||||
}
|
||||
return say(subject, body)
|
||||
}
|
||||
ev := catalog.VersionReleasedEvent{Module: "app", Version: "0.4.1", Source: 5}
|
||||
if n, err := h.Released(ev, "main"); n != 2 || err != nil {
|
||||
t.Fatalf("released wrote %d (%v), want app's mover of main.5 and main.8", n, err)
|
||||
first, err := h.Released(ev, "main")
|
||||
if err == nil || len(*order) != 0 {
|
||||
t.Fatalf("released wrote %d (%v) and said %v, want the failed say returned", first, err, *order)
|
||||
}
|
||||
// Heard again (the nak's redelivery), main.5's version is held already and its end is said (H-A-277 (3)).
|
||||
if n, err := h.Released(ev, "main"); first+n != 2 || err != nil {
|
||||
t.Fatalf("released wrote %d, then %d again (%v), want app's mover of main.5 and main.8", first, n, err)
|
||||
}
|
||||
if m, _ := MoverOf(store["main.6"].p, "app"); m.Version != "" {
|
||||
t.Errorf("main.6's mover = %+v, want no version: another source", m)
|
||||
@@ -133,8 +158,19 @@ func TestAReleasedVersionIsTheMoversVersion(t *testing.T) {
|
||||
if m, _ := MoverOf(store["beta.5"].p, "app"); m.Version != "" {
|
||||
t.Errorf("beta's mover = %+v, want no version: released for main", m)
|
||||
}
|
||||
if n, _ := h.Released(ev, "main"); n != 0 {
|
||||
t.Errorf("the version heard again wrote %d", n)
|
||||
pe, ok := bodies["pipeline-ended.main.5"].(seat.PipelineEnded)
|
||||
if !ok || len(pe.Movers) != 2 || pe.Movers[1].Module != "app" || pe.Movers[1].Version != "0.4.1" {
|
||||
t.Errorf("pipeline-ended.main.5 = %+v, want said again naming app at 0.4.1 (said %v)", bodies["pipeline-ended.main.5"], *order)
|
||||
}
|
||||
if len(*order) != 1 {
|
||||
t.Errorf("said %v, want only main.5's end again: main.8 has not ended", *order)
|
||||
}
|
||||
if n, _ := h.Released(ev, "main"); n != 0 || len(*order) != 2 {
|
||||
t.Errorf("the version heard once more wrote %d and said %v, want main.5's end said again", n, *order)
|
||||
}
|
||||
// beta's failed pipeline, its version written, is never said again (H-A-277 (2)).
|
||||
if n, _ := h.Released(ev, ""); n != 1 || len(*order) != 3 {
|
||||
t.Errorf("released for every branch wrote %d and said %v, want beta's mover written and main.5's end alone said", n, *order)
|
||||
}
|
||||
if got := pipelineEnded(store[pkey].p).Movers[1]; got.Module != "app" || got.Version != "0.4.1" {
|
||||
t.Errorf("pipeline-ended names %+v, want app at 0.4.1", got)
|
||||
|
||||
@@ -5,13 +5,15 @@ import (
|
||||
"fmt"
|
||||
|
||||
catalog "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner"
|
||||
"git.novox.be/novox/mesh-sdk/go/keys"
|
||||
)
|
||||
|
||||
// Released writes a version-released's version into the entry of the mover it names (design 47 H §746, H-A-52): the mover of
|
||||
// that module in each pipeline of the source revision built, a run's aside, so its pipeline-ended names the released version.
|
||||
// branch, when not empty, is the one watched branch the version was released for (H-A-62); empty matches every branch's
|
||||
// pipeline of that source. It says how many movers it wrote.
|
||||
// pipeline of that source. A pipeline that ended passed says its end again, naming the version, and again whenever the version
|
||||
// is heard again (H-A-270 (2), H-A-277). It says how many movers it wrote.
|
||||
func (h *Hearer) Released(ev catalog.VersionReleasedEvent, branch string) (int, error) {
|
||||
if ev.Module == "" || ev.Version == "" || ev.Source <= 0 {
|
||||
return 0, fmt.Errorf("a version-released names its module, version and source revision: %+v", ev)
|
||||
@@ -46,7 +48,15 @@ func (h *Hearer) Released(ev catalog.VersionReleasedEvent, branch string) (int,
|
||||
i = j
|
||||
}
|
||||
}
|
||||
if i < 0 || p.Movers[i].Version == ev.Version {
|
||||
if i < 0 {
|
||||
break
|
||||
}
|
||||
if p.Movers[i].Version == ev.Version {
|
||||
// A version heard again says the end of an ended passed pipeline again (H-A-277 (3)): a say that failed after
|
||||
// the version was written is said now; taking it again is a no-op for the holder.
|
||||
if err := h.sayEndedAgain(key, p, ev); err != nil {
|
||||
return wrote, err
|
||||
}
|
||||
break
|
||||
}
|
||||
p.Movers[i].Version = ev.Version
|
||||
@@ -56,6 +66,11 @@ func (h *Hearer) Released(ev catalog.VersionReleasedEvent, branch string) (int,
|
||||
return wrote, fmt.Errorf("the pipeline %s cannot be written: %w", key, err)
|
||||
}
|
||||
wrote++
|
||||
// A version written after the pipeline's end was said says that end again (H-A-270 (2)): the same pipeline-ended,
|
||||
// now naming the version, so the seat mesh-wants' holder takes the mover it skipped; taking a mover again is a no-op.
|
||||
if err := h.sayEndedAgain(key, p, ev); err != nil {
|
||||
return wrote, err
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -65,6 +80,20 @@ func (h *Hearer) Released(ev catalog.VersionReleasedEvent, branch string) (int,
|
||||
return wrote, nil
|
||||
}
|
||||
|
||||
// sayEndedAgain says p's pipeline-ended again when p ended passed (H-A-270 (2), H-A-277 (2)): only a passed end writes a want,
|
||||
// so a superseded, cancelled or failed one is not said again.
|
||||
func (h *Hearer) sayEndedAgain(key string, p seat.Pipeline, ev catalog.VersionReleasedEvent) error {
|
||||
if p.Ended == nil || p.Outcome != seat.PipelineOutcomePassed {
|
||||
return nil
|
||||
}
|
||||
if err := h.say(seat.EventPipelineEnded, p, nil); err != nil {
|
||||
return fmt.Errorf("the version %s of %s is in the ended pipeline %s but its %s is not said again: %w",
|
||||
ev.Version, ev.Module, key, seat.EventPipelineEnded, err)
|
||||
}
|
||||
h.logf("%s: the version %s of %s is written after its end: %s said again", key, ev.Version, ev.Module, seat.EventPipelineEnded)
|
||||
return nil
|
||||
}
|
||||
|
||||
// ReleasedBranch is the watched branch a module's versions are released for, its registration's first (H-A-62); empty when
|
||||
// the registration is not held.
|
||||
func ReleasedBranch(reg func(string) (catalog.Registration, bool), module string) string {
|
||||
|
||||
Reference in New Issue
Block a user