Compare commits
14
Commits
go/v0.1.60
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1fe6ade359 | ||
|
|
9e09767a4b | ||
|
|
59443ab3f7 | ||
|
|
92d0ab8602 | ||
|
|
3a31331ad3 | ||
|
|
d1581666d2 | ||
|
|
d4d7895392 | ||
|
|
d6c209a10c | ||
|
|
51ac838732 | ||
|
|
06a52a10e0 | ||
|
|
773e2e33a1 | ||
|
|
d817d85fca | ||
|
|
6d5000871d | ||
|
|
5c7648744d |
@@ -25,6 +25,12 @@ import (
|
||||
// below the newest the picture holds, whose entries the picture no longer names, asks the catalog seat's verb revision for
|
||||
// its catalog revision by number, once, and is built when that kept revision is of its source and names every entry it
|
||||
// asks; it never waits, since the picture only moves on. Only a revision above the newest is waited for.
|
||||
//
|
||||
// **An ask naming a revision is held by its number** (design 47 H H-A-222): when the picture does not name the ask's
|
||||
// entries, the ask's catalog revision is read by number, and the ask is built when the catalog keeps it and it names every
|
||||
// fingerprint asked, whatever the source the picture holds says (a re-pin keeps a later revision of the same source, H-A-211,
|
||||
// H-A-213, so the source alone cannot say it). The source is compared only for an ask naming no revision; an ask whose
|
||||
// revision the catalog does not answer and whose source is not below the picture's waits as before.
|
||||
|
||||
// DefaultRevisionWait is the bound of a step ask's wait for its revision, its setting revision-wait-minutes' default (H-A-156).
|
||||
const DefaultRevisionWait = 2 * time.Minute
|
||||
@@ -73,10 +79,13 @@ func (b *Builder) holdsRevision(branch string, source int64, entries []meshbuild
|
||||
return true
|
||||
}
|
||||
|
||||
// keptRevisionHolds answers no outcome when the catalog keeps the ask's revision (its catalog revision by number, of its
|
||||
// source revision) and that revision names every entry of the ask; else failed or could not run, with its words.
|
||||
// keptRevisionHolds answers no outcome when the catalog keeps the ask's revision (its catalog revision by number) and that
|
||||
// revision names every entry of the ask (H-A-205, H-A-222); else failed or could not run, with its words.
|
||||
func (b *Builder) keptRevisionHolds(ctx context.Context, run meshbuilds.StepRun, held int64) (outcome, said string) {
|
||||
below := fmt.Sprintf("revision %d of %s is below the %d the builder's picture holds", run.Source, run.Branch, held)
|
||||
below := fmt.Sprintf("revision %d of %s is not named by the builder's picture, which holds source revision %d", run.Source, run.Branch, held)
|
||||
if run.Source < held {
|
||||
below = fmt.Sprintf("revision %d of %s is below the %d the builder's picture holds", run.Source, run.Branch, held)
|
||||
}
|
||||
if b.KeptRevision == nil || run.Revision <= 0 {
|
||||
return meshbuilds.StepEndedOutcomeFailed, below + ", and the ask names no catalog revision to read it by"
|
||||
}
|
||||
@@ -85,11 +94,15 @@ func (b *Builder) keptRevisionHolds(ctx context.Context, run meshbuilds.StepRun,
|
||||
b.logf("%s: %s, and the catalog's revision %d cannot be read: %v", run.Pipeline, below, run.Revision, err)
|
||||
return meshbuilds.StepEndedOutcomeCouldNotRun, fmt.Sprintf("%s, and the catalog's revision %d cannot be read: %v", below, run.Revision, err)
|
||||
}
|
||||
// An ask names the revision and the source of one revision (H-A-218, H-A-219): a kept revision of another source is
|
||||
// not the ask's.
|
||||
if source != run.Source {
|
||||
return meshbuilds.StepEndedOutcomeFailed, fmt.Sprintf("%s, and the catalog's revision %d is of source revision %d", below, run.Revision, source)
|
||||
b.logf("%s: %s, and the catalog's revision %d is of source revision %d, the ask names %d: the step fails, nothing is built", run.Pipeline, below, run.Revision, source, run.Source)
|
||||
return meshbuilds.StepEndedOutcomeFailed, fmt.Sprintf("%s, and the catalog's revision %d is of source revision %d, the ask names %d", below, run.Revision, source, run.Source)
|
||||
}
|
||||
for _, e := range run.Entries {
|
||||
if fps[e.Module] != e.Fingerprint {
|
||||
b.logf("%s: %s, and the catalog's revision %d names %s at %q, not %s: the step fails, nothing is built", run.Pipeline, below, run.Revision, e.Module, fps[e.Module], e.Fingerprint)
|
||||
return meshbuilds.StepEndedOutcomeFailed, fmt.Sprintf("%s, and the catalog's revision %d names %s at %q, not %s", below, run.Revision, e.Module, fps[e.Module], e.Fingerprint)
|
||||
}
|
||||
}
|
||||
@@ -116,8 +129,17 @@ func (b *Builder) awaitRevision(ctx context.Context, run meshbuilds.StepRun) (ou
|
||||
if b.Picture == nil || run.Source <= 0 || run.Branch == "" {
|
||||
return "", ""
|
||||
}
|
||||
if held, ok := b.Picture(run.Branch); ok && run.Source < held && !b.holdsRevision(run.Branch, run.Source, run.Entries) {
|
||||
return b.keptRevisionHolds(ctx, run, held)
|
||||
if held, ok := b.Picture(run.Branch); !b.holdsRevision(run.Branch, run.Source, run.Entries) {
|
||||
below := ok && run.Source < held
|
||||
if (run.Revision > 0 && b.KeptRevision != nil) || below {
|
||||
// By its number (H-A-222), whatever the source the picture holds; for an ask naming none, only below the
|
||||
// picture (H-A-205). A kept revision of another source or naming other fingerprints is a mismatch the wait
|
||||
// cannot mend: it fails at once; only a revision the catalog does not answer is waited for.
|
||||
outcome, said := b.keptRevisionHolds(ctx, run, held)
|
||||
if outcome == "" || below || outcome == meshbuilds.StepEndedOutcomeFailed {
|
||||
return outcome, said
|
||||
}
|
||||
}
|
||||
}
|
||||
bound := b.revisionWait()
|
||||
notHeld := fmt.Sprintf("revision %d of %s not in the builder's picture", run.Source, run.Branch)
|
||||
|
||||
@@ -356,7 +356,7 @@ func aStepAskWaitsForItsRevision(t *testing.T) {
|
||||
held.Store(40)
|
||||
asked := make(chan struct{}, 1)
|
||||
r, res, entry := revisionRig(t, &held, asked)
|
||||
var keptReads atomic.Int64 // H-A-205: a revision above the newest is waited for, never read by number
|
||||
var keptReads atomic.Int64 // H-A-205, H-A-222: a revision above the newest is read by number once; not answered, it is waited for
|
||||
r.b.KeptRevision = func(context.Context, string, int64) (int64, map[string]string, error) {
|
||||
keptReads.Add(1)
|
||||
return 0, nil, errors.New("not asked")
|
||||
@@ -385,8 +385,8 @@ func aStepAskWaitsForItsRevision(t *testing.T) {
|
||||
t.Fatal("the ask was not woken by the entry the picture took in")
|
||||
}
|
||||
r.b.Wait()
|
||||
if end.Outcome != meshbuilds.StepEndedOutcomePassed || len(res.sources) != 1 || res.sources[0].Revision != 41 || keptReads.Load() != 0 {
|
||||
t.Errorf("end = %+v, reserved from %+v, kept revisions read %d; want passed with one version reserved from revision 41, none read", end, res.sources, keptReads.Load())
|
||||
if end.Outcome != meshbuilds.StepEndedOutcomePassed || len(res.sources) != 1 || res.sources[0].Revision != 41 || keptReads.Load() != 1 {
|
||||
t.Errorf("end = %+v, reserved from %+v, kept revisions read %d; want passed with one version reserved from revision 41, read by number once", end, res.sources, keptReads.Load())
|
||||
}
|
||||
|
||||
}
|
||||
@@ -425,6 +425,45 @@ func anOlderKeptRevisionIsReadByNumber(t *testing.T) {
|
||||
if end := r2.b.BuildStep(t.Context(), run); end.Outcome != meshbuilds.StepEndedOutcomeFailed || !strings.Contains(end.Said, "names m at \"src2:other\"") {
|
||||
t.Errorf("end = %+v; want failed naming the fingerprint the kept revision names", end)
|
||||
}
|
||||
// H-A-222: an ask of the very source the picture holds, whose entries the picture no longer names (a re-pin kept revision 48
|
||||
// of the same source 46 and the picture took its entries in), is held by its revision read by number, never waited for.
|
||||
r3, res3, _ := revisionRig(t, &held, make(chan struct{}, 1))
|
||||
r3.b.RevisionWait = time.Nanosecond
|
||||
r3.b.FirstBranch = func(branch, module string) bool { return branch == "main" && module == "m" }
|
||||
var read3 []string
|
||||
r3.b.KeptRevision = func(_ context.Context, branch string, revision int64) (int64, map[string]string, error) {
|
||||
read3 = append(read3, fmt.Sprintf("%s %d", branch, revision))
|
||||
return 46, map[string]string{"m": fp1}, nil
|
||||
}
|
||||
same := meshbuilds.StepRun{Pipeline: "main.48.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Revision: 48, Source: 46,
|
||||
Entries: []meshbuilds.BuildEntry{{Module: "m", Fingerprint: fp1}}}
|
||||
end3 := r3.b.BuildStep(t.Context(), same)
|
||||
r3.b.Wait()
|
||||
if end3.Outcome != meshbuilds.StepEndedOutcomePassed || !slices.Equal(read3, []string{"main 48"}) || len(res3.sources) != 1 || res3.sources[0].CatalogRevision != 48 {
|
||||
t.Errorf("end = %+v, kept revisions read %v, reserved %+v; want passed, revision 48 of main read once and reserved at it", end3, read3, res3.sources)
|
||||
}
|
||||
// H-A-218, H-A-222: a kept revision of another source than the ask names, or naming another fingerprint, is a mismatch:
|
||||
// the step fails at once naming it, never waiting out its bound (the bound here is long, the ask is not below the picture).
|
||||
for _, c := range []struct {
|
||||
name string
|
||||
source int64
|
||||
fp string
|
||||
said string
|
||||
}{
|
||||
{"another source", 45, fp1, "the catalog's revision 48 is of source revision 45, the ask names 46"},
|
||||
{"another fingerprint", 46, "src2:other", "names m at \"src2:other\""},
|
||||
} {
|
||||
rc, resc, _ := revisionRig(t, &held, make(chan struct{}, 1))
|
||||
rc.b.RevisionWait = time.Hour
|
||||
rc.b.KeptRevision = func(context.Context, string, int64) (int64, map[string]string, error) {
|
||||
return c.source, map[string]string{"m": c.fp}, nil
|
||||
}
|
||||
end := rc.b.BuildStep(t.Context(), same)
|
||||
rc.b.Wait()
|
||||
if end.Outcome != meshbuilds.StepEndedOutcomeFailed || !strings.Contains(end.Said, c.said) || len(resc.sources) != 0 {
|
||||
t.Errorf("%s: end = %+v, reserved %+v; want failed at once saying %q, nothing reserved", c.name, end, resc.sources, c.said)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func aStepAskPastItsRevisionBoundFails(t *testing.T) {
|
||||
|
||||
@@ -7,6 +7,8 @@ import (
|
||||
"reflect"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -172,25 +174,43 @@ func (f *fakeBranchJS) Consumer(_ context.Context, stream, name string) (jetstre
|
||||
|
||||
func (f *fakeBranchJS) CreateConsumer(_ context.Context, stream string, cfg jetstream.ConsumerConfig) (jetstream.Consumer, error) {
|
||||
f.made = append(f.made, cfg)
|
||||
c := &fakeBranchConsumer{}
|
||||
c := newFakeBranchConsumer(stream, cfg.Durable)
|
||||
f.held[stream+"/"+cfg.Durable] = c
|
||||
return c, nil
|
||||
}
|
||||
|
||||
// fakeBranchConsumer hands one source-moved to the hearing as soon as it is consumed.
|
||||
// fakeBranchConsumer hands one source-moved to the hearing as soon as it is consumed. It answers its CachedInfo as the bus
|
||||
// does, with its stream, name and created time, which the SDK's guard of one pull per durable keys by (design 47 H-A-196).
|
||||
type fakeBranchConsumer struct {
|
||||
jetstream.Consumer
|
||||
info jetstream.ConsumerInfo
|
||||
heard int
|
||||
}
|
||||
|
||||
type fakeConsumeContext struct{ jetstream.ConsumeContext }
|
||||
// fakeConsumersMade numbers the fakes, so each is created at a time of its own, as each durable the bus makes is.
|
||||
var fakeConsumersMade atomic.Int64
|
||||
|
||||
func (fakeConsumeContext) Stop() {}
|
||||
func newFakeBranchConsumer(stream, durable string) *fakeBranchConsumer {
|
||||
return &fakeBranchConsumer{info: jetstream.ConsumerInfo{Stream: stream, Name: durable, Config: jetstream.ConsumerConfig{Durable: durable},
|
||||
Created: time.Unix(0, fakeConsumersMade.Add(1)).UTC()}}
|
||||
}
|
||||
|
||||
func (c *fakeBranchConsumer) CachedInfo() *jetstream.ConsumerInfo { return &c.info }
|
||||
|
||||
// fakeConsumeContext is a consume that ends when stopped, as the guard's release waits for (H-A-196).
|
||||
type fakeConsumeContext struct {
|
||||
jetstream.ConsumeContext
|
||||
stop sync.Once
|
||||
closed chan struct{}
|
||||
}
|
||||
|
||||
func (c *fakeConsumeContext) Stop() { c.stop.Do(func() { close(c.closed) }) }
|
||||
func (c *fakeConsumeContext) Closed() <-chan struct{} { return c.closed }
|
||||
|
||||
func (c *fakeBranchConsumer) Consume(handle jetstream.MessageHandler, _ ...jetstream.PullConsumeOpt) (jetstream.ConsumeContext, error) {
|
||||
c.heard++
|
||||
handle(msgOf{f: &fakeMsg{subject: "mesh.seat.mesh-delivery.event.source-moved.main.2"}})
|
||||
return fakeConsumeContext{}, nil
|
||||
return &fakeConsumeContext{closed: make(chan struct{})}, nil
|
||||
}
|
||||
|
||||
// Design 47 H §743, H-A-134: a branch's durable the bus does not hold the indexer makes, as a module's seat-event consumer is
|
||||
@@ -207,7 +227,7 @@ func TestABranchDurableNotThereIsMadeAndHeard(t *testing.T) {
|
||||
name := "n1_mesh-delivery-indexer_" + keys.EscapeName("main")
|
||||
var existing *fakeBranchConsumer
|
||||
if tc.held {
|
||||
existing = &fakeBranchConsumer{}
|
||||
existing = newFakeBranchConsumer(meshdelivery.StreamSourceMoved, name)
|
||||
js.held[meshdelivery.StreamSourceMoved+"/"+name] = existing
|
||||
}
|
||||
var heard []string
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/nats-io/nats.go/jetstream"
|
||||
|
||||
"mesh-delivery-indexer/internal/index"
|
||||
)
|
||||
|
||||
// askedBy is a takerIn that names the hand act it was asked.
|
||||
type askedBy struct{ asked []string }
|
||||
|
||||
func (s *askedBy) did(act string) index.TakenIn {
|
||||
s.asked = append(s.asked, act)
|
||||
return index.TakenIn{Module: "m", Stored: true, Answer: act}
|
||||
}
|
||||
func (s *askedBy) SeatDefinitionsAgain(context.Context, string) index.TakenIn {
|
||||
return s.did("seat-definitions")
|
||||
}
|
||||
func (s *askedBy) FingerprintsAgain(context.Context, string) index.TakenIn {
|
||||
return s.did("fingerprints")
|
||||
}
|
||||
func (s *askedBy) RecomputeByHand(context.Context, string, string) index.TakenIn {
|
||||
return s.did("recompute")
|
||||
}
|
||||
func (s *askedBy) DropCandidateGraph(context.Context, string, string, string, string) index.TakenIn {
|
||||
return s.did("candidate-group")
|
||||
}
|
||||
func (s *askedBy) NamedDrop(context.Context, string, string, string, string) index.TakenIn {
|
||||
return s.did("named-fingerprint")
|
||||
}
|
||||
func (s *askedBy) PinDrop(context.Context, string, string, string) index.TakenIn {
|
||||
return s.did("pin-drop")
|
||||
}
|
||||
func (s *askedBy) DropRunByHand(context.Context, string, string, string) index.TakenIn {
|
||||
return s.did("run-drop")
|
||||
}
|
||||
func (s *askedBy) RegistryAct(context.Context, index.TakeInAsk) index.TakenIn {
|
||||
return s.did("registry")
|
||||
}
|
||||
func (s *askedBy) HeldAgain(context.Context, string) index.TakenIn { return s.did("held") }
|
||||
func (s *askedBy) HeldSkip(context.Context, string, int64, string, string) index.TakenIn {
|
||||
return s.did("held-skip")
|
||||
}
|
||||
func (s *askedBy) TakeInAgain(context.Context, string) index.TakenIn { return s.did("again") }
|
||||
|
||||
// answeredKV keeps the answer takenIn writes back.
|
||||
type answeredKV struct {
|
||||
jetstream.KeyValue
|
||||
written []byte
|
||||
}
|
||||
|
||||
func (k *answeredKV) Update(_ context.Context, _ string, value []byte, _ uint64) (uint64, error) {
|
||||
k.written = value
|
||||
return 2, nil
|
||||
}
|
||||
|
||||
type askEntry struct {
|
||||
jetstream.KeyValueEntry
|
||||
key string
|
||||
value []byte
|
||||
}
|
||||
|
||||
func (e askEntry) Key() string { return e.key }
|
||||
func (e askEntry) Value() []byte { return e.value }
|
||||
func (e askEntry) Revision() uint64 { return 1 }
|
||||
func (e askEntry) Operation() jetstream.KeyValueOp { return jetstream.KeyValuePut }
|
||||
|
||||
// Design 47 H-A-208, H-A-210, H §774: every hand tool's takeins value, built by the tool's own Run path (or the constructor it
|
||||
// calls), is read by DecodeTakeIn and acted on by takenIn as the act it names; indexer_take_in_again's was refused, its Again
|
||||
// missing from a hand-kept list. Every field of TakeInAsk says by its tag whether it is an act, so an act added is read.
|
||||
func TestEveryHandToolsAskIsReadAndActedOn(t *testing.T) {
|
||||
t.Run("every field is classed", func(t *testing.T) {
|
||||
ty := reflect.TypeFor[index.TakeInAsk]()
|
||||
for i := range ty.NumField() {
|
||||
if c := ty.Field(i).Tag.Get("takein"); !slices.Contains([]string{"act", "argument", "ask"}, c) {
|
||||
t.Errorf("TakeInAsk.%s has takein %q, want act, argument or ask", ty.Field(i).Name, c)
|
||||
}
|
||||
}
|
||||
})
|
||||
var values [][]byte
|
||||
ask := func(_ string, value []byte) (index.TakeInAsk, error) {
|
||||
values = append(values, value)
|
||||
return index.TakeInAsk{V: 1, Result: &index.TakenIn{Stored: true}, Answered: time.Now()}, nil
|
||||
}
|
||||
record := func(string, string) error { return nil }
|
||||
tools := map[string]func(map[string]any) (any, error){}
|
||||
for _, tl := range slices.Concat(index.HeldTools(nil, ask, time.Now, record), index.PinsTools(nil, nil, ask, time.Now, record),
|
||||
index.RunsTools(nil, nil, ask, time.Now, record), index.NamedTools(ask, time.Now, record),
|
||||
index.FingerprintsTools(ask, time.Now, record, time.Minute), index.CatalogRevisionTools(nil, ask, time.Now, record),
|
||||
index.RegistrationTools(nil, nil, ask, time.Now, func(string, string, string, string) error { return nil })) {
|
||||
tools[tl.Name] = tl.Run
|
||||
}
|
||||
tools[index.SeatDefinitionsAgainTool] = func(args map[string]any) (any, error) { // its tool lives in the tools bundle
|
||||
_, value, err := index.NewSeatDefinitionsAgain(args["module"].(string), "why", "by", time.Now())
|
||||
values = append(values, value)
|
||||
return nil, err
|
||||
}
|
||||
for _, c := range []struct {
|
||||
tool string
|
||||
args map[string]any
|
||||
act string
|
||||
}{
|
||||
{index.TakeInAgainTool, map[string]any{"repository": "novox/mesh-host", "why": "rule changed"}, "again"},
|
||||
{index.TakeInPendingTool, map[string]any{"branch": "main"}, "held"},
|
||||
{index.TakeInSkipTool, map[string]any{"branch": "main", "source": float64(4), "why": "stale"}, "held-skip"},
|
||||
{index.PinDropTool, map[string]any{"key": "main.7", "why": "no pipeline"}, "pin-drop"},
|
||||
{index.RunDropTool, map[string]any{"run": "run-12", "why": "never ends"}, "run-drop"},
|
||||
{index.NamedDropTool, map[string]any{"fingerprint": "abc", "member": "ace.feh", "why": "gone"}, "named-fingerprint"},
|
||||
{index.FingerprintsAgainTool, map[string]any{"module": "feh", "why": "unread packages"}, "fingerprints"},
|
||||
{index.RecomputeTool, map[string]any{"why": "check"}, "recompute"},
|
||||
{index.DropCandidateGraphTool, map[string]any{"group": "g", "heads": "h", "why": "no gate event"}, "candidate-group"},
|
||||
{index.SeedAgainTool, map[string]any{"why": "empty"}, "registry"},
|
||||
{index.SeatDefinitionsAgainTool, map[string]any{"module": "mesh-contracts"}, "seat-definitions"},
|
||||
} {
|
||||
t.Run(c.tool, func(t *testing.T) {
|
||||
run, ok := tools[c.tool]
|
||||
if !ok {
|
||||
t.Fatalf("no tool %s", c.tool)
|
||||
}
|
||||
values = nil
|
||||
if _, err := run(c.args); err != nil || len(values) != 1 {
|
||||
t.Fatalf("%s wrote %d values (%v)", c.tool, len(values), err)
|
||||
}
|
||||
if _, err := index.DecodeTakeIn(values[0]); err != nil {
|
||||
t.Fatalf("DecodeTakeIn refuses %s: %v", values[0], err)
|
||||
}
|
||||
ix, kv := &askedBy{}, &answeredKV{}
|
||||
var said []string
|
||||
takenIn(t.Context(), ix, kv, askEntry{key: "k", value: values[0]}, func(f string, a ...any) { said = append(said, f) })
|
||||
if !slices.Equal(ix.asked, []string{c.act}) {
|
||||
t.Errorf("takenIn asked %v of %s, want %s (said %s)", ix.asked, values[0], c.act, strings.Join(said, "; "))
|
||||
}
|
||||
var answered index.TakeInAsk
|
||||
if err := json.Unmarshal(kv.written, &answered); err != nil || !answered.Done() {
|
||||
t.Errorf("takenIn wrote back %s (%v), want the answered ask", kv.written, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -93,16 +93,20 @@ func TestTheKeptTrunkIsReadAtTheStartAndOncePerHeardRevision(t *testing.T) {
|
||||
if e, ok, err := modules.Get("ca-trust"); err != nil || !ok || e.Revision != 2 {
|
||||
t.Errorf("after the event ca-trust = %+v %v (%v), want it at revision 2", e, ok, err)
|
||||
}
|
||||
// A-487c: the manifests by digest and the verb revision asked of the trunk's newest answer from the view held.
|
||||
// A-487c: the manifests by digest answer from the view held; the verb revision asked of the trunk's newest lists the bucket
|
||||
// once for which revision is newest (H-A-222) and takes the entries of the view held at that very revision.
|
||||
listed = objects.n.Load()
|
||||
if raw, err := kept.Manifest(meshcatalogclient.BareManifestDigest(keptDigest("ca-trust"))); err != nil || raw != `{"module":"ca-trust"}` {
|
||||
t.Errorf("the held manifest = %q (%v), want the entry's manifest", raw, err)
|
||||
}
|
||||
if got := objects.n.Load() - listed; got != 0 {
|
||||
t.Errorf("the manifest listed the bucket %d times, want none", got)
|
||||
}
|
||||
if a, err := Revision(context.Background(), objects, kept, meshcatalog.RevisionInput{}); err != nil || a.Revision.Revision != 2 || len(a.Entries) != 2 {
|
||||
t.Errorf("revision of the newest answered %+v (%v), want revision 2 whole", a, err)
|
||||
}
|
||||
if got := objects.n.Load() - listed; got != 0 {
|
||||
t.Errorf("the manifest and the verb revision listed the bucket %d times, want none", got)
|
||||
if got := objects.n.Load() - listed; got != 1 {
|
||||
t.Errorf("the verb revision listed the bucket %d times, want once, for the newest", got)
|
||||
}
|
||||
if len(said) != 2 || !strings.Contains(said[1], "read revision 2 (was 1), 2 modules, in ") {
|
||||
t.Errorf("said %q, want each read with its revision, module count and time", said)
|
||||
@@ -126,6 +130,16 @@ func TestTheKeptTrunkIsReadAtTheStartAndOncePerHeardRevision(t *testing.T) {
|
||||
if keys, _ := modules.Keys(); len(keys) != 3 {
|
||||
t.Errorf("the next heard event left the view at %v, want revision 3's three modules", keys)
|
||||
}
|
||||
// H-A-222: two revisions kept that the view has not heard are answered by the verb revision from the store, whole; the
|
||||
// view held stays a cache at its own revision.
|
||||
keep(4, "avahi", "ca-trust", "dbus")
|
||||
keep(5, "avahi", "ca-trust", "dbus", "feh")
|
||||
if a, err := Revision(context.Background(), objects, kept, meshcatalog.RevisionInput{}); err != nil || a.Revision == nil || a.Revision.Revision != 5 || len(a.Entries) != 4 {
|
||||
t.Errorf("revision of the newest answered %+v (%v) while the view held 3, want revision 5 whole from the store", a, err)
|
||||
}
|
||||
if keys, _ := modules.Keys(); len(keys) != 3 {
|
||||
t.Errorf("the verb moved the view held to %v, want it at revision 3 until it hears the event", keys)
|
||||
}
|
||||
}
|
||||
|
||||
// A-487: the verb module reads the one module it is asked.
|
||||
|
||||
@@ -60,8 +60,9 @@ func (t *goModTree) sameRepositoryDir(required string) (string, bool) {
|
||||
}
|
||||
|
||||
// sameRepositoryRequired are the directories (from the root, sorted, each once) of every same-repository Go module the
|
||||
// go.mod of each start directory requires, transitively through those modules' own go.mod files (H-A-202, H-A-157). The
|
||||
// start directories themselves are not among them.
|
||||
// go.mod of each start directory requires, transitively through those modules' own go.mod files (H-A-202, H-A-157). A
|
||||
// same-repository module a go.mod names in a replace directive counts as required, whether or not a require line names it
|
||||
// (H-A-224). The start directories themselves are not among them.
|
||||
func (t *goModTree) sameRepositoryRequired(start []string) []string {
|
||||
seen := map[string]bool{}
|
||||
for _, s := range start {
|
||||
@@ -72,7 +73,8 @@ func (t *goModTree) sameRepositoryRequired(start []string) []string {
|
||||
for len(queue) > 0 {
|
||||
dir := queue[0]
|
||||
queue = queue[1:]
|
||||
for _, req := range fingerprint.MeshRequiresOf(t.goMod(dir)) {
|
||||
raw := t.goMod(dir)
|
||||
for _, req := range append(fingerprint.MeshRequiresOf(raw), fingerprint.ReplacedSiblings(raw, t.f.Repository)...) {
|
||||
d, ok := t.sameRepositoryDir(req)
|
||||
if !ok || seen[d] {
|
||||
continue
|
||||
|
||||
@@ -2,6 +2,7 @@ package index
|
||||
|
||||
import (
|
||||
"context"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -141,4 +142,23 @@ func TestTheEntryPinsEveryRequirementOfTheModuleGraph(t *testing.T) {
|
||||
if _, pinned := pins[builds]; pinned || len(pins) != 1 {
|
||||
t.Errorf("pins = %v, want %s only, never a module of the repository", pins, conditions)
|
||||
}
|
||||
// H-A-224: a same-repository module the go.mod names only in a replace directive (the watchman's buildrun) counts as
|
||||
// required: its own requirement of another repository's client is pinned too.
|
||||
const assigner = "git.novox.be/novox/mesh-contracts/go/clients/meshmoduleassignerclient"
|
||||
objects["modules/d/buildrun"] = strings.Repeat("d", 40)
|
||||
ix, mods, _ = ptpIndexer(t, objects)
|
||||
mod["modules/g"] += "\nreplace git.novox.be/novox/mesh-delivery/modules/d/buildrun => ../d/buildrun\n"
|
||||
mod["modules/d/buildrun"] = "module git.novox.be/novox/mesh-delivery/modules/d/buildrun\n\nrequire " + assigner + ptpZero + "\n"
|
||||
ix.GoMod = func(_ context.Context, _, _, dir string) ([]byte, error) {
|
||||
if c, ok := mod[dir]; ok {
|
||||
return []byte(c), nil
|
||||
}
|
||||
return []byte(ptpGoMods[dir]), nil
|
||||
}
|
||||
if err := ix.Apply(context.Background(), f); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if m, _ := moduleOf(t, mods, "g"); m.Inputs2 == nil || !slices.Contains(m.Inputs2.Packages, assigner) || !slices.Contains(m.Inputs2.Packages, conditions) {
|
||||
t.Errorf("packages = %+v, want the replaced sibling's requirement %s pinned beside the client's", m.Inputs2, assigner)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,17 +23,22 @@ const RevisionInvoke = "seat:" + meshcatalog.Seat + "." + meshcatalog.VerbRevisi
|
||||
// H-A-66: every account may call every verb). With no trunk revision kept yet the answer is `none-yet` alone (design 47 G §530), never an empty
|
||||
// catalog and never an error.
|
||||
//
|
||||
// kept, when not nil, is the trunk's newest revision held in memory: the trunk's newest answers from it with no read of
|
||||
// the bucket (A-487c); a candidate, a branch and an older number read the bucket.
|
||||
// The trunk's newest is the newest the bucket keeps at the time of the ask, read from the store (a listing of the names and
|
||||
// one object, design 47 H-A-222), never the view held in memory, which runs behind until it hears the revision. kept, when
|
||||
// not nil, is that view: a cache of the entries only, used when it holds the very revision read; else the entries are read
|
||||
// from the bucket. A candidate, a branch and an older number read the bucket.
|
||||
func Revision(ctx context.Context, o Objects, kept *KeptTrunk, in meshcatalog.RevisionInput) (meshcatalog.RevisionAnswer, error) {
|
||||
var out meshcatalog.RevisionAnswer
|
||||
var newest meshcatalog.CatalogRevision
|
||||
var ok bool
|
||||
var trunkEntries, branchEntries []meshcatalog.CatalogEntry
|
||||
var err error
|
||||
if kept != nil {
|
||||
newest, trunkEntries, ok, err = kept.Newest(ctx, o)
|
||||
} else {
|
||||
newest, ok, err := newestOf(ctx, o, TrunkBranch)
|
||||
cached := false
|
||||
if err == nil && ok && kept != nil {
|
||||
if held, entries, any, kerr := kept.Newest(ctx, o); kerr == nil && any && held.Revision == newest.Revision {
|
||||
trunkEntries, cached = entries, true
|
||||
}
|
||||
}
|
||||
if !cached && (err != nil || ok) {
|
||||
// readNewestOf reads the entries whole, and the newest again when the pin judge removed one under the read.
|
||||
newest, trunkEntries, ok, err = readNewestOf(ctx, o, TrunkBranch)
|
||||
}
|
||||
if err != nil {
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -18,45 +20,48 @@ const (
|
||||
)
|
||||
|
||||
// TakeInAsk is a value of the takeins state: which hand act a person asked, why, who and when, and, once the indexer read
|
||||
// it, its answer.
|
||||
// it, its answer. Every field says by its tag takein what it is: an act (a field that alone names a hand act the indexer
|
||||
// serves), an argument of an act, or of the ask itself (version, who, why, when, the answer); DecodeTakeIn reads the acts
|
||||
// from these tags, so a hand act added here is read the moment its field is (H-A-208, H-A-210: indexer_take_in_again's
|
||||
// Again was refused by a hand-kept list).
|
||||
type TakeInAsk struct {
|
||||
V int `json:"v"`
|
||||
Module string `json:"module,omitempty"`
|
||||
Why string `json:"why,omitempty"`
|
||||
V int `json:"v" takein:"ask"`
|
||||
Module string `json:"module,omitempty" takein:"argument"`
|
||||
Why string `json:"why,omitempty" takein:"ask"`
|
||||
// SeatDefinitions asks a contracts module's trunk seat definitions to be read again now (indexer_seat_definitions_again,
|
||||
// DLV-I19).
|
||||
SeatDefinitions bool `json:"seat-definitions,omitempty"`
|
||||
SeatDefinitions bool `json:"seat-definitions,omitempty" takein:"act"`
|
||||
// Fingerprints asks the fingerprints of Module ("all": every module) to be computed again now, from the published
|
||||
// packages as they are read (indexer_fingerprints_again, fingerprints.go).
|
||||
Fingerprints bool `json:"fingerprints,omitempty"`
|
||||
Fingerprints bool `json:"fingerprints,omitempty" takein:"act"`
|
||||
// Recompute asks the catalog graph to be computed again now and compared with the newest kept revision (indexer_recompute).
|
||||
Recompute bool `json:"recompute,omitempty"`
|
||||
Recompute bool `json:"recompute,omitempty" takein:"act"`
|
||||
// CandidateGroup and CandidateHeads, with Drop, ask that candidate's catalog half to be dropped (indexer_drop_candidate_graph).
|
||||
CandidateGroup string `json:"candidate-group,omitempty"`
|
||||
CandidateHeads string `json:"candidate-heads,omitempty"`
|
||||
Drop bool `json:"drop,omitempty"`
|
||||
CandidateGroup string `json:"candidate-group,omitempty" takein:"act"`
|
||||
CandidateHeads string `json:"candidate-heads,omitempty" takein:"argument"`
|
||||
Drop bool `json:"drop,omitempty" takein:"argument"`
|
||||
// NamedFingerprint and NamedMember, with Drop, ask one member to be removed from that fingerprint's set of the state named
|
||||
// (indexer_named_drop, named.go, design 47 G §675).
|
||||
NamedFingerprint string `json:"named-fingerprint,omitempty"`
|
||||
NamedFingerprint string `json:"named-fingerprint,omitempty" takein:"act"`
|
||||
// PinDrop asks one pin of the state pins, by its key, to be dropped (indexer_pin_drop, design 47 H §765).
|
||||
PinDrop string `json:"pin-drop,omitempty"`
|
||||
PinDrop string `json:"pin-drop,omitempty" takein:"act"`
|
||||
// Held names the watched branch whose held source-moved is taken in again now (indexer_take_in_pending) or, with Skip and
|
||||
// HeldSource, ended unwritten (indexer_take_in_skip; design 47 H §744).
|
||||
Held string `json:"held,omitempty"`
|
||||
HeldSource int64 `json:"held-source,omitempty"`
|
||||
Skip bool `json:"skip,omitempty"`
|
||||
NamedMember string `json:"named-member,omitempty"`
|
||||
Held string `json:"held,omitempty" takein:"act"`
|
||||
HeldSource int64 `json:"held-source,omitempty" takein:"argument"`
|
||||
Skip bool `json:"skip,omitempty" takein:"argument"`
|
||||
NamedMember string `json:"named-member,omitempty" takein:"argument"`
|
||||
// Again names the repository taken in again at its kept merge commit (indexer_take_in_again, take_in_again.go; H-A-208, H-A-210).
|
||||
Again string `json:"again,omitempty"`
|
||||
Again string `json:"again,omitempty" takein:"act"`
|
||||
// RunDrop asks one run on request, by its group run-<id>, to be dropped with its candidate (indexer_run_drop, runs_tools.go, A-194).
|
||||
RunDrop string `json:"run-drop,omitempty"`
|
||||
RunDrop string `json:"run-drop,omitempty" takein:"act"`
|
||||
// Registry asks one of the registrations' acts (registrations.go): a trusted change of one, the verb registrations,
|
||||
// indexer_proposal_drop or indexer_seed_again (design 47 G §3, §4, §8, §667).
|
||||
Registry *RegistryAct `json:"registry,omitempty"`
|
||||
By string `json:"by,omitempty"`
|
||||
At time.Time `json:"at"`
|
||||
Result *TakenIn `json:"result,omitempty"`
|
||||
Answered time.Time `json:"answered,omitzero"`
|
||||
Registry *RegistryAct `json:"registry,omitempty" takein:"act"`
|
||||
By string `json:"by,omitempty" takein:"ask"`
|
||||
At time.Time `json:"at" takein:"ask"`
|
||||
Result *TakenIn `json:"result,omitempty" takein:"ask"`
|
||||
Answered time.Time `json:"answered,omitzero" takein:"ask"`
|
||||
}
|
||||
|
||||
// Done says the ask is answered.
|
||||
@@ -71,8 +76,33 @@ func DecodeTakeIn(data []byte) (TakeInAsk, error) {
|
||||
if a.V != 1 {
|
||||
return a, fmt.Errorf("a takeins value of version %d, not 1", a.V)
|
||||
}
|
||||
if a.Module == "" && !a.Fingerprints && !a.Recompute && a.CandidateGroup == "" && a.NamedFingerprint == "" && a.PinDrop == "" && a.Held == "" && a.RunDrop == "" && a.Registry == nil {
|
||||
if len(a.Acts()) == 0 {
|
||||
return a, errors.New("a takeins value naming no hand act the indexer serves")
|
||||
}
|
||||
return a, nil
|
||||
}
|
||||
|
||||
// takeInActs are the indices of TakeInAsk's fields tagged takein:"act".
|
||||
var takeInActs = func() []int {
|
||||
var out []int
|
||||
t := reflect.TypeFor[TakeInAsk]()
|
||||
for i := range t.NumField() {
|
||||
if t.Field(i).Tag.Get("takein") == "act" {
|
||||
out = append(out, i)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}()
|
||||
|
||||
// Acts names the hand acts the ask names, by their json names: its fields tagged takein:"act" that are set.
|
||||
func (a TakeInAsk) Acts() []string {
|
||||
var out []string
|
||||
v := reflect.ValueOf(a)
|
||||
for _, i := range takeInActs {
|
||||
if !v.Field(i).IsZero() {
|
||||
name, _, _ := strings.Cut(v.Type().Field(i).Tag.Get("json"), ",")
|
||||
out = append(out, name)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
@@ -160,6 +160,7 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
Kept: keptReader(ctx, kept), Toolchain: toolchainReader(ctx, toolchains),
|
||||
Fills: fills, Recovered: kvRecoveries{ctx, recovered}.Has, Holders: rv.Holders.Holders, Ended: hearer.EndedAtPlacing}
|
||||
hearer.AskSteps = starter.AskSteps
|
||||
starter.Supersede = func(newer seat.Pipeline) { hearer.SupersedeRunning(newer) }
|
||||
hearer.Unplaced = func(p seat.Pipeline, module string) string { return starter.Unplaced(p, module, rv.Catalog.View) }
|
||||
hearer.AskPinHeld = func(key, module string, pins map[string]string) {
|
||||
if _, err := starter.AskPinHeld(hearer.Store, key, module, pins, widener.Revision); err != nil {
|
||||
|
||||
@@ -162,6 +162,9 @@ type Starter struct {
|
||||
// Ended says a pipeline that ended at its placing (holderless): the step-ended of each step of steps, then its end
|
||||
// (Hearer.EndedAtPlacing); nil says it in the journal alone.
|
||||
Ended func(p seat.Pipeline, steps []int) error
|
||||
// Supersede takes out of every older running pipeline of newer's branch each mover whose fingerprint newer moved
|
||||
// (H-A-223; Hearer.SupersedeRunning); nil leaves running pipelines as they are.
|
||||
Supersede func(newer seat.Pipeline)
|
||||
// Fills refuses a start while a store of the runner is full (§366); nil refuses none.
|
||||
Fills *Fills
|
||||
// Recovered says whether a commit is named a recovery (§81, §86): its steps are asked on the build seats' stream delivery.
|
||||
@@ -538,6 +541,10 @@ func (s *Starter) Start(b Begin) (bool, error) {
|
||||
// A waiting pipeline says pipeline-started at its write, so its revision is pinned while it waits (H-A-52), and its
|
||||
// wait on its turn.
|
||||
s.sayStartedPipeline(p, now)
|
||||
// A mover whose fingerprint this revision moved leaves every older running pipeline of the branch (H-A-223).
|
||||
if s.Supersede != nil {
|
||||
s.Supersede(p)
|
||||
}
|
||||
if !place {
|
||||
s.sayQueueWait(seat.EventWaitHeld, p, now, "")
|
||||
if _, err := s.supersedeWaiting(p); err != nil {
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -611,9 +612,16 @@ func endPipeline(p *seat.Pipeline, now time.Time, unplaced func(seat.Pipeline, s
|
||||
}
|
||||
// A mover with no step placed waits on its registration or a publish: it holds the end only while every placed mover's
|
||||
// required steps passed, since once one failed or could not run the pipeline can no longer pass (H-A-163, H-A-171).
|
||||
// A mover that left for a newer pipeline (H-A-223) holds nothing and fails nothing: its steps are not judged, and a
|
||||
// pipeline every mover left ends superseded.
|
||||
if allLeft(*p) {
|
||||
p.Outcome, p.Why, p.Ended = seat.PipelineOutcomeSuperseded, "every mover left it for a newer pipeline (H-A-223)", &now
|
||||
p.EndCount++
|
||||
return true
|
||||
}
|
||||
var waiting []string
|
||||
for _, m := range p.Movers {
|
||||
if !placed(*p, m.Module) {
|
||||
if !placed(*p, m.Module) && !slices.Contains(p.Superseded, m.Module) {
|
||||
waiting = append(waiting, m.Module)
|
||||
}
|
||||
}
|
||||
@@ -621,6 +629,8 @@ func endPipeline(p *seat.Pipeline, now time.Time, unplaced func(seat.Pipeline, s
|
||||
var notAsked []int
|
||||
for i, s := range p.Steps {
|
||||
switch {
|
||||
case slices.Contains(p.Superseded, s.Module):
|
||||
continue
|
||||
case s.Step == seat.StepResultStepApproval && s.Outcome == seat.StepResultOutcomeWaiting:
|
||||
notAsked = append(notAsked, i)
|
||||
continue
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package pipeline
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -377,3 +379,105 @@ func TestARecoverysStepsAreAskedOnTheStreamDelivery(t *testing.T) {
|
||||
t.Errorf("recovered: said %v", said)
|
||||
}
|
||||
}
|
||||
|
||||
// A mover whose fingerprint a newer revision moved leaves a running pipeline (H-A-223, H-A-163): its open steps end
|
||||
// superseded, never failed, the other mover's go on and the pipeline ends by them alone; one every mover left ends
|
||||
// superseded.
|
||||
func TestAMovedMoverLeavesARunningPipeline(t *testing.T) {
|
||||
t0 := time.Date(2026, 11, 21, 1, 0, 0, 0, time.UTC)
|
||||
running := func() seat.Pipeline {
|
||||
return seat.Pipeline{V: 1, Pipeline: "main.54", Branch: "main", Source: 54, Revision: 54, Outcome: seat.PipelineOutcomeRunning, Started: &t0,
|
||||
Movers: []seat.Mover{{Module: "a", Commit: "c1", Fingerprint: "src2:a1"}, {Module: "b", Commit: "c1", Fingerprint: "src2:b1"}},
|
||||
Steps: []seat.StepResult{
|
||||
{Module: "a", Step: seat.StepResultStepBuild, Status: seat.StepResultStatusRequired, Outcome: seat.StepResultOutcomeRunning, Ask: "x1", Started: &t0},
|
||||
{Module: "b", Step: seat.StepResultStepBuild, Status: seat.StepResultStatusRequired, Outcome: seat.StepResultOutcomeRunning, Ask: "x2", Started: &t0},
|
||||
{Module: "b", Step: seat.StepResultStepLint, Artifact: "b:program", Status: seat.StepResultStatusRequired, Outcome: seat.StepResultOutcomeRunning, Ask: "x3", Started: &t0,
|
||||
Seat: nodebuildgo.Seat, Node: "n2"}}}
|
||||
}
|
||||
rows := []struct {
|
||||
name string
|
||||
newer []seat.Mover
|
||||
want string
|
||||
}{
|
||||
{"a newer revision moving b: b's steps end superseded, a's go on and end the pipeline passed alone",
|
||||
[]seat.Mover{{Module: "b", Commit: "c2", Fingerprint: "src2:b2"}}, "running; a build running; b build superseded; b lint superseded | passed"},
|
||||
{"a newer revision moving every mover ends the pipeline superseded",
|
||||
[]seat.Mover{{Module: "a", Commit: "c2", Fingerprint: "src2:a2"}, {Module: "b", Commit: "c2", Fingerprint: "src2:b2"}},
|
||||
"superseded; a build superseded; b build superseded; b lint superseded | superseded"},
|
||||
{"a newer revision at the same fingerprint takes nothing", []seat.Mover{{Module: "b", Commit: "c1", Fingerprint: "src2:b1"}},
|
||||
"running; a build running; b build running; b lint running | running"},
|
||||
}
|
||||
for _, r := range rows {
|
||||
t.Run(r.name, func(t *testing.T) {
|
||||
store := memStore{}
|
||||
store["main.54"] = struct {
|
||||
p seat.Pipeline
|
||||
rev uint64
|
||||
}{running(), 1}
|
||||
var said, dropped []string
|
||||
h := &Hearer{Store: store, Say: func(subject string, _ any) error { said = append(said, subject); return nil }, Now: func() time.Time { return t0 },
|
||||
DropRun: func(buildSeat, node, ask, why string) error {
|
||||
dropped = append(dropped, buildSeat+" "+node+" "+ask+" "+fmt.Sprint(strings.Contains(why, "main.57")))
|
||||
return nil
|
||||
}}
|
||||
h.SupersedeRunning(seat.Pipeline{Pipeline: "main.57", Branch: "main", Revision: 57, Movers: r.newer})
|
||||
// b's lint ask on its build node is dropped naming the newer pipeline; the build ask on mesh-builds, which
|
||||
// serves no drop, is not (H-A-223).
|
||||
wantDropped := ""
|
||||
if r.newer[0].Fingerprint != "src2:b1" {
|
||||
wantDropped = "node-build-go n2 x3 true"
|
||||
}
|
||||
if got := strings.Join(dropped, ","); got != wantDropped {
|
||||
t.Errorf("dropped %q; want %q", got, wantDropped)
|
||||
}
|
||||
p, _, _ := store.Get("main.54")
|
||||
got := []string{p.Outcome}
|
||||
for _, s := range p.Steps {
|
||||
got = append(got, s.Module+" "+s.Step+" "+s.Outcome)
|
||||
if s.Outcome == seat.StepResultOutcomeSuperseded && !strings.Contains(s.Why, "main.57") {
|
||||
t.Errorf("the superseded step's why %q names no newer pipeline", s.Why)
|
||||
}
|
||||
}
|
||||
// The mover left holds nothing: a's build passing ends the pipeline by a alone.
|
||||
if p.Outcome == seat.PipelineOutcomeRunning {
|
||||
p.Steps[0].Outcome, p.Steps[0].Ended = seat.StepResultOutcomePassed, &t0
|
||||
endPipeline(&p, t0, nil)
|
||||
}
|
||||
if s := strings.Join(got, "; ") + " | " + p.Outcome; s != r.want {
|
||||
t.Errorf("got %s\nwant %s", s, r.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
// The live path: a newer pipeline started through Start, a take-in's or a release revision's alike, takes the moved
|
||||
// mover out of the older running pipeline over the same store (H-A-223, H-A-213).
|
||||
starts := []struct {
|
||||
name string
|
||||
begin Begin
|
||||
}{
|
||||
{"a take-in", Begin{Branch: "main", Source: 55, Revision: 55, Call: "0123456789abcdef", Movers: []seat.Mover{{Module: "b", Commit: "c2", Fingerprint: "src2:b2"}}}},
|
||||
{"a release revision", Begin{Branch: "main", Source: 54, Revision: 57, Call: "release of mesh-sdk 0.1.26", Movers: []seat.Mover{{Module: "b", Commit: "c1", Fingerprint: "src2:b2"}}}},
|
||||
}
|
||||
for _, r := range starts {
|
||||
t.Run("started by "+r.name, func(t *testing.T) {
|
||||
store := &MoverStore{Raw: newMemRaw()}
|
||||
raw, _ := json.Marshal(running())
|
||||
if err := store.Create("main.54", raw); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
h := &Hearer{Store: store, Say: func(string, any) error { return nil }, Now: func() time.Time { return t0 }}
|
||||
s := &Starter{Pipelines: store, Store: store, Say: func(string, any) error { return nil }, Now: func() time.Time { return t0 },
|
||||
Supersede: func(newer seat.Pipeline) { h.SupersedeRunning(newer) }}
|
||||
if ok, err := s.Start(r.begin); !ok || err != nil {
|
||||
t.Fatalf("start = %v, %v", ok, err)
|
||||
}
|
||||
p, _, _ := store.Get("main.54")
|
||||
var got []string
|
||||
for _, st := range p.Steps {
|
||||
got = append(got, st.Module+" "+st.Step+" "+st.Outcome)
|
||||
}
|
||||
if s := p.Outcome + "; " + strings.Join(got, "; "); s != "running; a build running; b build superseded; b lint superseded" {
|
||||
t.Errorf("the older pipeline after %s = %s; want b left it", r.name, s)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
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"
|
||||
wants "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||
)
|
||||
|
||||
// Drop asks a build seat's `drop` of a superseded step's ask as a kept call (design 47 G §31, §350; A-182): of node's holder
|
||||
@@ -50,10 +51,120 @@ func (h *Hearer) Taken(ask, node string) error {
|
||||
|
||||
func ptrTime(t time.Time) *time.Time { return &t }
|
||||
|
||||
// allLeft says whether every mover of p left it for a newer pipeline (H-A-223).
|
||||
func allLeft(p seat.Pipeline) bool {
|
||||
if len(p.Movers) == 0 {
|
||||
return false
|
||||
}
|
||||
for _, m := range p.Movers {
|
||||
if !slices.Contains(p.Superseded, m.Module) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// SupersedeRunning takes out of every older running pipeline of newer's branch, read by that branch's keys alone, each mover whose fingerprint newer moved
|
||||
// (H-A-223): its open steps end superseded, naming newer, never failed; a step reading a test run leaves it, as a cancel's
|
||||
// does; the mover is kept in the pipeline's superseded, so the end judgement (H-A-163) counts it as left and newer carries
|
||||
// it. A pipeline then judged ends as at a step's end, by its other movers alone; one every mover left ends superseded.
|
||||
// A run on request's pipeline is never touched. It answers the pipelines it touched.
|
||||
func (h *Hearer) SupersedeRunning(newer seat.Pipeline) []string {
|
||||
pkeys, err := branchKeys(h.Store, newer.Branch)
|
||||
if err != nil {
|
||||
h.logf("the running pipelines of %s are not listed, so none is superseded by %s: %v", newer.Branch, newer.Pipeline, err)
|
||||
return nil
|
||||
}
|
||||
var touched []string
|
||||
for _, key := range pkeys {
|
||||
if key == newer.Pipeline {
|
||||
continue
|
||||
}
|
||||
if h.supersedeRunningOne(key, newer) {
|
||||
touched = append(touched, key)
|
||||
}
|
||||
}
|
||||
return touched
|
||||
}
|
||||
|
||||
func (h *Hearer) supersedeRunningOne(key string, newer seat.Pipeline) bool {
|
||||
for {
|
||||
p, rev, err := h.Store.Get(key)
|
||||
if err != nil || p.Outcome != seat.PipelineOutcomeRunning || p.Branch != newer.Branch || p.Run != "" || newer.Run != "" ||
|
||||
p.Revision >= newer.Revision {
|
||||
return false
|
||||
}
|
||||
var moved []string
|
||||
for _, m := range p.Movers {
|
||||
if slices.Contains(p.Superseded, m.Module) {
|
||||
continue
|
||||
}
|
||||
if nm, ok := MoverOf(newer, m.Module); ok && nm.Fingerprint != m.Fingerprint {
|
||||
moved = append(moved, m.Module)
|
||||
}
|
||||
}
|
||||
if len(moved) == 0 {
|
||||
return false
|
||||
}
|
||||
now := h.now()
|
||||
why := "superseded: the newer " + newer.Pipeline + " moved its fingerprint, and carries it (H-A-223)"
|
||||
var ended []int
|
||||
var leave, drop []seat.StepResult
|
||||
for i := range p.Steps {
|
||||
st := &p.Steps[i]
|
||||
if !slices.Contains(moved, st.Module) || (!open(*st) && st.Outcome != seat.StepResultOutcomeWaiting) {
|
||||
continue
|
||||
}
|
||||
switch {
|
||||
case sharedRun(*st) != "" && st.Seat != wants.Seat:
|
||||
leave = append(leave, *st)
|
||||
case st.Ask != "" && BoundSeat(st.Seat):
|
||||
drop = append(drop, *st) // its own ask on a build node: the seat's drop cancels it
|
||||
}
|
||||
st.Outcome, st.Why, st.Ended = seat.StepResultOutcomeSuperseded, why, &now
|
||||
p.Unlogged = append(p.Unlogged, endEntry(key, *st, now))
|
||||
ended = append(ended, i)
|
||||
}
|
||||
p.Superseded = append(p.Superseded, moved...)
|
||||
done := h.endPipeline(&p, now)
|
||||
if _, err := h.Store.Update(key, p, rev); errors.Is(err, ErrChanged) {
|
||||
continue
|
||||
} else if err != nil {
|
||||
h.logf("the running pipeline %s is not written, so its movers moved by %s stay: %v", key, newer.Pipeline, err)
|
||||
return false
|
||||
}
|
||||
h.logf("%s: %s moved by the newer %s leave it, %d of its open steps ended superseded (H-A-223)", key, strings.Join(moved, ", "), newer.Pipeline, len(ended))
|
||||
for _, i := range ended {
|
||||
if err := h.say(seat.EventStepEnded, p, &p.Steps[i]); err != nil {
|
||||
h.logf("step-ended of %s's %s %s, superseded, is not said: %v", key, p.Steps[i].Module, p.Steps[i].Step, err)
|
||||
}
|
||||
}
|
||||
for _, st := range leave {
|
||||
h.leaveRun(key, st, "the mover "+st.Module+" left "+key+" for the newer "+newer.Pipeline)
|
||||
}
|
||||
// Its running asks on the build nodes are cancelled through the seat's drop (H-A-223). The seat mesh-builds serves no
|
||||
// drop, so a build ask there runs to its end, which the runner ignores: the step is no longer open.
|
||||
for _, st := range drop {
|
||||
if h.DropRun == nil {
|
||||
h.logf("%s: the ask %s of %s's %s is not dropped: the runner has no drop", key, st.Ask, st.Module, st.Step)
|
||||
continue
|
||||
}
|
||||
if err := h.DropRun(st.Seat, st.Node, st.Ask, why); err != nil {
|
||||
h.logf("%s: the drop of the ask %s of %s's %s is not asked of %s: %v", key, st.Ask, st.Module, st.Step, st.Seat, err)
|
||||
}
|
||||
}
|
||||
if err := h.said(p, nil, done); err != nil {
|
||||
h.logf("%v", err)
|
||||
}
|
||||
h.appendUnlogged(key)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// supersedeWaiting takes, in each older waiting pipeline of newer's branch, the movers newer also moves out of it (design 47 H
|
||||
// §748, ADR 0682 §7): a waiting pipeline left with no mover ends superseded, its waiting key deleted, saying wait-ended and its
|
||||
// pipeline-ended. newer is a pipeline just written waiting; a running pipeline is never touched, it runs to its end. It
|
||||
// answers the pipelines it ended.
|
||||
// pipeline-ended. newer is a pipeline just written waiting; a running pipeline's movers leave it by SupersedeRunning
|
||||
// (H-A-223). It answers the pipelines it ended.
|
||||
func (s *Starter) supersedeWaiting(newer seat.Pipeline) ([]string, error) {
|
||||
if s.Queue == nil || newer.Outcome != seat.PipelineOutcomeWaiting {
|
||||
return nil, nil
|
||||
|
||||
Reference in New Issue
Block a user