diff --git a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/run_integration_test.go b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/run_integration_test.go index 40bc02b25..08ab99de9 100644 --- a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/run_integration_test.go +++ b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/run_integration_test.go @@ -56,10 +56,18 @@ func TestTheRunnerPlacesAPipelineAsksItsBuildTakesItsEndAndAnswersAReview(t *tes reg := catalog.Registration{Module: "app", Branches: []string{"main"}, Origin: "o/app", Policy: catalog.Policy{Steps: catalog.StepStatuses{Review: "optional", Validate: "bypass", Composition: "bypass", Approval: "bypass"}}} // design 47 H2 §790: the stalled bound is the setting stalled-bound, here one minute, read as the node-engine composes it. t.Setenv(stdio.SettingWord(pipeline.StalledBoundSetting), "1m") - // The branch main has no revision yet at the runner's start (none-yet), then revision 1 holding app (A-336). - var revised atomic.Bool - w := startWhole(t, ctx, []catalog.Registration{reg}, func([]byte) catalog.RevisionAnswer { - if revised.Load() { + // The branch main has no revision yet at the runner's start (none-yet), then revision 1 holding app (A-336), then the + // re-pin revision 5 of the same source moving app to src2:ab (H-A-283), its newest once said. + var revised, repinned atomic.Bool + w := startWhole(t, ctx, []catalog.Registration{reg}, func(raw []byte) catalog.RevisionAnswer { + var in catalog.RevisionInput + _ = json.Unmarshal(raw, &in) + switch { + case repinned.Load() && (in.Revision == 5 || in.Revision == 0): + return catalog.RevisionAnswer{Revision: &catalog.CatalogRevision{Revision: 5, Kind: "trunk", Branch: "main", Source: 3, CallKind: catalog.CatalogRevisionCallKindRelease, + Movers: []catalog.TakeInEntry{{Module: "app", Commit: "c1", Fingerprint: "src2:ab", Repository: "o/app"}}}, + Entries: []catalog.CatalogEntry{{Module: "app", Commit: "c1", Fp: "src2:ab"}}} + case revised.Load(): return catalog.RevisionAnswer{Revision: &catalog.CatalogRevision{Revision: 1, Kind: "trunk", Branch: "main", Source: 3}, Entries: []catalog.CatalogEntry{{Module: "app", Commit: "c1", Fp: "src2:aa"}}} } @@ -67,6 +75,17 @@ func TestTheRunnerPlacesAPipelineAsksItsBuildTakesItsEndAndAnswersAReview(t *tes }) const module = "mesh-delivery-pipeline" nc, js, asks, pipelines, logs := w.nc, w.js, w.asks, w.pipelines, w.logs + // design 47 H2 §821: every event the runner says is waited on by its seat and name, as mesh_wait waits on + // mesh-pipeline-runner.; each is heard by the test's end. + heard := map[string][][]byte{} + var heardMu sync.Mutex + for name, subject := range map[string]string{seat.EventPipelineStarted: seat.SubjectPipelineStartedAll, seat.EventStepEnded: seat.SubjectStepEndedAll, + seat.EventPipelineEnded: seat.SubjectPipelineEndedAll, seat.EventRePinned: seat.SubjectRePinned} { + if _, err := nc.Subscribe(subject, func(m *nats.Msg) { heardMu.Lock(); heard[name] = append(heard[name], m.Data); heardMu.Unlock() }); err != nil { + t.Fatal(err) + } + } + heardOf := func(name string) [][]byte { heardMu.Lock(); defer heardMu.Unlock(); return heard[name] } // A take-in.taken names one entry of the source revision; the runner places the pipeline of the registered module. taken, _ := json.Marshal(catalog.TakeInTaken{Branch: "main", Source: 3, Call: "0123456789abcdef", @@ -103,6 +122,24 @@ func TestTheRunnerPlacesAPipelineAsksItsBuildTakesItsEndAndAnswersAReview(t *tes if build.Outcome != seat.StepResultOutcomeRunning || build.Ask == "" { t.Fatalf("the build step = %+v", build) } + // A re-pin revision of the pipeline's own source keeps app in it at src2:ab, its steps placed again under new asks, and + // says re-pinned naming the pipeline, the mover and the revision (design 47 H2 §821, H-A-283). + repinned.Store(true) + repin, _ := json.Marshal(catalog.CatalogRevisionEvent{V: 1, Revision: 5, Kind: "trunk", Branch: "main", Source: 3, CallKind: catalog.CatalogRevisionEventCallKindRelease}) + if _, err := js.Publish(ctx, catalog.SubjectCatalogRevision("main"), repin); err != nil { + t.Fatal(err) + } + waitFor(t, ctx, logs, func() bool { return len(heardOf(seat.EventRePinned)) > 0 }) + var said seat.RePinnedEvent + if err := json.Unmarshal(heardOf(seat.EventRePinned)[0], &said); err != nil || said.Pipeline != key || said.Mover != "app" || said.Revision != 5 { + t.Fatalf("re-pinned said %+v (%v), want %s app 5", said, err, key) + } + waitFor(t, ctx, logs, func() bool { + return readPipeline(ctx, pipelines, key, &p) && stepOf(p, seat.StepResultStepBuild).Fingerprint == "src2:ab" + }) + if build = stepOf(p, seat.StepResultStepBuild); build.Outcome != seat.StepResultOutcomeRunning || build.Ask == "" { + t.Fatalf("the build placed again = %+v", build) + } // Once a step is placed in it, the health no longer names it (§790). if a := pipeline.Health(kvKept{ctx, pipelines}, noConsumers, p.Started.Add(61*time.Second), bound); strings.Contains(a.Why, key+" (nothing open") { t.Fatalf("with its build placed, the health still names %s: %+v", key, a) @@ -111,7 +148,7 @@ func TestTheRunnerPlacesAPipelineAsksItsBuildTakesItsEndAndAnswersAReview(t *tes waitFor(t, ctx, logs, func() bool { info, err := asks.Info(ctx); return err == nil && info.State.Msgs >= 1 }) // A session's review, while the build still runs, is answered by the runner's process, the caller the one the subject names. - in, _ := json.Marshal(seat.ReviewInput{Module: "app", Commit: "c1", Fingerprint: "src2:aa", Outcome: "passed", Said: "reads well"}) + in, _ := json.Marshal(seat.ReviewInput{Module: "app", Commit: "c1", Fingerprint: "src2:ab", Outcome: "passed", Said: "reads well"}) var reply struct { Result seat.ReviewAnswer `json:"result"` Error string `json:"error"` @@ -131,7 +168,7 @@ func TestTheRunnerPlacesAPipelineAsksItsBuildTakesItsEndAndAnswersAReview(t *tes // The seat's holder says the build ended; the runner takes it from the node's subject. ended, _ := json.Marshal(builds.StepEnded{ID: build.Ask, Pipeline: key, Step: "build", Node: "n1", Outcome: "passed", - Entries: []builds.BuildEntry{{Module: "app", Commit: "c1", Fingerprint: "src2:aa"}}}) + Entries: []builds.BuildEntry{{Module: "app", Commit: "c1", Fingerprint: "src2:ab"}}}) if _, err := js.Publish(ctx, "mesh.seat.mesh-builds.event.step-ended.n1", ended); err != nil { t.Fatal(err) } @@ -140,6 +177,10 @@ func TestTheRunnerPlacesAPipelineAsksItsBuildTakesItsEndAndAnswersAReview(t *tes }) waitFor(t, ctx, logs, func() bool { return readPipeline(ctx, pipelines, key, &p) && p.Outcome == seat.PipelineOutcomePassed }) + // Each of the runner's events was heard by its name (§821). + waitFor(t, ctx, logs, func() bool { + return len(heardOf(seat.EventPipelineStarted)) > 0 && len(heardOf(seat.EventStepEnded)) > 0 && len(heardOf(seat.EventPipelineEnded)) > 0 + }) // H-A-187 over the bus: show composes the pipeline from its record and mover keys, naming a mover its steps alone, and a // record written before it, its steps inline, is read whole and split at its next write. diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/repin.go b/modules/mesh-delivery-pipeline/internal/pipeline/repin.go index 36008513b..4a39038cd 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/repin.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/repin.go @@ -131,6 +131,7 @@ func (s *Starter) keepIn(key string, half Half, movers []seat.Mover) []seat.Move } s.logf("%s keeps the movers revision %d of its own source %d re-pinned, %s: %d steps ended superseded, %d asked again (H-A-283, H-A-284)", key, half.Revision, half.Source, strings.Join(moved, ", "), len(ended), len(asks)) + s.sayRePinned(p, kept, revisions, half.Revision) for _, st := range ended { if s.Say == nil { break @@ -164,6 +165,23 @@ func (s *Starter) keepIn(key string, half Half, movers []seat.Mover) []seat.Move } } +// sayRePinned says re-pinned for each of kept whose fingerprint the re-pin revision moved (it is in revisions), once its +// pipeline p is written keeping it (design 47 H2 §821, H-A-349 DQ-13): the pipeline, the mover and the revision it is +// re-pinned at, on the seat's subject for the event, so a wait by the seat and the event's name is answered. +func (s *Starter) sayRePinned(p seat.Pipeline, kept []seat.Mover, revisions map[string]int64, revision int64) { + if s.Say == nil { + return + } + for _, m := range kept { + if _, ok := revisions[m.Module]; !ok { + continue + } + if err := s.Say(seat.SubjectRePinned, seat.RePinnedEvent{Pipeline: p.Pipeline, Mover: m.Module, Revision: revision}); err != nil { + s.logf("%s of %s's %s at revision %d is not said: %v", seat.EventRePinned, p.Pipeline, m.Module, revision, err) + } + } +} + // placeAgain places the steps of kept mover m of p from the re-pin revision half's entry (H-A-284 (1)), as a mover is placed // (placeMovers), under ask ids its kept revision is mixed into (H-A-286): it answers the asks to put, the steps placed not asked because a // dependency did not build, and whether m has no registration. A mover not due yet (it waits on a publish) is left diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/repin_test.go b/modules/mesh-delivery-pipeline/internal/pipeline/repin_test.go index 3faf3472b..e1361f6a0 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/repin_test.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/repin_test.go @@ -66,13 +66,17 @@ func TestASameSourceRepinKeepsTheMoverInItsPipeline(t *testing.T) { store := &MoverStore{Raw: newMemRaw()} asks := &stepAsks{} var said []seat.StepEvent + var repinned []string var left [][]seat.StepResult s := &Starter{Pipelines: store, Store: store, Steps: asks, Name: "the-runner", Now: ticking(), Revision: read, Registration: func(m string) (catalog.Registration, bool) { return reg, m == "app" }, - Say: func(_ string, body any) error { + Say: func(subject string, body any) error { if ev, ok := body.(seat.StepEvent); ok && ev.Result.Outcome == seat.StepResultOutcomeSuperseded { said = append(said, ev) } + if ev, ok := body.(seat.RePinnedEvent); ok { + repinned = append(repinned, fmt.Sprintf("%s %s %s %d", subject, ev.Pipeline, ev.Mover, ev.Revision)) + } return nil }, Left: func(_ string, leave, drop []seat.StepResult, _ string) { left = append(left, append(leave, drop...)) }} @@ -122,6 +126,10 @@ func TestASameSourceRepinKeepsTheMoverInItsPipeline(t *testing.T) { if !ok || asks.ids[0] != p.Steps[0].Ask || b.Revision != 10 || b.Source != 41 || len(b.Entries) != 1 || b.Entries[0].Fingerprint != "src2:ab" { t.Fatalf("the build asked again = %+v (%s), want the new fingerprint at the pipeline's revision", asks.asks[0], asks.ids[0]) } + // design 47 H2 §821: the kept mover's re-pin is said once, on the seat's re-pinned, naming the pipeline, mover and revision. + if want := seat.SubjectRePinned + " " + key + " app 11"; len(repinned) != 1 || repinned[0] != want { + t.Errorf("re-pinned said %q, want once %q", repinned, want) + } if kept, err := store.KeptRevisions(key); err != nil || kept["app"] != 11 { t.Errorf("kept-revisions = %v (%v), want app at 11", kept, err) }