Files
mesh-delivery/modules/mesh-delivery-pipeline/internal/pipeline/run_test.go
T
jschoubben 0cbabe9860 Runner and builder: a run's build step ask names no source; a held revision wakes the builder's wait (H-A-162)
A run on request copied its pipeline's source onto its build step ask,
so the builder waited for the run's candidate fingerprints in its
picture of the branch, where they never come, and failed every run past
the bound. The seat mesh-builds' contract leaves a run's source absent:
the runner now does. A revision the builder's view takes in whole that
changes no entry now also wakes a waiting ask, told by the catalog
client's new Held.

Builds: design 47 H H-A-162, H-A-155
2026-11-20 17:30:56 +01:00

139 lines
7.4 KiB
Go

package pipeline
import (
"errors"
"strings"
"testing"
builds "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds"
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"
)
// RN12 (design 47 G §64, §373, §420; A-180, A-193; H H-A-83, H-A-85): `run` writes the run's one pipeline at once, keyed
// <branch>.run.<id>, its movers the members, its source its branch's newest, and says run-started; the candidate
// run-<id>'s revision places each member's steps and a mover of each entry the members change, says pipeline-started once,
// and places nothing twice; a member naming no branch, or members of two branches, are refused.
func TestRunOnRequest(t *testing.T) {
reg, entries := placeFixture()
store := memCreated{memStore{}}
var said []string
asks := &stepAsks{}
s := &Starter{Pipelines: store, Store: store, Steps: asks, Name: "the-runner",
Registration: func(m string) (catalog.Registration, bool) {
r := reg
r.Module = m
return r, m == "app" || m == "lib"
},
Say: func(subject string, body any) error {
said = append(said, subject[strings.Index(subject, ".event.")+7:])
return nil
}}
id := func() (string, error) { return "0a1b2c3d4e5f", nil }
view := func(b string) (Half, bool) { return Half{Source: 41}, b == "fix/1" || b == "main" }
if _, err := s.Run("sessions", seat.RunInput{Members: []seat.Member{{Module: "app", Commit: "c1"}}}, id, view); err == nil {
t.Error("a member naming no branch was taken")
}
if _, err := s.Run("sessions", seat.RunInput{Members: []seat.Member{{Module: "app", Commit: "c1", Branch: "fix/1"}, {Module: "lib", Commit: "c0", Branch: "main"}}}, id, view); err == nil {
t.Error("a run naming two branches was taken: it is one pipeline of one branch")
}
// H-A-85: a branch with no source revision yet is refused, naming it.
if _, err := s.Run("sessions", seat.RunInput{Members: []seat.Member{{Module: "app", Commit: "c1", Branch: "fix/2"}}}, id, view); err == nil || !strings.Contains(err.Error(), "fix/2") {
t.Errorf("a run of a branch with no source revision = %v, want refused naming it", err)
}
if len(store.memStore) != 0 || len(said) != 0 {
t.Fatalf("a refused run wrote %v and said %v", store.memStore, said)
}
a, err := s.Run("sessions", seat.RunInput{Members: []seat.Member{{Module: "app", Commit: "c1", Branch: "fix/1"}}}, id, view)
if err != nil || a.Run != "0a1b2c3d4e5f" || len(a.Pipelines) != 1 {
t.Fatalf("run = %+v, %v", a, err)
}
key := a.Pipelines[0]
// H-A-83, H-A-85: a run is one pipeline keyed <branch>.run.<id>, its movers the members, its source the branch's newest.
if key != "fix%2F1.run.0a1b2c3d4e5f" && key != RunKey("fix/1", "0a1b2c3d4e5f") {
t.Errorf("the run's pipeline is %s, want <branch>.run.<id>", key)
}
if p, _, _ := store.Get(key); p.Run != a.Run || p.Outcome != seat.PipelineOutcomeRunning || len(p.Steps) != 0 || p.Branch != "fix/1" ||
p.Source != 41 || len(p.Movers) != 1 || p.Movers[0].Module != "app" {
t.Errorf("the run's pipeline %s = %+v", key, p)
}
if len(said) != 1 || !strings.HasPrefix(said[0], seat.EventRunStarted+".app.") || !strings.HasSuffix(said[0], ".c1") {
t.Errorf("said %v, want run-started on the member's module, branch and commit", said)
}
// A-222: a restart finds the runs whose steps were never placed, by their branch.
if ids, err := s.UnplacedRuns(); err != nil || len(ids) != 1 || ids[0] != (UnplacedRun{Run: a.Run, Branch: "fix/1"}) {
t.Errorf("the unplaced runs = %v (%v), want %s on fix/1", ids, err, a.Run)
}
cand := entries
cand["app"] = catalog.CatalogEntry{Module: "app", Commit: "c1", Fp: "src2:new", Repository: "o/app", Artifacts: entries["app"].Artifacts}
cand["lib"] = catalog.CatalogEntry{Module: "lib", Commit: "c0", Fp: "src2:lib2", Artifacts: entries["app"].Artifacts}
cand["same"] = catalog.CatalogEntry{Module: "same", Fp: "src2:same"}
base := func(string) (Half, bool) {
return Half{Entries: map[string]catalog.CatalogEntry{"lib": {Fp: "src2:lib1"}, "same": {Fp: "src2:same"}, "mesh-build-go": entries["mesh-build-go"]}}, true
}
ev := catalog.CatalogRevisionEvent{Kind: "candidate", Group: "run-" + a.Run, Revision: 12}
if n, err := s.PlaceRun(catalog.CatalogRevisionEvent{Kind: "candidate", Group: "try-3", Revision: 11}, Half{Entries: cand}, base); n != 0 || err != nil {
t.Errorf("a try's candidate placed %d (%v)", n, err)
}
said = nil
n, err := s.PlaceRun(ev, Half{Revision: 12, Entries: cand}, base)
if err != nil || n != 1 {
t.Fatalf("the candidate placed %d (%v), want the run's one pipeline", n, err)
}
p, _, _ := store.Get(key)
app, _ := MoverOf(p, "app")
lib, _ := MoverOf(p, "lib")
if app.Fingerprint != "src2:new" || lib.Fingerprint != "src2:lib2" || Moves(p, "same") || p.Revision != 12 || !placed(p, "app") || !placed(p, "lib") {
t.Errorf("the run's pipeline placed = %+v, want the member and the dependent lib as movers, not same", p)
}
// Each pipeline placed says pipeline-started, then step-started for each step it asks (A-469a).
started, steps := 0, 0
for _, x := range said {
started += strings.Count(x, seat.EventPipelineStarted+".")
steps += strings.Count(x, seat.EventStepStarted+".")
}
if started != 1 || !strings.HasPrefix(said[0], seat.EventPipelineStarted+".") || len(asks.ids) == 0 || steps < len(asks.ids) {
t.Errorf("placing said %v and asked %d steps", said, len(asks.ids))
}
if ids, _ := s.UnplacedRuns(); len(ids) != 0 {
t.Errorf("a placed run is still unplaced: %v", ids)
}
// H-A-162: a run's build step asks name no source, as the seat mesh-builds' contract says of a run on request.
builtAsks := 0
for _, x := range asks.asks {
if r, ok := x.(builds.StepRun); ok {
builtAsks++
if r.Source != 0 {
t.Errorf("the run's build step ask names source %d, want none", r.Source)
}
}
}
if builtAsks == 0 {
t.Errorf("the run asked no build step: %v", asks.asks)
}
if n, _ := s.PlaceRun(ev, Half{Revision: 12, Entries: cand}, base); n != 0 {
t.Errorf("the revision heard again placed %d", n)
}
// A restart asks a run's steps again from no branch's half: they are its candidate's.
if n, err := s.Resume(store, "fix/1", Half{Entries: entries}); n != 0 || err != nil {
t.Errorf("a restart asked %d steps of the run again (%v)", n, err)
}
// Several members say run-started on the first member's module and branch and run-<id>; a run-started not said fails the
// pipelines written, so none stands running.
said = nil
two, err := s.Run("operator", seat.RunInput{Members: []seat.Member{{Module: "app", Commit: "c2", Branch: "main"}, {Module: "lib", Commit: "c3", Branch: "main"}}},
func() (string, error) { return "ffffffffffff", nil }, view)
if err != nil || len(two.Pipelines) != 1 || len(said) != 1 || said[0] != seat.EventRunStarted+".app.main.run-ffffffffffff" {
t.Errorf("a run of two: %+v (%v), said %v", two, err, said)
}
s.Say = func(string, any) error { return errors.New("bus away") }
three, err := s.Run("operator", seat.RunInput{Members: []seat.Member{{Module: "app", Commit: "c4", Branch: "main"}}}, func() (string, error) { return "eeeeeeeeeeee", nil }, view)
if err == nil || three.Run != "" {
t.Errorf("a run whose run-started was not said answered %+v", three)
}
if p, _, _ := store.Get(RunKey("main", "eeeeeeeeeeee")); p.Outcome != seat.PipelineOutcomeFailed {
t.Errorf("its pipeline is %s, want failed", p.Outcome)
}
}