# Conflicts: # modules/mesh-delivery-contracts/seats/mesh-pipeline-runner/seat.json # modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/main.go # modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/steps.go # modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/verbs.go # modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/verbs_test.go # modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/views.go # modules/mesh-delivery-pipeline/internal/pipeline/start.go # modules/mesh-delivery-pipeline/manifest_test.go # modules/mesh-delivery-pipeline/module.json
113 lines
5.8 KiB
Go
113 lines
5.8 KiB
Go
package pipeline
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
"testing"
|
|
|
|
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): `run` writes each member's pipeline at once under the run's id and its
|
|
// named branch and says run-started; the candidate run-<id>'s revision places each member's steps and a pipeline of each
|
|
// entry the members change, says pipeline-started once each, and places nothing twice; a member naming no branch is 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 }
|
|
if _, err := s.Run("sessions", seat.RunInput{Members: []seat.Member{{Module: "app", Commit: "c1"}}}, id); err == nil {
|
|
t.Error("a member naming no branch was taken")
|
|
}
|
|
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)
|
|
if err != nil || a.Run != "0a1b2c3d4e5f" || len(a.Pipelines) != 1 {
|
|
t.Fatalf("run = %+v, %v", a, err)
|
|
}
|
|
key := a.Pipelines[0]
|
|
if key != RunKey("fix/1", "0a1b2c3d4e5f", "app") {
|
|
t.Errorf("the member's pipeline is %s, want the run's id under its named branch", key)
|
|
}
|
|
if p, _, _ := store.Get(key); p.Run != a.Run || p.Outcome != seat.PipelineOutcomeRunning || len(p.Steps) != 0 || p.Branch != "fix/1" || p.Source != 0 {
|
|
t.Errorf("the member'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 != 2 {
|
|
t.Fatalf("the candidate placed %d (%v), want the member and the dependent lib", n, err)
|
|
}
|
|
p, _, _ := store.Get(key)
|
|
if p.Fingerprint != "src2:new" || p.Revision != 12 || len(p.Steps) == 0 {
|
|
t.Errorf("the member's pipeline placed = %+v", p)
|
|
}
|
|
dep, _, err := store.Get(RunKey("fix/1", a.Run, "lib"))
|
|
if err != nil || dep.Run != a.Run || dep.Fingerprint != "src2:lib2" || len(dep.Steps) == 0 {
|
|
t.Errorf("the dependent's pipeline = %+v (%v)", dep, err)
|
|
}
|
|
if _, _, err := store.Get(RunKey("fix/1", a.Run, "same")); err == nil {
|
|
t.Error("an entry the members do not change got a pipeline")
|
|
}
|
|
if len(said) != 2 || !strings.HasPrefix(said[0], seat.EventPipelineStarted+".") || len(asks.ids) == 0 {
|
|
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)
|
|
}
|
|
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 })
|
|
if err != nil || len(two.Pipelines) != 2 || 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 })
|
|
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", "app")); p.Outcome != seat.PipelineOutcomeFailed {
|
|
t.Errorf("its pipeline is %s, want failed", p.Outcome)
|
|
}
|
|
}
|