Review round 1: a node-build-go end naming superseded is refused as an outcome the runner does not know, moving nothing; a dependent whose steps ended not asked on a mover whose build ended superseded is taken out and placed again. Builds: design 47 H2 H-A-508 (and its addendum)
183 lines
10 KiB
Go
183 lines
10 KiB
Go
package pipeline
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"slices"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"git.novox.be/novox/mesh-contracts/identity-and-access/go/seats/meshgrants"
|
|
builds "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds"
|
|
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner"
|
|
)
|
|
|
|
// refusedOnce is a store whose first write of a pipeline is refused as changed, another write having come between (the
|
|
// pipeline's key moving while its end is judged, as main.117's did).
|
|
type refusedOnce struct {
|
|
memStore
|
|
refused map[string]bool
|
|
}
|
|
|
|
func (r *refusedOnce) Update(key string, p seat.Pipeline, rev uint64) (uint64, error) {
|
|
if !r.refused[key] {
|
|
r.refused[key] = true
|
|
e := r.memStore[key]
|
|
e.rev++
|
|
r.memStore[key] = e
|
|
return 0, ErrChanged
|
|
}
|
|
return r.memStore.Update(key, p, rev)
|
|
}
|
|
|
|
// H-A-288, H-A-289 (met with main.117 and main.76): a pipeline ends, and the next waiting is placed, the moment nothing of it is
|
|
// still open: when its last mover leaves, when its last open step ends by the silent bound, and at the runner's start pass;
|
|
// its outcome is said in the journal. The reads its end needs are made once, before the compare-and-set, shared by every mover
|
|
// and every retry of the write: a write refused once is written at the retry without asking grants-for again.
|
|
func TestAPipelineWithNothingOpenEndsAtOnce(t *testing.T) {
|
|
t0 := time.Date(2026, 11, 21, 17, 45, 19, 0, time.UTC)
|
|
movers := []seat.Mover{{Module: "a", Commit: "c1", Fingerprint: "src2:a1"}, {Module: "b", Commit: "c1", Fingerprint: "src2:b1"},
|
|
{Module: "c", Commit: "c1", Fingerprint: "src2:c1"}}
|
|
step := func(module, outcome, ask string) seat.StepResult {
|
|
return seat.StepResult{Module: module, Step: seat.StepResultStepBuild, Status: seat.StepResultStatusRequired, Outcome: outcome, Ask: ask, Seat: builds.Seat}
|
|
}
|
|
rows := []struct {
|
|
name string
|
|
steps []seat.StepResult
|
|
end func(t *testing.T, h *Hearer)
|
|
outcome string
|
|
}{
|
|
{"its last mover leaves for a newer pipeline (H-A-223)",
|
|
[]seat.StepResult{step("a", seat.StepResultOutcomeRunning, "x1"), step("b", seat.StepResultOutcomePassed, "x2"), step("c", seat.StepResultOutcomePassed, "x3")},
|
|
func(t *testing.T, h *Hearer) {
|
|
h.SupersedeRunning(seat.Pipeline{Pipeline: "main.120", Branch: "main", Revision: 120, Movers: []seat.Mover{
|
|
{Module: "a", Commit: "c2", Fingerprint: "src2:a2"}, {Module: "b", Commit: "c2", Fingerprint: "src2:b2"}, {Module: "c", Commit: "c2", Fingerprint: "src2:c2"}}})
|
|
}, seat.PipelineOutcomeSuperseded},
|
|
// H-A-508: a build the builder ended superseded moves its mover out as a newer pipeline taking it does: its other open
|
|
// steps end superseded, it is kept in superseded, and the pipeline passes by its other movers, never failed.
|
|
{"its last open step, a build, ends superseded (H-A-508)",
|
|
[]seat.StepResult{step("a", seat.StepResultOutcomeRunning, "x1"), {Module: "a", Artifact: "program", Step: seat.StepResultStepUnit,
|
|
Status: seat.StepResultStatusRequired, Outcome: seat.StepResultOutcomeWaiting, Seat: "node-build-go"},
|
|
{Module: "a", Artifact: "program", Step: seat.StepResultStepLint, Status: seat.StepResultStatusRequired, Outcome: seat.StepResultOutcomeRunning,
|
|
Ask: "l1", Seat: "node-build-go"},
|
|
step("b", seat.StepResultOutcomePassed, "x2"), step("c", seat.StepResultOutcomePassed, "x3")},
|
|
func(t *testing.T, h *Hearer) {
|
|
// Another seat's end naming superseded is an outcome the runner does not know: refused, loud, nothing taken.
|
|
gs := stepSeatOf(t, "node-build-go")
|
|
lint := StepEnded{ID: "l1", Node: "n1", Pipeline: "main.117", Module: "a", Commit: "c1", Fingerprint: "src2:a1", Step: "lint",
|
|
Outcome: builds.StepEndedOutcomeSuperseded}
|
|
if _, err := h.OnStepEnded(gs, gs.Prefix+"n1", lint); !errors.Is(err, ErrRefused) || !strings.Contains(err.Error(), "not an outcome of step-ended") {
|
|
t.Errorf("a node-build-go end naming superseded: %v, want refused as no outcome of step-ended", err)
|
|
}
|
|
if p, _, _ := h.Store.Get("main.117"); p.Steps[2].Outcome != seat.StepResultOutcomeRunning {
|
|
t.Errorf("the refused end moved the lint step: %+v", p.Steps[2])
|
|
}
|
|
bs := stepSeatOf(t, builds.Seat)
|
|
end := StepEnded{ID: "x1", Node: "n1", Pipeline: "main.117", Module: "a", Commit: "c1", Fingerprint: "src2:a1", Step: "build",
|
|
Outcome: builds.StepEndedOutcomeSuperseded, Said: "a at src2:a1 is superseded by src2:a2, the newest entry heard on its first branch"}
|
|
if _, err := h.OnStepEnded(bs, bs.Prefix+"n1", end); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
p, _, _ := h.Store.Get("main.117")
|
|
if !slices.Equal(p.Superseded, []string{"a"}) || p.Steps[0].Outcome != seat.StepResultOutcomeSuperseded || !strings.Contains(p.Steps[0].Why, "src2:a2") ||
|
|
p.Steps[1].Outcome != seat.StepResultOutcomeSuperseded || p.Steps[2].Outcome != seat.StepResultOutcomeSuperseded {
|
|
t.Errorf("after a's build ended superseded: superseded %v, steps %+v; want a left, its build and unit superseded naming src2:a2", p.Superseded, p.Steps[:3])
|
|
}
|
|
}, seat.PipelineOutcomePassed},
|
|
{"its last open step ends could not run on the silent bound (H-A-243)",
|
|
[]seat.StepResult{step("a", seat.StepResultOutcomeRunning, "mwql5pio3390aa"), step("b", seat.StepResultOutcomePassed, "x2"), step("c", seat.StepResultOutcomePassed, "x3")},
|
|
func(t *testing.T, h *Hearer) {
|
|
if err := h.endUnanswered("main.117", "mwql5pio3390aa", UntakenWhy("mesh-wants")); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}, seat.PipelineOutcomeFailed},
|
|
{"the runner's start pass finds it with nothing open",
|
|
[]seat.StepResult{step("a", seat.StepResultOutcomePassed, "x1"), step("b", seat.StepResultOutcomePassed, "x2"), step("c", seat.StepResultOutcomePassed, "x3")},
|
|
func(t *testing.T, h *Hearer) {
|
|
if n, err := h.EndAtStart(); n != 1 || err != nil {
|
|
t.Fatalf("the start pass ended %d (%v), want 1", n, err)
|
|
}
|
|
}, seat.PipelineOutcomePassed},
|
|
}
|
|
for _, r := range rows {
|
|
t.Run(r.name, func(t *testing.T) {
|
|
store := &refusedOnce{memStore: memStore{}, refused: map[string]bool{}}
|
|
store.memStore["main.117"] = struct {
|
|
p seat.Pipeline
|
|
rev uint64
|
|
}{seat.Pipeline{V: 1, Pipeline: "main.117", Branch: "main", Source: 117, Revision: 117, Outcome: seat.PipelineOutcomeRunning,
|
|
Movers: slices.Clone(movers), Steps: slices.Clone(r.steps)}, 1}
|
|
// Another running pipeline with a step open, and one waiting its turn: neither ends.
|
|
store.memStore["main.118"] = struct {
|
|
p seat.Pipeline
|
|
rev uint64
|
|
}{seat.Pipeline{V: 1, Pipeline: "main.118", Branch: "other", Source: 118, Revision: 118, Outcome: seat.PipelineOutcomeRunning,
|
|
Movers: movers[:1], Steps: []seat.StepResult{step("a", seat.StepResultOutcomeRunning, "y1")}}, 1}
|
|
store.memStore["main.119"] = struct {
|
|
p seat.Pipeline
|
|
rev uint64
|
|
}{seat.Pipeline{V: 1, Pipeline: "main.119", Branch: "other", Source: 119, Revision: 119, Outcome: seat.PipelineOutcomeWaiting, Movers: movers[:1]}, 1}
|
|
store.refused["main.118"], store.refused["main.119"] = true, true
|
|
grants, revisions := 0, 0
|
|
w := &Widener{
|
|
Revision: func(string, int64) (Half, error) { revisions++; return Half{}, nil },
|
|
Holder: func(s string) (string, error) { return s, nil },
|
|
GrantsFor: func(string, int64) (meshgrants.GrantsFor, error) {
|
|
grants++
|
|
return meshgrants.GrantsFor{}, fmt.Errorf("cut after 5s")
|
|
},
|
|
}
|
|
var turned, journal []string
|
|
h := &Hearer{Store: store, Say: func(string, any) error { return nil }, Now: func() time.Time { return t0 }, Widens: w.Reads,
|
|
Turn: func(key string) { turned = append(turned, key) },
|
|
Logf: func(f string, a ...any) { journal = append(journal, fmt.Sprintf(f, a...)) }}
|
|
r.end(t, h)
|
|
p, _, _ := store.Get("main.117")
|
|
if p.Outcome != r.outcome {
|
|
t.Fatalf("main.117 = %s (%s), want %s", p.Outcome, p.Why, r.outcome)
|
|
}
|
|
if !slices.Equal(turned, []string{"main.117"}) {
|
|
t.Errorf("the turns freed = %v, want main.117's alone, so the next waiting is placed", turned)
|
|
}
|
|
if !slices.ContainsFunc(journal, func(l string) bool { return strings.HasPrefix(l, "main.117 ended "+r.outcome) }) {
|
|
t.Errorf("the journal does not say main.117's end %s: %q", r.outcome, journal)
|
|
}
|
|
if grants != 1 || revisions != 2 {
|
|
t.Errorf("the end asked grants-for %d times and a revision %d times over 3 movers and a refused write, want 1 and 2", grants, revisions)
|
|
}
|
|
for _, m := range p.Movers {
|
|
if len(m.Widens) != 1 || m.Widens[0].Name != "mesh-grants" {
|
|
t.Errorf("%s's widens = %+v, want the cut grants-for said", m.Module, m.Widens)
|
|
}
|
|
}
|
|
for _, k := range []string{"main.118", "main.119"} {
|
|
if q, _, _ := store.Get(k); q.Outcome == seat.PipelineOutcomeSuperseded || q.Outcome == seat.PipelineOutcomePassed || q.Outcome == seat.PipelineOutcomeFailed {
|
|
t.Errorf("%s ended %s with a step open or waiting its turn", k, q.Outcome)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
// H-A-508, H-A-361: a dependent that stays, whose steps ended not asked on the mover whose build ended superseded, is
|
|
// taken out and placed again; the pipeline does not end on it, and the superseded build's end is said as its own step's.
|
|
t.Run("a dependent that stays is placed again when its dependency's build ends superseded", func(t *testing.T) {
|
|
store := memStore{"main.117": {p: seat.Pipeline{V: 1, Pipeline: "main.117", Branch: "main", Source: 117, Revision: 117, Outcome: seat.PipelineOutcomeRunning,
|
|
Movers: slices.Clone(movers[:2]), Steps: []seat.StepResult{step("b", seat.StepResultOutcomeNotAsked, ""), step("a", seat.StepResultOutcomeRunning, "x1")}}, rev: 1}}
|
|
e := store["main.117"]
|
|
e.p.Steps[0].Why = notBuiltWhy("a")
|
|
store["main.117"] = e
|
|
var released []string
|
|
h := &Hearer{Store: store, Say: func(string, any) error { return nil }, Now: func() time.Time { return t0 }, Release: func(key string) { released = append(released, key) }}
|
|
bs := stepSeatOf(t, builds.Seat)
|
|
got, err := h.OnStepEnded(bs, bs.Prefix+"n1", StepEnded{ID: "x1", Node: "n1", Pipeline: "main.117", Module: "a", Commit: "c1", Fingerprint: "src2:a1",
|
|
Step: "build", Outcome: builds.StepEndedOutcomeSuperseded, Said: "a at src2:a1 is superseded by src2:a2"})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got.Outcome != seat.PipelineOutcomeRunning || !slices.Equal(got.Superseded, []string{"a"}) || len(got.Steps) != 1 || got.Steps[0].Module != "a" ||
|
|
got.Steps[0].Outcome != seat.StepResultOutcomeSuperseded || !slices.Equal(released, []string{"main.117"}) {
|
|
t.Errorf("pipeline %s superseded %v steps %+v released %v; want running, a left, b taken out to be placed again", got.Outcome, got.Superseded, got.Steps, released)
|
|
}
|
|
})
|
|
}
|