Runner: say the end again only for a passed pipeline, and again on a version heard again
A say that failed after the version was written was lost: the redelivery found the version held and said nothing. A failed, superseded or cancelled end writes no want, so it is not said again. Builds: design 47 H H-A-270 (2), H-A-277 (2), (3)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package pipeline
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -110,8 +111,8 @@ func TestThePipelinePassesOnNothingToRunAndFailsOnOneMover(t *testing.T) {
|
||||
// of the source revision built, on the branch it was released for, so pipeline-ended names it; another branch's pipeline,
|
||||
// and a version heard again, write nothing.
|
||||
//
|
||||
// H-A-270 (2): a version written into a pipeline whose end was already said says its pipeline-ended again, naming the
|
||||
// version; a pipeline still running says nothing.
|
||||
// H-A-270 (2), H-A-277 (2), (3): a version written into a pipeline that ended passed says its pipeline-ended again, naming the
|
||||
// version; one still running, or ended failed, says nothing. A say that failed is said when the version is heard again.
|
||||
func TestAReleasedVersionIsTheMoversVersion(t *testing.T) {
|
||||
h, store, bodies, order := twoMovers(t)
|
||||
other := store[pkey]
|
||||
@@ -124,13 +125,29 @@ func TestAReleasedVersionIsTheMoversVersion(t *testing.T) {
|
||||
again.p.Pipeline, again.p.Source, again.p.Movers = key, source, append([]seat.Mover(nil), again.p.Movers...)
|
||||
store[key] = again
|
||||
}
|
||||
done := store[pkey]
|
||||
at := time.Unix(1, 0)
|
||||
done.p.Ended, done.p.Outcome = &at, seat.PipelineOutcomePassed
|
||||
store[pkey] = done
|
||||
for key, outcome := range map[string]string{pkey: seat.PipelineOutcomePassed, "beta.5": seat.PipelineOutcomeFailed} {
|
||||
done := store[key]
|
||||
done.p.Ended, done.p.Outcome = &at, outcome
|
||||
store[key] = done
|
||||
}
|
||||
say := h.Say
|
||||
fail := true
|
||||
h.Say = func(subject string, body any) error {
|
||||
if fail {
|
||||
fail = false
|
||||
return errors.New("the bus is away")
|
||||
}
|
||||
return say(subject, body)
|
||||
}
|
||||
ev := catalog.VersionReleasedEvent{Module: "app", Version: "0.4.1", Source: 5}
|
||||
if n, err := h.Released(ev, "main"); n != 2 || err != nil {
|
||||
t.Fatalf("released wrote %d (%v), want app's mover of main.5 and main.8", n, err)
|
||||
first, err := h.Released(ev, "main")
|
||||
if err == nil || len(*order) != 0 {
|
||||
t.Fatalf("released wrote %d (%v) and said %v, want the failed say returned", first, err, *order)
|
||||
}
|
||||
// Heard again (the nak's redelivery), main.5's version is held already and its end is said (H-A-277 (3)).
|
||||
if n, err := h.Released(ev, "main"); first+n != 2 || err != nil {
|
||||
t.Fatalf("released wrote %d, then %d again (%v), want app's mover of main.5 and main.8", first, n, err)
|
||||
}
|
||||
if m, _ := MoverOf(store["main.6"].p, "app"); m.Version != "" {
|
||||
t.Errorf("main.6's mover = %+v, want no version: another source", m)
|
||||
@@ -148,8 +165,12 @@ func TestAReleasedVersionIsTheMoversVersion(t *testing.T) {
|
||||
if len(*order) != 1 {
|
||||
t.Errorf("said %v, want only main.5's end again: main.8 has not ended", *order)
|
||||
}
|
||||
if n, _ := h.Released(ev, "main"); n != 0 || len(*order) != 1 {
|
||||
t.Errorf("the version heard again wrote %d and said %v", n, *order)
|
||||
if n, _ := h.Released(ev, "main"); n != 0 || len(*order) != 2 {
|
||||
t.Errorf("the version heard once more wrote %d and said %v, want main.5's end said again", n, *order)
|
||||
}
|
||||
// beta's failed pipeline, its version written, is never said again (H-A-277 (2)).
|
||||
if n, _ := h.Released(ev, ""); n != 1 || len(*order) != 3 {
|
||||
t.Errorf("released for every branch wrote %d and said %v, want beta's mover written and main.5's end alone said", n, *order)
|
||||
}
|
||||
if got := pipelineEnded(store[pkey].p).Movers[1]; got.Module != "app" || got.Version != "0.4.1" {
|
||||
t.Errorf("pipeline-ended names %+v, want app at 0.4.1", got)
|
||||
|
||||
@@ -12,8 +12,8 @@ import (
|
||||
// Released writes a version-released's version into the entry of the mover it names (design 47 H §746, H-A-52): the mover of
|
||||
// that module in each pipeline of the source revision built, a run's aside, so its pipeline-ended names the released version.
|
||||
// branch, when not empty, is the one watched branch the version was released for (H-A-62); empty matches every branch's
|
||||
// pipeline of that source. A pipeline whose end was said already says it again, naming the version (H-A-270 (2)). It says how
|
||||
// many movers it wrote.
|
||||
// pipeline of that source. A pipeline that ended passed says its end again, naming the version, and again whenever the version
|
||||
// is heard again (H-A-270 (2), H-A-277). It says how many movers it wrote.
|
||||
func (h *Hearer) Released(ev catalog.VersionReleasedEvent, branch string) (int, error) {
|
||||
if ev.Module == "" || ev.Version == "" || ev.Source <= 0 {
|
||||
return 0, fmt.Errorf("a version-released names its module, version and source revision: %+v", ev)
|
||||
@@ -48,7 +48,15 @@ func (h *Hearer) Released(ev catalog.VersionReleasedEvent, branch string) (int,
|
||||
i = j
|
||||
}
|
||||
}
|
||||
if i < 0 || p.Movers[i].Version == ev.Version {
|
||||
if i < 0 {
|
||||
break
|
||||
}
|
||||
if p.Movers[i].Version == ev.Version {
|
||||
// A version heard again says the end of an ended passed pipeline again (H-A-277 (3)): a say that failed after
|
||||
// the version was written is said now; taking it again is a no-op for the holder.
|
||||
if err := h.sayEndedAgain(key, p, ev); err != nil {
|
||||
return wrote, err
|
||||
}
|
||||
break
|
||||
}
|
||||
p.Movers[i].Version = ev.Version
|
||||
@@ -60,12 +68,8 @@ func (h *Hearer) Released(ev catalog.VersionReleasedEvent, branch string) (int,
|
||||
wrote++
|
||||
// A version written after the pipeline's end was said says that end again (H-A-270 (2)): the same pipeline-ended,
|
||||
// now naming the version, so the seat mesh-wants' holder takes the mover it skipped; taking a mover again is a no-op.
|
||||
if p.Ended != nil {
|
||||
if err := h.say(seat.EventPipelineEnded, p, nil); err != nil {
|
||||
return wrote, fmt.Errorf("the version %s of %s is written into the ended pipeline %s but its %s is not said again: %w",
|
||||
ev.Version, ev.Module, key, seat.EventPipelineEnded, err)
|
||||
}
|
||||
h.logf("%s: the version %s of %s is written after its end: %s said again", key, ev.Version, ev.Module, seat.EventPipelineEnded)
|
||||
if err := h.sayEndedAgain(key, p, ev); err != nil {
|
||||
return wrote, err
|
||||
}
|
||||
break
|
||||
}
|
||||
@@ -76,6 +80,20 @@ func (h *Hearer) Released(ev catalog.VersionReleasedEvent, branch string) (int,
|
||||
return wrote, nil
|
||||
}
|
||||
|
||||
// sayEndedAgain says p's pipeline-ended again when p ended passed (H-A-270 (2), H-A-277 (2)): only a passed end writes a want,
|
||||
// so a superseded, cancelled or failed one is not said again.
|
||||
func (h *Hearer) sayEndedAgain(key string, p seat.Pipeline, ev catalog.VersionReleasedEvent) error {
|
||||
if p.Ended == nil || p.Outcome != seat.PipelineOutcomePassed {
|
||||
return nil
|
||||
}
|
||||
if err := h.say(seat.EventPipelineEnded, p, nil); err != nil {
|
||||
return fmt.Errorf("the version %s of %s is in the ended pipeline %s but its %s is not said again: %w",
|
||||
ev.Version, ev.Module, key, seat.EventPipelineEnded, err)
|
||||
}
|
||||
h.logf("%s: the version %s of %s is written after its end: %s said again", key, ev.Version, ev.Module, seat.EventPipelineEnded)
|
||||
return nil
|
||||
}
|
||||
|
||||
// ReleasedBranch is the watched branch a module's versions are released for, its registration's first (H-A-62); empty when
|
||||
// the registration is not held.
|
||||
func ReleasedBranch(reg func(string) (catalog.Registration, bool), module string) string {
|
||||
|
||||
Reference in New Issue
Block a user