The bound key ask.<seat>.<ask> is armed at the put, again at the holder's ask-taken (heard now for mesh-builds and mesh-wants too) with what is left since taken-at, again from now at each step-progress, and at a start for every open ask whose key is gone; it is deleted at the step's end. Past it the step ends could-not-run, naming an untaken ask's seat holder as taking none, and its ask is dropped through the seat's drop. The silent seats' bound, the second put under AgainID, the ask2. keys and the put again at a holder's running go; a put refused by a full work queue is said and put again at the kept-call pace. Builds: design 47 H2 §777, §778 (H-A-349 DQ-4, H-A-395)
130 lines
6.3 KiB
Go
130 lines
6.3 KiB
Go
package pipeline
|
|
|
|
import (
|
|
"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},
|
|
{"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)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|