Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
41ca769fcb | ||
|
|
167eded5f1 | ||
|
|
e76e49e6a3 | ||
|
|
c0c6228ebb | ||
|
|
74bb7b4401 | ||
|
|
93d9d0ea13 | ||
|
|
3ae5fbdf1a | ||
|
|
2ce0acced1 | ||
|
|
da20b45a04 | ||
|
|
a5a7afdfa4 | ||
|
|
a2b916a896 | ||
|
|
1a19c5c4c1 | ||
|
|
367df6cadd | ||
|
|
a1379ef084 | ||
|
|
b53a3fd575 | ||
|
|
55ab8a82d0 | ||
|
|
bf18ae74cb | ||
|
|
ea5abba84d | ||
|
|
8614f0baf7 | ||
|
|
9afc8a160d | ||
|
|
600a4a99a5 | ||
|
|
6a550f59f6 | ||
|
|
b6702196b8 | ||
|
|
f6aff0182c | ||
|
|
ed0b905767 | ||
|
|
28726acaaf | ||
|
|
7bacccf562 | ||
|
|
29c4673ad1 | ||
|
|
a8240f5549 | ||
|
|
5792e83bc6 | ||
|
|
678d8fa5b3 | ||
|
|
b2d9d1ac90 | ||
|
|
6ffddedfbf | ||
|
|
146b9b4ff8 | ||
|
|
1d0a40592b | ||
|
|
7be95905f2 | ||
|
|
04fe2e30fe | ||
|
|
52ad5af1e9 | ||
|
|
cd16358b21 | ||
|
|
0c2ead025d | ||
|
|
5ab9bd9acc |
@@ -0,0 +1,152 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"maps"
|
||||
"slices"
|
||||
|
||||
mmac "git.novox.be/novox/mesh-contracts/go/clients/meshmoduleassignerclient"
|
||||
mma "git.novox.be/novox/mesh-contracts/go/seats/meshmoduleassigner"
|
||||
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient"
|
||||
mcc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||
"git.novox.be/novox/mesh-sdk/go/buscalls"
|
||||
)
|
||||
|
||||
// assignmentDropTool drops one assignment key of a module no manifest names any more by hand (design 47 H2 H-A-509): a
|
||||
// module key `<node>.<module>` of a retired module, as the clean state of the pass drops it, the act written in the
|
||||
// hand-act log first.
|
||||
const assignmentDropTool = "assigner_assignment_drop"
|
||||
|
||||
// assignmentLeft is why a module key `<node>.<module>` is not dropped, "" when it may be (H-A-509 and its second
|
||||
// addendum, and the lead's answer of review round 1): only when no watched branch's catalog half holds the module (trunk, as
|
||||
// world.trunk is) and the node key does not name it, since the node key is the commit of a write and a hand act never leaves
|
||||
// one node's keys disagreeing; nothing while no half holds any module.
|
||||
func assignmentLeft(node, module string, trunk map[string]bool, nodeRaw []byte, nodeFound bool) string {
|
||||
switch {
|
||||
case len(trunk) == 0:
|
||||
return "no watched branch's catalog half holds a module yet, so no module is known to be retired"
|
||||
case trunk[module]:
|
||||
return "a watched branch's catalog half holds " + module
|
||||
case !nodeFound:
|
||||
return ""
|
||||
}
|
||||
n, err := mmac.DecodeNode(nodeRaw)
|
||||
if err != nil {
|
||||
return fmt.Sprintf("the node key of %s does not read, so whether it names %s is not known: %v", node, module, err)
|
||||
}
|
||||
if slices.ContainsFunc(n.Modules, func(r mma.AssignmentsByNodeNodeValueModulesItem) bool { return r.Module == module }) {
|
||||
return "the node key of " + node + " still names " + module + ", so it stays placed there"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// dropAssignment deletes the module key of module on node, the act first recorded through the seat mesh-hand-acts; trunk
|
||||
// answers every module a watched branch's catalog half holds.
|
||||
func dropAssignment(st seatStore, ask func(string, any) (json.RawMessage, error), trunk func() (map[string]bool, error), node, module, why, by string) (any, error) {
|
||||
switch {
|
||||
case node == "" || module == "":
|
||||
return nil, errors.New("name the node and the module whose assignment key is dropped")
|
||||
case why == "":
|
||||
return nil, errors.New("an assignment key dropped by hand says why")
|
||||
case by == "" || by == stdio.Unproven:
|
||||
return nil, errors.New("an assignment key dropped by hand names who drops it, and the runtime proved no caller")
|
||||
}
|
||||
key, err := mmac.ModuleKey(node, module)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
nodeKey, err := mmac.NodeKey(node)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
raw, _, found, err := st.get(mma.StateAssignments, key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !found {
|
||||
return nil, fmt.Errorf("the assigner holds no assignment key %s", key)
|
||||
}
|
||||
modules, err := trunk()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("the watched branches' modules cannot be read, so %s stays: %w", key, err)
|
||||
}
|
||||
nodeRaw, _, nodeFound, err := st.get(mma.StateAssignments, nodeKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if left := assignmentLeft(node, module, modules, nodeRaw, nodeFound); left != "" {
|
||||
return nil, fmt.Errorf("the assignment key %s stays: %s", key, left)
|
||||
}
|
||||
taken, err := meshhandactsclient.Recorder{Ask: ask}.Record(meshhandactsclient.Request{What: assignmentDropTool + " " + key, Why: why + " (" + by + ")", Cause: "assignment-drop"})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("the drop of %s is not recorded, so the key stays: %w", key, err)
|
||||
}
|
||||
if err := st.del(mma.StateAssignments, key); err != nil {
|
||||
return nil, fmt.Errorf("the assignment key %s is not dropped: %w", key, err)
|
||||
}
|
||||
return map[string]any{"key": key, "dropped": json.RawMessage(raw), "by": by, "hand-act": taken.Log}, nil
|
||||
}
|
||||
|
||||
// watchedModules is every module any watched branch's catalog half holds, as the pass's world.trunk is (design 47 H2 H-A-509,
|
||||
// the lead's answer of review round 1): the watched branches of the seat mesh-catalog's registrations, each branch's revision
|
||||
// read whole through the verb revision, page by page; a branch with none yet holds none.
|
||||
func watchedModules(call mcc.Call) func() (map[string]bool, error) {
|
||||
return func() (map[string]bool, error) {
|
||||
raw, err := call(mcc.RegistrationsVerb, meshcatalog.RegistrationsInput{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
answer, said, ok := buscalls.Unwrap(raw)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("%s answered: %s", mcc.RegistrationsVerb, said)
|
||||
}
|
||||
var regs meshcatalog.RegistrationsAnswer
|
||||
if err := json.Unmarshal(answer, ®s); err != nil || regs.Registrations == nil {
|
||||
return nil, fmt.Errorf("%s answered no registrations: %v", mcc.RegistrationsVerb, err)
|
||||
}
|
||||
branches := map[string]bool{}
|
||||
for _, reg := range regs.Registrations {
|
||||
for _, b := range reg.Branches {
|
||||
branches[b] = true
|
||||
}
|
||||
}
|
||||
out := map[string]bool{}
|
||||
for _, branch := range slices.Sorted(maps.Keys(branches)) {
|
||||
for after := ""; ; {
|
||||
a, err := askCandidatePage(call, meshcatalog.RevisionInput{Branch: branch, After: after})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("the catalog half of %s cannot be read: %w", branch, err)
|
||||
}
|
||||
if a.NoneYet {
|
||||
break
|
||||
}
|
||||
for _, e := range a.Entries {
|
||||
out[e.Module] = true
|
||||
}
|
||||
if a.Next == "" {
|
||||
break
|
||||
}
|
||||
after = a.Next
|
||||
}
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
}
|
||||
|
||||
// assignmentDropTools is the tool over the runtime's states.
|
||||
func assignmentDropTools(st seatStore, ask func(string, any) (json.RawMessage, error), trunk func() (map[string]bool, error)) []stdio.Tool {
|
||||
return []stdio.Tool{{Name: assignmentDropTool, Description: "Drop one assignment key by hand (design 47 H2 H-A-509): the module " +
|
||||
"key <node>.<module> of the seat mesh-module-assigner's assignments, for a module no watched branch's catalog half holds any more " +
|
||||
"(a retired module's key, which may predate the value's version), as the clean state of the pass drops it. Refused while a " +
|
||||
"watched branch's catalog half holds the module, while the node key <node>.node still names it, or with no key there. Recorded as a " +
|
||||
"hand act first.",
|
||||
Input: schema(map[string]string{"node": "the node's name", "module": "the module's name", "why": "why the key is dropped"},
|
||||
[]string{"node", "module", "why"}),
|
||||
Run: func(a map[string]any) (any, error) {
|
||||
return dropAssignment(st, ask, trunk, arg(a, "node"), arg(a, "module"), arg(a, "why"), stdio.CallerOf(a))
|
||||
}}}
|
||||
}
|
||||
+175
@@ -0,0 +1,175 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
mmac "git.novox.be/novox/mesh-contracts/go/clients/meshmoduleassignerclient"
|
||||
mma "git.novox.be/novox/mesh-contracts/go/seats/meshmoduleassigner"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
|
||||
plc "mesh-delivery-assigner/internal/assignment"
|
||||
)
|
||||
|
||||
// H-A-509 and its second addendum: a module key of a module no manifest of the trunk names, that the node key does not name,
|
||||
// is dropped, by hand through assigner_assignment_drop (recorded as a hand act first) and at the pass's clean state (named in
|
||||
// the journal); a key a manifest of the trunk still names, or the node key still names, stays; nothing goes while the trunk
|
||||
// is empty.
|
||||
func TestARetiredModulesAssignmentKeyIsDropped(t *testing.T) {
|
||||
// novox places web; the key of the retired checker predates the value's version; the key of the retired old is still
|
||||
// named by the node key.
|
||||
values, err := mmac.AssignmentsValues(mma.Assignments{V: mmac.Version, Node: "novox", Modules: []mma.PlacedModule{{Module: "web"}, {Module: "old"}}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
values["novox.checker"] = []byte(`{"node":"novox"}`)
|
||||
checker, web, old := "novox.checker", "novox.web", "novox.old"
|
||||
trunkOf := func(names ...string) map[string]bool {
|
||||
out := map[string]bool{}
|
||||
for _, n := range names {
|
||||
out[n] = true
|
||||
}
|
||||
return out
|
||||
}
|
||||
copyOf := func() map[string][]byte {
|
||||
out := map[string][]byte{}
|
||||
for k, v := range values {
|
||||
out[k] = v
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
t.Run("by hand", func(t *testing.T) {
|
||||
for _, c := range []struct {
|
||||
name, module string
|
||||
trunk map[string]bool
|
||||
refuse error
|
||||
dropped bool
|
||||
}{
|
||||
{"a retired module's key", "checker", trunkOf("web"), nil, true},
|
||||
{"a manifest of the trunk names it", "web", trunkOf("web"), nil, false},
|
||||
{"the node key still names it", "old", trunkOf("web"), nil, false},
|
||||
{"the trunk is empty", "checker", trunkOf(), nil, false},
|
||||
{"no key there", "gone", trunkOf("web"), nil, false},
|
||||
{"not recorded", "checker", trunkOf("web"), errors.New("no responders"), false},
|
||||
} {
|
||||
st := memStore{mma.StateAssignments: &memKV{values: copyOf()}}
|
||||
var asked []string
|
||||
ask := func(verb string, body any) (json.RawMessage, error) {
|
||||
raw, _ := json.Marshal(body)
|
||||
asked = append(asked, verb+" "+string(raw))
|
||||
return json.RawMessage(`{}`), c.refuse
|
||||
}
|
||||
trunk := func() (map[string]bool, error) { return c.trunk, nil }
|
||||
out, err := dropAssignment(st, ask, trunk, "novox", c.module, "retired", "person.jochen")
|
||||
key := "novox." + c.module
|
||||
_, there := st[mma.StateAssignments].values[key]
|
||||
switch {
|
||||
case c.dropped && (err != nil || there || len(asked) != 1 || !strings.Contains(asked[0], assignmentDropTool+" "+key)):
|
||||
t.Errorf("%s: %v, %v; the key left %v, asked %v", c.name, out, err, there, asked)
|
||||
case !c.dropped && err == nil:
|
||||
t.Errorf("%s: %v, want it refused", c.name, out)
|
||||
case len(st[mma.StateAssignments].values) != len(values)-btoi(c.dropped):
|
||||
t.Errorf("%s: %d keys left, want %d", c.name, len(st[mma.StateAssignments].values), len(values)-btoi(c.dropped))
|
||||
}
|
||||
}
|
||||
if _, err := dropAssignment(memStore{mma.StateAssignments: &memKV{values: copyOf()}}, nil, func() (map[string]bool, error) { return trunkOf("web"), nil },
|
||||
"novox", "checker", "", "person.jochen"); err == nil {
|
||||
t.Error("a drop with no why is not refused")
|
||||
}
|
||||
})
|
||||
|
||||
// The tool judges against every watched branch's half, as the pass does (the lead's answer of review round 1): the branches
|
||||
// of the registrations, each read page by page; a branch with none yet holds none.
|
||||
t.Run("every watched branch", func(t *testing.T) {
|
||||
call := func(verb string, body any) (json.RawMessage, error) {
|
||||
switch verb {
|
||||
case meshcatalogclient.RegistrationsVerb:
|
||||
return json.Marshal(meshcatalog.RegistrationsAnswer{Registrations: []meshcatalog.Registration{{Module: "web", Branches: []string{"main", "feature"}}, {Module: "db", Branches: []string{"fresh"}}}})
|
||||
case meshcatalogclient.RevisionVerb:
|
||||
in := body.(meshcatalog.RevisionInput)
|
||||
switch {
|
||||
case in.Branch == "main" && in.After == "":
|
||||
return json.Marshal(meshcatalog.RevisionAnswer{Revision: &meshcatalog.CatalogRevision{}, Entries: []meshcatalog.CatalogEntry{{Module: "web"}}, Next: "web"})
|
||||
case in.Branch == "main":
|
||||
return json.Marshal(meshcatalog.RevisionAnswer{Revision: &meshcatalog.CatalogRevision{}, Entries: []meshcatalog.CatalogEntry{{Module: "db"}}})
|
||||
case in.Branch == "feature":
|
||||
return json.Marshal(meshcatalog.RevisionAnswer{Revision: &meshcatalog.CatalogRevision{}, Entries: []meshcatalog.CatalogEntry{{Module: "new"}}})
|
||||
}
|
||||
return json.Marshal(meshcatalog.RevisionAnswer{NoneYet: true})
|
||||
}
|
||||
return nil, errors.New("no such verb " + verb)
|
||||
}
|
||||
got, err := watchedModules(call)()
|
||||
if err != nil || len(got) != 3 || !got["web"] || !got["db"] || !got["new"] {
|
||||
t.Errorf("watchedModules = %v, %v; want web, db and new", got, err)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("at the pass", func(t *testing.T) {
|
||||
for _, c := range []struct {
|
||||
name string
|
||||
trunk []string
|
||||
gone []string
|
||||
}{
|
||||
{"a retired module's key goes, one the node key names stays", []string{"web"}, []string{checker}},
|
||||
{"the trunk is empty", nil, nil},
|
||||
} {
|
||||
kv := &memKV{values: copyOf()}
|
||||
p := newPasser(kvSet{plc.AssignmentsBucket(): kv}, time.Now())
|
||||
var said []string
|
||||
p.logf = func(f string, a ...any) { said = append(said, f) }
|
||||
for k, v := range kv.values {
|
||||
p.w.put(plc.AssignmentsBucket(), k, v)
|
||||
}
|
||||
// web is held by a watched branch that is not the trunk's first: the pass judges against every watched branch's half.
|
||||
for _, n := range c.trunk {
|
||||
mod, _ := meshcatalogclient.EncodeModule(meshcatalog.ModulesByModuleValue{Fp2: fpTest, Repository: "novox/" + n, Commit: strings.Repeat("1", 40), Path: meshcatalogclient.RootPath})
|
||||
putModuleRaw(p.w, "feature", n, mod)
|
||||
}
|
||||
for range 2 {
|
||||
p.wants(context.Background())
|
||||
}
|
||||
for _, key := range []string{checker, web, old, "novox.node"} {
|
||||
_, there := kv.values[key]
|
||||
if want := !contains(c.gone, key); there != want {
|
||||
t.Errorf("%s: %s left = %v, want %v", c.name, key, there, want)
|
||||
}
|
||||
}
|
||||
if dropped, left := countSaid(said, "is dropped"), countSaid(said, "is left"); len(c.gone) > 0 && (dropped != 1 || left != 1) {
|
||||
t.Errorf("%s: said dropped %d and left %d times, want once each: %v", c.name, dropped, left, said)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func btoi(b bool) int {
|
||||
if b {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func contains(list []string, s string) bool {
|
||||
for _, x := range list {
|
||||
if x == s {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func countSaid(said []string, words string) int {
|
||||
n := 0
|
||||
for _, s := range said {
|
||||
if strings.Contains(s, words) {
|
||||
n++
|
||||
}
|
||||
}
|
||||
return n
|
||||
}
|
||||
@@ -96,21 +96,22 @@ func TestTheWantsAreSaidWantedFromTheKeptAssignmentGraphRevision(t *testing.T) {
|
||||
if err := json.Unmarshal(events[len(events)-1].body, &w); err != nil || len(events) != 3 || !w.Removed || w.Fp != fpTest {
|
||||
t.Errorf("a removing want said %+v (%v), %d events", w, err, len(events))
|
||||
}
|
||||
// Design 47 H2 §813 (1), H-A-416: a want carries its run, its pipeline's source in decimal, or the newest source held for a
|
||||
// want of no pipeline; it is written by compare-and-set refusing a lower run, and one that differs only by its run stands.
|
||||
// Design 47 H2 §813 (1), H-A-504 corrected and its addendum: a want of a pipeline carries its run, the pipeline's sequence the
|
||||
// want rule set; a want of no pipeline the newest source held. It is written by compare-and-set refusing a lower run, and
|
||||
// one that differs only by its run stands.
|
||||
t.Run("a want's run", func(t *testing.T) {
|
||||
wkey, _ := mwc.WantKey("g14", "db")
|
||||
stored := func() mwc.Want { w, _ := mwc.DecodeWant(kv.values[wkey]); return w }
|
||||
p.putWant(ctx, "g14", "db", mwc.Want{Fp: fpTest, Version: "0.1.2", Pipeline: "main.12", Rank: 1})
|
||||
if w := stored(); w.Run != "12" || w.Pipeline != "main.12" {
|
||||
t.Fatalf("the want of pipeline main.12 is %+v, want run 12", w)
|
||||
p.putWant(ctx, "g14", "db", mwc.Want{Fp: fpTest, Version: "0.1.2", Pipeline: "main.12", Rank: 1, Run: "212"})
|
||||
if w := stored(); w.Run != "212" || w.Pipeline != "main.12" {
|
||||
t.Fatalf("the want of pipeline main.12 is %+v, want run 212", w)
|
||||
}
|
||||
puts := kv.puts
|
||||
p.putWant(ctx, "g14", "db", mwc.Want{Fp: fpTest, Version: "0.1.1", Pipeline: "main.11", Rank: 1})
|
||||
if w := stored(); w.Run != "12" || w.Version != "0.1.2" || kv.puts != puts {
|
||||
p.putWant(ctx, "g14", "db", mwc.Want{Fp: fpTest, Version: "0.1.1", Pipeline: "main.11", Rank: 1, Run: "211"})
|
||||
if w := stored(); w.Run != "212" || w.Version != "0.1.2" || kv.puts != puts {
|
||||
t.Errorf("a want of a lower run replaced %+v (%d writes)", w, kv.puts-puts)
|
||||
}
|
||||
p.putWant(ctx, "g14", "db", mwc.Want{Fp: fpTest, Version: "0.1.2", Pipeline: "main.12", Rank: 1})
|
||||
p.putWant(ctx, "g14", "db", mwc.Want{Fp: fpTest, Version: "0.1.2", Pipeline: "main.12", Rank: 1, Run: "212"})
|
||||
if kv.puts != puts {
|
||||
t.Error("a want that stands was written again")
|
||||
}
|
||||
@@ -119,10 +120,23 @@ func TestTheWantsAreSaidWantedFromTheKeptAssignmentGraphRevision(t *testing.T) {
|
||||
if w, _ := mwc.DecodeWant(kv.values[skey]); w.Run != "9" {
|
||||
t.Errorf("a put's want is %+v, want the newest source held, 9", w)
|
||||
}
|
||||
// a placement's build after the delivery of run 12: the newest source held for it is the want's own, never refused
|
||||
// a placement's build after the delivery of run 212: the newest source held for it is the want's own, never refused
|
||||
p.putWant(ctx, "g14", "db", mwc.Want{Fp: fpTest, Version: "0.1.0"})
|
||||
if w := stored(); w.Run != "12" || w.Version != "0.1.0" {
|
||||
t.Errorf("a placement's want after run 12 is %+v, want it written at run 12", w)
|
||||
if w := stored(); w.Run != "212" || w.Version != "0.1.0" {
|
||||
t.Errorf("a placement's want after run 212 is %+v, want it written at run 212", w)
|
||||
}
|
||||
// A want written with an again run's number ("2") is replaced by any sequence; a lower sequence is refused.
|
||||
nkey, _ := mwc.WantKey("novox", "node-tools")
|
||||
atNovox := func() mwc.Want { w, _ := mwc.DecodeWant(kv.values[nkey]); return w }
|
||||
p.putWant(ctx, "novox", "node-tools", mwc.Want{Fp: fpTest, Version: "0.1.96", Pipeline: "main.265.again.2", Rank: 1, Run: "2"})
|
||||
p.putWant(ctx, "novox", "node-tools", mwc.Want{Fp: fpTest, Version: "0.1.115", Pipeline: "main.320.again.1", Rank: 1, Run: "270"})
|
||||
if w := atNovox(); w.Run != "270" || w.Version != "0.1.115" {
|
||||
t.Errorf("seq 270 after run 2 left %+v, want 0.1.115 at run 270", w)
|
||||
}
|
||||
puts = kv.puts
|
||||
p.putWant(ctx, "novox", "node-tools", mwc.Want{Fp: fpTest, Version: "0.1.114", Pipeline: "main.319", Rank: 1, Run: "269"})
|
||||
if w := atNovox(); w.Run != "270" || kv.puts != puts {
|
||||
t.Errorf("seq 269 after 270 replaced %+v (%d writes)", w, kv.puts-puts)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -599,7 +599,7 @@ func (b *bed) ended(t *testing.T, source int64, outcome string, movers ...moverA
|
||||
if outcome != mpr.PipelineEndedOutcomePassed {
|
||||
step.Outcome = mpr.StepResultOutcomeFailed
|
||||
}
|
||||
e := mpr.PipelineEnded{V: 1, Pipeline: pipeline, Branch: trunkBranch, Source: source, Outcome: outcome}
|
||||
e := mpr.PipelineEnded{V: 1, Pipeline: pipeline, Branch: trunkBranch, Source: source, Seq: 200 + source, Outcome: outcome}
|
||||
for _, m := range movers {
|
||||
e.Movers = append(e.Movers, mpr.MoverEnded{Module: m.module, Fingerprint: m.fp, Version: m.version, Tier: m.tier, Steps: []mpr.StepResult{step}})
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"git.novox.be/novox/mesh-contracts/go/seats/nodeengine"
|
||||
"maps"
|
||||
"mesh-delivery-assigner/internal/buckets"
|
||||
"reflect"
|
||||
"slices"
|
||||
@@ -14,6 +15,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
mmac "git.novox.be/novox/mesh-contracts/go/clients/meshmoduleassignerclient"
|
||||
"git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient"
|
||||
mma "git.novox.be/novox/mesh-contracts/go/seats/meshmoduleassigner"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-assigner/asks"
|
||||
@@ -97,6 +99,9 @@ type passer struct {
|
||||
// saidWaits is the last said of the seat's wait for its states (sayWaits).
|
||||
saidWaits string
|
||||
intended map[string]map[string]map[string]bool
|
||||
// assignmentLeftSaid is, by assignment key, the why last said that the clean state leaves a retired module's key (H-A-509),
|
||||
// so each is said once per why.
|
||||
assignmentLeftSaid map[string]string
|
||||
// laidHere are the proposals whose candidates this process wrote (design 47 G A-317), by id.
|
||||
laidHere map[string]bool
|
||||
// reads is the assigner's state engine-reads, what each node's engine said it reads (enginewords.go, design 47 H-A-104);
|
||||
@@ -222,6 +227,7 @@ func (p *passer) wants(ctx context.Context) {
|
||||
puts := p.putsByModule()
|
||||
builds := placementBuilds(p.w.assignments())
|
||||
p.staleAsks(ctx, trunk)
|
||||
p.retiredAssignments(ctx, trunk)
|
||||
names := map[string]bool{}
|
||||
for name := range trunk {
|
||||
names[name] = true
|
||||
@@ -312,15 +318,14 @@ func (p *passer) putWant(ctx context.Context, node, module string, want mwc.Want
|
||||
}
|
||||
}
|
||||
|
||||
// runOf is the run a want carries (design 47 H2 §813 (1); H-A-355 (1), H-A-416): the source revision of the pipeline that
|
||||
// released it, `<branch>.<source>`, in decimal; for a want of no pipeline (a put, a placement's build, a removal) the newest
|
||||
// source the assigner holds for it: the trunk's source of its kept assignment graph revision, or the run of the want written
|
||||
// (held) when that is newer, so a person's put or placement after a delivery is never refused as older; "" when it holds none.
|
||||
// runOf is the run a want carries (design 47 H2 §813 (1); H-A-355 (1), H-A-504 corrected and its addendum): the sequence of
|
||||
// the pipeline that released it, as its pipeline-ended said it, set on the want by the want rule; for a want of no pipeline (a
|
||||
// put, a placement's build, a removal) the newest source the assigner holds for it: the trunk's source of its kept assignment
|
||||
// graph revision, or the run of the want written (held) when that is newer, so a person's put or placement after a delivery is
|
||||
// never refused as older; "" when it holds none.
|
||||
func (p *passer) runOf(want mwc.Want, held *mwc.Want) string {
|
||||
if i := strings.LastIndexByte(want.Pipeline, '.'); i >= 0 {
|
||||
if n, err := strconv.ParseInt(want.Pipeline[i+1:], 10, 64); err == nil && n > 0 {
|
||||
return strconv.FormatInt(n, 10)
|
||||
}
|
||||
if want.Run != "" {
|
||||
return want.Run
|
||||
}
|
||||
var newest int64
|
||||
if p.graph != nil {
|
||||
@@ -529,6 +534,42 @@ func (p *passer) staleAsks(ctx context.Context, trunk map[string]meshcatalog.Mod
|
||||
}
|
||||
}
|
||||
|
||||
// retiredAssignments is the clean state of the assignments at the pass (design 47 H2 H-A-509 and its second addendum): each
|
||||
// module key `<node>.<module>` of a module no manifest the trunk holds names, that the node key does not name, is deleted and
|
||||
// named in the journal, whether its value reads or not; one the node key still names is left, said once per why. Nothing goes
|
||||
// while the trunk is empty, or with no assignments bucket open.
|
||||
func (p *passer) retiredAssignments(ctx context.Context, trunk map[string]meshcatalog.ModulesByModuleValue) {
|
||||
if len(trunk) == 0 || p.kvs[plc.AssignmentsBucket()] == nil {
|
||||
return
|
||||
}
|
||||
names := make(map[string]bool, len(trunk))
|
||||
for name := range trunk {
|
||||
names[name] = true
|
||||
}
|
||||
held := p.w.read(plc.AssignmentsBucket())
|
||||
for _, key := range slices.Sorted(maps.Keys(held)) {
|
||||
node, module, kind, err := mmac.ParseKey(key)
|
||||
if err != nil || kind != mmac.ModuleKind || names[module] {
|
||||
continue
|
||||
}
|
||||
nodeKey, _ := mmac.NodeKey(node)
|
||||
nodeRaw, nodeFound := held[nodeKey]
|
||||
if left := assignmentLeft(node, module, names, nodeRaw, nodeFound); left != "" {
|
||||
if p.assignmentLeftSaid[key] != left {
|
||||
if p.assignmentLeftSaid == nil {
|
||||
p.assignmentLeftSaid = map[string]string{}
|
||||
}
|
||||
p.assignmentLeftSaid[key] = left
|
||||
p.logf("the assignment key %s is of a module no manifest of the trunk names, and is left: %s", key, left)
|
||||
}
|
||||
continue
|
||||
}
|
||||
delete(p.assignmentLeftSaid, key)
|
||||
p.logf("the assignment key %s is of a module no manifest of the trunk names, and is dropped", key)
|
||||
p.remove(ctx, plc.AssignmentsBucket(), key)
|
||||
}
|
||||
}
|
||||
|
||||
// remove deletes one key of the assigner's own bucket when it holds it; a delete that fails is said and made again at the next
|
||||
// pass.
|
||||
func (p *passer) remove(ctx context.Context, bucket, key string) {
|
||||
|
||||
@@ -44,8 +44,11 @@ const pipelineEndedSubject = "mesh.seat." + mpr.Seat + ".event." + mpr.EventPipe
|
||||
type End struct {
|
||||
Pipeline string `json:"pipeline"`
|
||||
Source int64 `json:"source"`
|
||||
Fp string `json:"fp"`
|
||||
Version string `json:"version"`
|
||||
// Seq is the pipeline's sequence its pipeline-ended said, written as the run of its wants (design 47 H2 §813 (1), H-A-504
|
||||
// addendum).
|
||||
Seq int64 `json:"seq,omitempty"`
|
||||
Fp string `json:"fp"`
|
||||
Version string `json:"version"`
|
||||
// Rank is the mover's tier in the pipeline's delivery order, from 1 (§746, §750).
|
||||
Rank int64 `json:"rank"`
|
||||
}
|
||||
@@ -141,6 +144,8 @@ type pipelineEnds struct {
|
||||
// firsts is, by module, the first watched branch of its registration, the branch of a placement that names none (design
|
||||
// 47 G §14).
|
||||
firsts map[string]string
|
||||
// noSeq is, by module and pipeline, the ends kept without a sequence already said (H-A-504 second addendum).
|
||||
noSeq map[string]bool
|
||||
// runEnded is told a run on request's pipeline-ended, its group `run-<id>`, to drop the run's candidate (A-235, H-A-58); nil
|
||||
// drops nothing.
|
||||
runEnded func(group string) error
|
||||
@@ -178,6 +183,13 @@ func (e *pipelineEnds) take(p mpr.PipelineEnded) (bool, error) {
|
||||
e.logf("the pipeline-ended of %s is refused, and none of its movers' versions is kept: %v", p.Pipeline, err)
|
||||
return false, nil
|
||||
}
|
||||
// Its sequence is its wants' run (design 47 H2 §813 (1), H-A-504 addendum): an end without one, of an older runner, is
|
||||
// refused loudly and writes no want.
|
||||
if p.Seq <= 0 {
|
||||
e.logf("the pipeline-ended of %s is refused, and none of its movers' versions is kept: it carries no seq, the run its "+
|
||||
"wants would carry (a runner older than H-A-504's addendum); the runner's end-again of %s, once it says seq, keeps them", p.Pipeline, p.Pipeline)
|
||||
return false, nil
|
||||
}
|
||||
changed := false
|
||||
var kept []tierMover
|
||||
versioned := map[string]bool{}
|
||||
@@ -219,7 +231,7 @@ func (e *pipelineEnds) take(p mpr.PipelineEnded) (bool, error) {
|
||||
break // an older version, or this one again
|
||||
}
|
||||
}
|
||||
value, err := json.Marshal(End{Pipeline: p.Pipeline, Source: p.Source, Fp: m.Fingerprint, Version: m.Version, Rank: max(m.Tier, 1)})
|
||||
value, err := json.Marshal(End{Pipeline: p.Pipeline, Source: p.Source, Seq: p.Seq, Fp: m.Fingerprint, Version: m.Version, Rank: max(m.Tier, 1)})
|
||||
if err != nil {
|
||||
return changed, err
|
||||
}
|
||||
@@ -236,6 +248,22 @@ func (e *pipelineEnds) take(p mpr.PipelineEnded) (bool, error) {
|
||||
return changed, nil
|
||||
}
|
||||
|
||||
// noSeqOnce says, once per module and pipeline, that the end kept for module from pipeline carries no sequence and writes
|
||||
// no want, naming the recovery (H-A-504 second addendum).
|
||||
func (e *pipelineEnds) noSeqOnce(module, pipeline string) {
|
||||
e.mu.Lock()
|
||||
if e.noSeq == nil {
|
||||
e.noSeq = map[string]bool{}
|
||||
}
|
||||
said := e.noSeq[module+" "+pipeline]
|
||||
e.noSeq[module+" "+pipeline] = true
|
||||
e.mu.Unlock()
|
||||
if !said && e.logf != nil {
|
||||
e.logf("no want of %s is written: its end kept from %s carries no seq, the run its want would carry (kept before "+
|
||||
"H-A-504's addendum); the runner's end-again of %s, or %s's next pipeline, writes it", module, pipeline, pipeline, module)
|
||||
}
|
||||
}
|
||||
|
||||
// endOf is the end kept for module on branch: the newest version released there whose pipeline passed.
|
||||
func (e *pipelineEnds) endOf(module, branch string) (End, bool) {
|
||||
if e == nil {
|
||||
@@ -257,7 +285,13 @@ func (e *pipelineEnds) target(module, branch string) (assign.Target, bool) {
|
||||
if !ok || !e.tierWritten(end) {
|
||||
return assign.Target{}, false
|
||||
}
|
||||
return assign.Target{Fp: end.Fp, Version: end.Version, Pipeline: end.Pipeline, Rank: end.Rank}, true
|
||||
if end.Seq <= 0 {
|
||||
// An end kept before pipeline-ended carried its sequence has no run for its wants (design 47 H2 §813 (1), H-A-504
|
||||
// second addendum): it writes no want, said once.
|
||||
e.noSeqOnce(module, end.Pipeline)
|
||||
return assign.Target{}, false
|
||||
}
|
||||
return assign.Target{Fp: end.Fp, Version: end.Version, Pipeline: end.Pipeline, Rank: end.Rank, Seq: end.Seq}, true
|
||||
}
|
||||
|
||||
// hearPipeline takes a pipeline-ended: a passed one's released versions are kept (take), and a run on request's drops the
|
||||
|
||||
@@ -68,9 +68,9 @@ func mover(module, fp, version string, tier int64, outcome string) mpr.MoverEnde
|
||||
Steps: []mpr.StepResult{{Step: "unit", Status: mpr.StepResultStatusRequired, Outcome: outcome, Module: module}}}
|
||||
}
|
||||
|
||||
// ended is the pipeline-ended of the take-in of source on branch, its movers given.
|
||||
// ended is the pipeline-ended of the take-in of source on branch, its movers given, its sequence 200 + source.
|
||||
func ended(branch string, source int64, outcome string, movers ...mpr.MoverEnded) mpr.PipelineEnded {
|
||||
return mpr.PipelineEnded{V: 1, Branch: branch, Source: source, EndCount: 1, Outcome: outcome, Movers: movers,
|
||||
return mpr.PipelineEnded{V: 1, Branch: branch, Source: source, Seq: 200 + source, EndCount: 1, Outcome: outcome, Movers: movers,
|
||||
Pipeline: fmt.Sprintf("%s.%d", branch, source)}
|
||||
}
|
||||
|
||||
@@ -86,28 +86,34 @@ func TestThePassedVersionIsKept(t *testing.T) {
|
||||
want *End // nil: none kept for web on main
|
||||
}{
|
||||
{"a passed pipeline keeps its version", []mpr.PipelineEnded{ended("main", 5, pass, mover("web", "fp1", "0.1.2", 2, ok))},
|
||||
&End{Pipeline: "main.5", Source: 5, Fp: "fp1", Version: "0.1.2", Rank: 2}},
|
||||
&End{Pipeline: "main.5", Source: 5, Seq: 205, Fp: "fp1", Version: "0.1.2", Rank: 2}},
|
||||
{"nothing to run counts as passed", []mpr.PipelineEnded{ended("main", 5, pass, mover("web", "fp1", "0.1.2", 1, nothing))},
|
||||
&End{Pipeline: "main.5", Source: 5, Fp: "fp1", Version: "0.1.2", Rank: 1}},
|
||||
&End{Pipeline: "main.5", Source: 5, Seq: 205, Fp: "fp1", Version: "0.1.2", Rank: 1}},
|
||||
{"a failed pipeline keeps nothing, a passed mover in it neither", []mpr.PipelineEnded{ended("main", 5, fail, mover("web", "fp1", "0.1.2", 1, ok),
|
||||
mover("db", "fp9", "0.3.0", 1, failed))}, nil},
|
||||
{"a mover whose required step failed keeps nothing", []mpr.PipelineEnded{ended("main", 5, pass, mover("web", "fp1", "0.1.2", 1, failed))}, nil},
|
||||
{"no version released keeps nothing", []mpr.PipelineEnded{ended("main", 5, pass, mover("web", "fp1", "", 1, ok))}, nil},
|
||||
{"an older end heard after a newer one keeps the newer", []mpr.PipelineEnded{ended("main", 6, pass, mover("web", "fp2", "0.1.3", 1, ok)),
|
||||
ended("main", 5, pass, mover("web", "fp1", "0.1.2", 1, ok))}, &End{Pipeline: "main.6", Source: 6, Fp: "fp2", Version: "0.1.3", Rank: 1}},
|
||||
ended("main", 5, pass, mover("web", "fp1", "0.1.2", 1, ok))}, &End{Pipeline: "main.6", Source: 6, Seq: 206, Fp: "fp2", Version: "0.1.3", Rank: 1}},
|
||||
{"a newer version replaces", []mpr.PipelineEnded{ended("main", 5, pass, mover("web", "fp1", "0.1.2", 1, ok)),
|
||||
ended("main", 6, pass, mover("web", "fp2", "0.1.10", 1, ok))}, &End{Pipeline: "main.6", Source: 6, Fp: "fp2", Version: "0.1.10", Rank: 1}},
|
||||
ended("main", 6, pass, mover("web", "fp2", "0.1.10", 1, ok))}, &End{Pipeline: "main.6", Source: 6, Seq: 206, Fp: "fp2", Version: "0.1.10", Rank: 1}},
|
||||
// H-A-485: an again pipeline's end is kept as a take-in's; a key of no form the runner's seat defines is refused, nothing kept.
|
||||
{"an again pipeline keeps its version", []mpr.PipelineEnded{func() mpr.PipelineEnded {
|
||||
p := ended("main", 5, pass, mover("web", "fp1", "0.1.2", 2, ok))
|
||||
p.Pipeline = "main.5.again.2"
|
||||
return p
|
||||
}()}, &End{Pipeline: "main.5.again.2", Source: 5, Fp: "fp1", Version: "0.1.2", Rank: 2}},
|
||||
}()}, &End{Pipeline: "main.5.again.2", Source: 5, Seq: 205, Fp: "fp1", Version: "0.1.2", Rank: 2}},
|
||||
{"a key of no form is refused", []mpr.PipelineEnded{func() mpr.PipelineEnded {
|
||||
p := ended("main", 5, pass, mover("web", "fp1", "0.1.2", 2, ok))
|
||||
p.Pipeline = "main.5.later.2"
|
||||
return p
|
||||
}()}, nil},
|
||||
// H-A-504 addendum: an end without its sequence, of an older runner, is refused and keeps nothing.
|
||||
{"an end without seq keeps nothing", []mpr.PipelineEnded{func() mpr.PipelineEnded {
|
||||
p := ended("main", 5, pass, mover("web", "fp1", "0.1.2", 1, ok))
|
||||
p.Seq = 0
|
||||
return p
|
||||
}()}, nil},
|
||||
{"a run on request keeps nothing", []mpr.PipelineEnded{func() mpr.PipelineEnded {
|
||||
p := ended("main", 5, pass, mover("web", "fp1", "0.1.2", 1, ok))
|
||||
p.Run = "r1"
|
||||
@@ -206,7 +212,7 @@ func TestAPassWritesTheWantOfThePassedVersion(t *testing.T) {
|
||||
if !passed {
|
||||
continue
|
||||
}
|
||||
if w, err := mwc.DecodeWant(raw); err != nil || w.Fp != fp || w.Version != "0.1.2" || w.Pipeline != trunkBranch+".5" || w.Rank != 2 {
|
||||
if w, err := mwc.DecodeWant(raw); err != nil || w.Fp != fp || w.Version != "0.1.2" || w.Pipeline != trunkBranch+".5" || w.Rank != 2 || w.Run != "205" {
|
||||
t.Errorf("%s: the want on %s = %+v (%v)", c.name, node, w, err)
|
||||
}
|
||||
}
|
||||
@@ -235,8 +241,25 @@ func TestARegistrationNamesTheDefaultBranch(t *testing.T) {
|
||||
if woken == 0 || endsKept() != 1 || e.branchOf("web", "") != "beta" || e.branchOf("other", "") != trunkBranch {
|
||||
t.Errorf("ends kept %d, default branch %q: an unwatched branch's end stayed, or the default is wrong", endsKept(), e.branchOf("web", ""))
|
||||
}
|
||||
if tg, ok := e.target("web", ""); !ok || tg.Fp != "fp2" {
|
||||
t.Errorf("the default branch's target = %+v %v", tg, ok)
|
||||
if tg, ok := e.target("web", ""); !ok || tg.Fp != "fp2" || tg.Seq != 205 {
|
||||
t.Errorf("the default branch's target = %+v %v, want fp2 at seq 205", tg, ok)
|
||||
}
|
||||
// H-A-504 second addendum: an end kept without a sequence (before pipeline-ended said it) writes no want, said once.
|
||||
raw, rev, _ := st.get(endKey("web", "beta"))
|
||||
var old End
|
||||
_ = json.Unmarshal(raw, &old)
|
||||
old.Seq = 0
|
||||
raw, _ = json.Marshal(old)
|
||||
_ = st.swap(endKey("web", "beta"), raw, rev)
|
||||
var said []string
|
||||
e.logf = func(f string, a ...any) { said = append(said, fmt.Sprintf(f, a...)) }
|
||||
for range 2 {
|
||||
if tg, ok := e.target("web", ""); ok {
|
||||
t.Errorf("an end kept without seq is the target %+v", tg)
|
||||
}
|
||||
}
|
||||
if len(said) != 1 || !strings.Contains(said[0], "beta.5") || !strings.Contains(said[0], "end-again") {
|
||||
t.Errorf("an end kept without seq said %q, want once, naming the pipeline and end-again", said)
|
||||
}
|
||||
e.registered(mpcat.Registration{Module: "web"}, true)
|
||||
if endsKept() != 0 {
|
||||
|
||||
@@ -417,6 +417,7 @@ func serveTools() error {
|
||||
tools = append(tools, whyTools(runtimeStore{})...)
|
||||
tools = append(tools, askAgainTools(runtimeStore{}, stdio.Ask, time.Now)...)
|
||||
tools = append(tools, wantDropTools(runtimeStore{}, stdio.Ask)...)
|
||||
tools = append(tools, assignmentDropTools(runtimeStore{}, stdio.Ask, watchedModules(stdio.Ask))...) // a retired module's assignment key (H-A-509)
|
||||
tools = append(tools, asksTools(stdio.QueueWaiting, stdio.State(process.TakenState), stdio.Ask)...) // the seat's work queue (§777)
|
||||
tools = append(tools, keepNowTools(stdio.Ask)...)
|
||||
tools = append(tools, validateBeforeTools(runtimeStore{})...) // what a validate step did not count (§814) // the keeping by hand (§813 (2))
|
||||
|
||||
@@ -3,6 +3,7 @@ package assign
|
||||
import (
|
||||
"fmt"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient"
|
||||
@@ -28,6 +29,9 @@ type Target struct {
|
||||
Version string
|
||||
Pipeline string
|
||||
Rank int64
|
||||
// Seq is the pipeline's sequence, the want's run in decimal (design 47 H2 §813 (1), H-A-504 addendum); 0 for a placement's
|
||||
// build.
|
||||
Seq int64
|
||||
}
|
||||
|
||||
// Module is what the want rule reads of one module: the nodes it is assigned to, the build each node's want names, the puts
|
||||
@@ -123,6 +127,9 @@ func Wants(m Module, wants map[string]mwc.Want) Outcome {
|
||||
continue
|
||||
}
|
||||
next := mwc.Want{Fp: t.Fp, Version: t.Version, Pipeline: t.Pipeline, Rank: t.Rank, Self: m.selfOn(node)}
|
||||
if t.Seq > 0 {
|
||||
next.Run = strconv.FormatInt(t.Seq, 10)
|
||||
}
|
||||
if had && !before.Removed && !before.Put && before.Fp == t.Fp {
|
||||
// The answers the want carries stay while its build does: a failed backup's (ADR 0539 §16), a held revert's, the yes.
|
||||
next.Backup, next.Words, next.Revert, next.Yes, next.Release = before.Backup, before.Words, before.Revert, before.Yes, before.Release
|
||||
|
||||
@@ -116,8 +116,8 @@ func TestManifest(t *testing.T) {
|
||||
// which lists and asks again what each node's engine reads.
|
||||
if !slices.Equal(m.Tools, []string{"assigner_put", "assigner_release", "assigner_puts", "assigner_waits", "assigner_inputs", "assigner_inputs_drop", "assigner_compositions", "assigner_compositions_drop", "assignments", "seat-holders", "wants", "asks",
|
||||
"assigner_read_assignments", "assigner_read_seat_holders", "assigner_read_wants", "assigner_read_findings", "assigner_read_differences", "assigner_read_copies",
|
||||
"assigner_first_views", "assigner_first_view_again", "assigner_engine_reads", "assigner_seat_list", "assigner_seat_list_again", "assigner_ask_again", "assigner_written", "assigner_why", "assigner_want_drop", "assigner_asks", "assigner_ask_drop", "assigner_keep_now", "assigner_validate_before"}) {
|
||||
t.Errorf("the assigner serves tools %v, want its three put tools, three first views, six read tools, assigner_engine_reads, the seat list's two (ADR 0636 §7) assigner_ask_again (ADR 0668 §5) and assigner_why (design 47 G A-439)", m.Tools)
|
||||
"assigner_first_views", "assigner_first_view_again", "assigner_engine_reads", "assigner_seat_list", "assigner_seat_list_again", "assigner_ask_again", "assigner_written", "assigner_why", "assigner_want_drop", "assigner_assignment_drop", "assigner_asks", "assigner_ask_drop", "assigner_keep_now", "assigner_validate_before"}) {
|
||||
t.Errorf("the assigner serves tools %v, want its three put tools, three first views, six read tools, assigner_engine_reads, the seat list's two (ADR 0636 §7) assigner_ask_again (ADR 0668 §5), assigner_why (design 47 G A-439) and assigner_assignment_drop after assigner_want_drop (design 47 H2 H-A-509)", m.Tools)
|
||||
}
|
||||
if m.RunsAs != m.Module || m.SecretsOwner != m.RunsAs {
|
||||
t.Errorf("runs-as = %q: the bundle runs on the assigner's own account (ADR 0621 §1)", m.RunsAs)
|
||||
|
||||
@@ -134,6 +134,7 @@
|
||||
"assigner_written",
|
||||
"assigner_why",
|
||||
"assigner_want_drop",
|
||||
"assigner_assignment_drop",
|
||||
"assigner_asks",
|
||||
"assigner_ask_drop",
|
||||
"assigner_keep_now",
|
||||
|
||||
@@ -80,7 +80,8 @@ func (b *Builder) holdsRevision(branch string, source int64, entries []meshbuild
|
||||
}
|
||||
|
||||
// keptRevisionHolds answers no outcome when the catalog keeps the ask's revision (its catalog revision by number) and that
|
||||
// revision names every entry of the ask (H-A-205, H-A-222); else failed or could not run, with its words.
|
||||
// revision names every entry of the ask (H-A-205, H-A-222); superseded when it names a newer fingerprint of an entry (H-A-508
|
||||
// second addendum); else failed or could not run, with its words.
|
||||
func (b *Builder) keptRevisionHolds(ctx context.Context, run meshbuilds.StepRun, held int64) (outcome, said string) {
|
||||
below := fmt.Sprintf("revision %d of %s is not named by the builder's picture, which holds source revision %d", run.Source, run.Branch, held)
|
||||
if run.Source < held {
|
||||
@@ -100,11 +101,25 @@ func (b *Builder) keptRevisionHolds(ctx context.Context, run meshbuilds.StepRun,
|
||||
b.logf("%s: %s, and the catalog's revision %d is of source revision %d, the ask names %d: the step fails, nothing is built", run.Pipeline, below, run.Revision, source, run.Source)
|
||||
return meshbuilds.StepEndedOutcomeFailed, fmt.Sprintf("%s, and the catalog's revision %d is of source revision %d, the ask names %d", below, run.Revision, source, run.Source)
|
||||
}
|
||||
// A step whose fingerprint the catalog's revision no longer names but names a newer one of its module, found below the
|
||||
// picture or by the revision's number, ends superseded with the superseding fingerprint in its why, never failed (design
|
||||
// 47 H2 H-A-508 second addendum: one outcome for one fact, found by either check). Failed stays for any other mismatch.
|
||||
var superseded []string
|
||||
for _, e := range run.Entries {
|
||||
if fps[e.Module] != e.Fingerprint {
|
||||
b.logf("%s: %s, and the catalog's revision %d names %s at %q, not %s: the step fails, nothing is built", run.Pipeline, below, run.Revision, e.Module, fps[e.Module], e.Fingerprint)
|
||||
return meshbuilds.StepEndedOutcomeFailed, fmt.Sprintf("%s, and the catalog's revision %d names %s at %q, not %s", below, run.Revision, e.Module, fps[e.Module], e.Fingerprint)
|
||||
if fps[e.Module] == e.Fingerprint {
|
||||
continue
|
||||
}
|
||||
if fps[e.Module] != "" {
|
||||
superseded = append(superseded, stepSuperseded(e.Module, e.Fingerprint, fps[e.Module]))
|
||||
continue
|
||||
}
|
||||
b.logf("%s: %s, and the catalog's revision %d names %s at %q, not %s: the step fails, nothing is built", run.Pipeline, below, run.Revision, e.Module, fps[e.Module], e.Fingerprint)
|
||||
return meshbuilds.StepEndedOutcomeFailed, fmt.Sprintf("%s, and the catalog's revision %d names %s at %q, not %s", below, run.Revision, e.Module, fps[e.Module], e.Fingerprint)
|
||||
}
|
||||
if len(superseded) > 0 {
|
||||
said := strings.Join(superseded, "; ")
|
||||
b.logf("%s: %s, and the catalog's revision %d names newer fingerprints: %s; nothing is built", run.Pipeline, below, run.Revision, said)
|
||||
return meshbuilds.StepEndedOutcomeSuperseded, said
|
||||
}
|
||||
// Each asked fingerprint is recorded as the branch's, so its build reserves its version (H-A-155) as one the picture
|
||||
// took in does; what the picture heard stays as it is, so the newer fingerprint's build is not superseded. Once the picture
|
||||
@@ -136,9 +151,10 @@ func (b *Builder) awaitRevision(ctx context.Context, run meshbuilds.StepRun) (ou
|
||||
if (run.Revision > 0 && b.KeptRevision != nil) || below {
|
||||
// By its number (H-A-222), whatever the source the picture holds; for an ask naming none, only below the
|
||||
// picture (H-A-205). A kept revision of another source or naming other fingerprints is a mismatch the wait
|
||||
// cannot mend: it fails at once; only a revision the catalog does not answer is waited for.
|
||||
// cannot mend: it fails at once, or ends superseded at once when it names a newer fingerprint of the module (H-A-508
|
||||
// second addendum); only a revision the catalog does not answer is waited for.
|
||||
outcome, said := b.keptRevisionHolds(ctx, run, held)
|
||||
if outcome == "" || below || outcome == meshbuilds.StepEndedOutcomeFailed {
|
||||
if outcome == "" || below || outcome == meshbuilds.StepEndedOutcomeFailed || outcome == meshbuilds.StepEndedOutcomeSuperseded {
|
||||
return outcome, said
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,12 +18,13 @@ import (
|
||||
// number is needed, and the builder follows no candidate.
|
||||
|
||||
// BuildStep builds the entries of the step ask ask and answers its end: passed when every entry's build is done, failed when
|
||||
// one failed (said), could not run when an entry could not be read, nothing to run for an ask naming none. The node is the
|
||||
// one failed (said), superseded when none failed and a newer entry of its branch superseded one (H-A-508), could not run when
|
||||
// an entry could not be read, nothing to run for an ask naming none. The node is the
|
||||
// caller's to set.
|
||||
func (b *Builder) BuildStep(ctx context.Context, ask string, run meshbuilds.StepRun) meshbuilds.StepEnded {
|
||||
b.init()
|
||||
started := b.now()
|
||||
end := meshbuilds.StepEnded{V: 1, ID: ask, Pipeline: run.Pipeline, Step: meshbuilds.StepEndedStepBuild, Rerun: run.Rerun, By: run.By, Entries: run.Entries, Node: b.Node, Started: &started}
|
||||
end := meshbuilds.StepEnded{V: 1, Form: meshbuilds.Form, ID: ask, Pipeline: run.Pipeline, Step: meshbuilds.StepEndedStepBuild, Rerun: run.Rerun, By: run.By, Entries: run.Entries, Node: b.Node, Started: &started}
|
||||
// finish is the one place the ask is answered: one journal line, "answered <ask> <pipeline> <movers> <step> <outcome>"
|
||||
// (design 47 H2 §792; H-A-320 (1), H-A-333).
|
||||
finish := func(outcome, said string) meshbuilds.StepEnded {
|
||||
@@ -58,7 +59,7 @@ func (b *Builder) BuildStep(ctx context.Context, ask string, run meshbuilds.Step
|
||||
return finish(outcome, said)
|
||||
}
|
||||
b.askedRevision(run)
|
||||
var failed []string
|
||||
var failed, superseded []string
|
||||
for _, e := range run.Entries {
|
||||
var pins map[string]string
|
||||
outcome, said := b.buildEntry(ctx, run.Pipeline, e, &pins)
|
||||
@@ -77,11 +78,16 @@ func (b *Builder) BuildStep(ctx context.Context, ask string, run meshbuilds.Step
|
||||
return finish(outcome, said)
|
||||
case meshbuilds.StepEndedOutcomeFailed:
|
||||
failed = append(failed, said)
|
||||
case meshbuilds.StepEndedOutcomeSuperseded:
|
||||
superseded = append(superseded, said)
|
||||
}
|
||||
}
|
||||
if len(failed) > 0 {
|
||||
return finish(meshbuilds.StepEndedOutcomeFailed, strings.Join(failed, "; "))
|
||||
}
|
||||
if len(superseded) > 0 {
|
||||
return finish(meshbuilds.StepEndedOutcomeSuperseded, strings.Join(superseded, "; "))
|
||||
}
|
||||
return finish(meshbuilds.StepEndedOutcomePassed, "")
|
||||
}
|
||||
|
||||
@@ -133,7 +139,19 @@ func (b *Builder) buildEntry(ctx context.Context, pipeline string, e meshbuilds.
|
||||
b.logf("%s@%s build step answered %s for %s (%s)", entry.Module, entry.Fp, outcome, pipeline, how)
|
||||
return outcome, said
|
||||
}
|
||||
if done, failedWords, found := b.keyEnd(ctx, key); found {
|
||||
done, failedWords, found := b.keyEnd(ctx, key)
|
||||
// The fingerprint is judged against its branch's newest entry first, for a done build as for one not built (H-A-508): a
|
||||
// superseded one ends the step superseded, naming the superseding fingerprint, never failed. One not built is refused, not
|
||||
// waited on (H-A-489): no look builds a superseded fingerprint, so its end would never come.
|
||||
if newer := b.supersededBy(entry.Module, key, entry.Fp); newer != "" {
|
||||
how := "existing build"
|
||||
if !found {
|
||||
how = "refused"
|
||||
b.saySuperseded(entry.Module, key, entry.Fp, newer)
|
||||
}
|
||||
return answered(meshbuilds.StepEndedOutcomeSuperseded, stepSuperseded(entry.Module, entry.Fp, newer), how)
|
||||
}
|
||||
if found {
|
||||
if done {
|
||||
// A key done before reports the pins it was built with, kept with it, never the ones a publish gives now.
|
||||
*pins = b.keptPins(ctx, key)
|
||||
@@ -142,15 +160,16 @@ func (b *Builder) buildEntry(ctx context.Context, pipeline string, e meshbuilds.
|
||||
}
|
||||
return answered(meshbuilds.StepEndedOutcomeFailed, failedWords, "existing build")
|
||||
}
|
||||
if newer := b.supersededBy(entry.Module, key, entry.Fp); newer != "" {
|
||||
// Refused, not waited on (H-A-489): no look builds a superseded fingerprint, so its end would never come.
|
||||
return answered(meshbuilds.StepEndedOutcomeFailed, fmt.Sprintf("%s at %s %s", entry.Module, entry.Fp, b.saySuperseded(entry.Module, key, entry.Fp, newer)), "refused")
|
||||
}
|
||||
m := meshcatalog.ModulesByModuleValue{Repository: entry.Repository, Commit: entry.Commit, Fp2: entry.Fp, Manifest: meshcatalogclient.BareManifestDigest(entry.ManifestDigest), Path: entry.Path,
|
||||
Toolchains: CatalogToolchains(b.agreedFor(ctx, meshcatalogclient.BareManifestDigest(entry.ManifestDigest))), Packages: entry.Packages}
|
||||
b.consider(ctx, entry.Module, m)
|
||||
select {
|
||||
case log := <-ended:
|
||||
// A fingerprint a newer entry superseded while it built (its build withdrawn, or done) ends superseded, judged before
|
||||
// the log's outcome (H-A-508).
|
||||
if newer := b.supersededBy(entry.Module, key, entry.Fp); newer != "" {
|
||||
return answered(meshbuilds.StepEndedOutcomeSuperseded, stepSuperseded(entry.Module, entry.Fp, newer), "built now")
|
||||
}
|
||||
if log.Outcome == builds.BuildDone {
|
||||
*pins = b.keptPins(ctx, key)
|
||||
outcome, said := b.passedWithItsVersion(ctx, entry)
|
||||
@@ -168,13 +187,18 @@ func (b *Builder) buildEntry(ctx context.Context, pipeline string, e meshbuilds.
|
||||
// that can never be released, and one whose series another fingerprint took over fails saying it is stale, naming that
|
||||
// fingerprint and its version (design 47 H H-A-244). A build that reserves none (a candidate's, a series of before G) passes as it did.
|
||||
func (b *Builder) passedWithItsVersion(ctx context.Context, entry meshcatalog.CatalogEntry) (outcome, said string) {
|
||||
if b.Reserved == nil {
|
||||
return meshbuilds.StepEndedOutcomePassed, ""
|
||||
}
|
||||
key, err := builds.BuilderBuildKey(entry.Module, entry.Fp)
|
||||
if err != nil {
|
||||
return meshbuilds.StepEndedOutcomeCouldNotRun, err.Error()
|
||||
}
|
||||
// The fingerprint is judged against its branch's newest entry first (H-A-508): a superseded one ends superseded, whatever
|
||||
// its reservation, release or takeover says.
|
||||
if newer := b.supersededBy(entry.Module, key, entry.Fp); newer != "" {
|
||||
return meshbuilds.StepEndedOutcomeSuperseded, stepSuperseded(entry.Module, entry.Fp, newer)
|
||||
}
|
||||
if b.Reserved == nil {
|
||||
return meshbuilds.StepEndedOutcomePassed, ""
|
||||
}
|
||||
b.mu.Lock()
|
||||
reserving := b.trunkFP[key] && b.origin[key].First
|
||||
b.mu.Unlock()
|
||||
@@ -209,6 +233,11 @@ func (b *Builder) passedWithItsVersion(ctx context.Context, entry meshcatalog.Ca
|
||||
return meshbuilds.StepEndedOutcomePassed, ""
|
||||
}
|
||||
|
||||
// stepSuperseded is the why of a build step ended superseded (H-A-508): the fingerprint and the newer entry that superseded it.
|
||||
func stepSuperseded(module, fp, newer string) string {
|
||||
return fmt.Sprintf("%s at %s is superseded by %s, the newest entry heard on its first branch", module, fp, newer)
|
||||
}
|
||||
|
||||
// keptPins are the pins a done key keeps it was built with (H-A-207); none when it keeps none or cannot be read, so the
|
||||
// runner ends the steps that waited for them could not run, loud.
|
||||
func (b *Builder) keptPins(ctx context.Context, key string) map[string]string {
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -12,7 +13,9 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/buildrun"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
|
||||
@@ -124,15 +127,20 @@ func TestABuildStepPassesAReservingBuildOnlyWithItsReservedVersion(t *testing.T)
|
||||
for _, c := range []struct {
|
||||
name, version string
|
||||
reserve, released, unreadable bool
|
||||
takenOver bool
|
||||
takenOver, superseded bool
|
||||
want, said string
|
||||
}{
|
||||
{"no version reserved", "0.1", false, false, false, false, meshbuilds.StepEndedOutcomeFailed, "built at " + fp1 + ", but no version is reserved for it"},
|
||||
{"H-A-244: its series was taken over by a newer fingerprint", "0.1", false, false, false, true, meshbuilds.StepEndedOutcomeFailed, "m: built at " + fp1 + " but its series moved to " + fp2 + " 0.1.7: stale"},
|
||||
{"a version reserved", "0.1", true, false, false, false, meshbuilds.StepEndedOutcomePassed, ""},
|
||||
{"a released build whose reservation is gone", "0.1", false, true, false, false, meshbuilds.StepEndedOutcomePassed, ""},
|
||||
{"the plan cannot be read", "0.1", false, false, true, false, meshbuilds.StepEndedOutcomeCouldNotRun, "plan cannot be read"},
|
||||
{"a series of before G", "1", false, false, false, false, meshbuilds.StepEndedOutcomePassed, ""},
|
||||
{"no version reserved", "0.1", false, false, false, false, false, meshbuilds.StepEndedOutcomeFailed, "built at " + fp1 + ", but no version is reserved for it"},
|
||||
{"H-A-244: its series was taken over by a newer fingerprint", "0.1", false, false, false, true, false, meshbuilds.StepEndedOutcomeFailed, "m: built at " + fp1 + " but its series moved to " + fp2 + " 0.1.7: stale"},
|
||||
// H-A-508: a done build a newer entry of its branch superseded is judged against that entry first, its takeover lost
|
||||
// with the release that deleted it: superseded, naming the newer fingerprint, never "no version is reserved".
|
||||
{"H-A-508: a done build a newer entry superseded", "0.1", false, false, false, false, true, meshbuilds.StepEndedOutcomeSuperseded, "m at " + fp1 + " is superseded by " + fp2},
|
||||
{"H-A-508: a done build a newer entry superseded, though a version is reserved", "0.1", true, false, false, false, true, meshbuilds.StepEndedOutcomeSuperseded, "m at " + fp1 + " is superseded by " + fp2},
|
||||
{"H-A-508: a done build a newer entry superseded, its series taken over", "0.1", false, false, false, true, true, meshbuilds.StepEndedOutcomeSuperseded, "m at " + fp1 + " is superseded by " + fp2},
|
||||
{"a version reserved", "0.1", true, false, false, false, false, meshbuilds.StepEndedOutcomePassed, ""},
|
||||
{"a released build whose reservation is gone", "0.1", false, true, false, false, false, meshbuilds.StepEndedOutcomePassed, ""},
|
||||
{"the plan cannot be read", "0.1", false, false, true, false, false, meshbuilds.StepEndedOutcomeCouldNotRun, "plan cannot be read"},
|
||||
{"a series of before G", "1", false, false, false, false, false, meshbuilds.StepEndedOutcomePassed, ""},
|
||||
} {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
r := newRig(t, goBundle)
|
||||
@@ -144,6 +152,15 @@ func TestABuildStepPassesAReservingBuildOnlyWithItsReservedVersion(t *testing.T)
|
||||
if v := r.consider(t, "modules/m"); v.State != builds.BuildDone { // built while the builder reserved nothing, as the live key was
|
||||
t.Fatalf("build = %+v, want done", v)
|
||||
}
|
||||
if c.superseded { // a newer entry of the branch heard after the build
|
||||
newer, err := meshcatalogclient.EncodeModule(meshcatalog.ModulesByModuleValue{Repository: "novox/mesh-catalog", Commit: "7a74cee83f88e6585a5511c3cc53bdf0f5303d20",
|
||||
Fp2: fp2, Manifest: mdigest('a'), Path: "modules/m", Toolchains: CatalogToolchains(agreedToolchains)})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r.b.Module(t.Context(), "m", newer)
|
||||
r.b.Wait()
|
||||
}
|
||||
r.b.Reserved = res
|
||||
if c.reserve {
|
||||
res.sources = append(res.sources, versions.Source{Fingerprint: fp1})
|
||||
@@ -155,8 +172,16 @@ func TestABuildStepPassesAReservingBuildOnlyWithItsReservedVersion(t *testing.T)
|
||||
if end.Outcome != c.want || !strings.Contains(end.Said, c.said) || (c.want == meshbuilds.StepEndedOutcomeFailed && strings.Contains(end.Said, "builder_reserve_done") == c.takenOver) {
|
||||
t.Errorf("end = %+v, want %s saying %q", end, c.want, c.said)
|
||||
}
|
||||
// The verdict of a build that ended done, as a build ended now is judged, says the same (H-A-508: the newest entry first).
|
||||
if c.superseded {
|
||||
entry, _ := r.b.StepEntry(t.Context(), fp1)
|
||||
if outcome, said := r.b.passedWithItsVersion(t.Context(), entry); outcome != c.want || !strings.Contains(said, c.said) {
|
||||
t.Errorf("built now: %s %q, want %s saying %q", outcome, said, c.want, c.said)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
t.Run("H-A-508: built now, superseded: a newer entry heard while the build runs ends the step superseded", aNewerEntryWhileTheBuildRunsSupersedesTheStep)
|
||||
t.Run("H-A-155: an ask waits for the picture to take its revision in, then builds with its version reserved", aStepAskWaitsForItsRevision)
|
||||
t.Run("H-A-155: past the bound the ask fails naming its revision, and nothing is built", aStepAskPastItsRevisionBoundFails)
|
||||
t.Run("H-A-205: an ask of a revision below the picture's newest is read by number and built", anOlderKeptRevisionIsReadByNumber)
|
||||
@@ -452,7 +477,7 @@ func aStepAskWaitsForItsRevision(t *testing.T) {
|
||||
// H-A-205: two pipelines of consecutive revisions run at once; the picture holds source revision 46, while the older pipeline
|
||||
// asks the build of revision 45. Its kept catalog revision is read by number and the build runs while the picture never heard
|
||||
// a newer entry of m (a restart); once it heard one on the first branch, H-A-489 overrides H-A-205 and the older ask is refused
|
||||
// superseded. A kept revision naming another fingerprint fails the step, naming it.
|
||||
// superseded. A kept revision naming another fingerprint ends the step superseded, naming it (H-A-508 second addendum).
|
||||
func anOlderKeptRevisionIsReadByNumber(t *testing.T) {
|
||||
var held atomic.Int64
|
||||
held.Store(46)
|
||||
@@ -476,8 +501,8 @@ func anOlderKeptRevisionIsReadByNumber(t *testing.T) {
|
||||
if len(res.sources) != 1 || res.sources[0].Revision != 45 || res.sources[0].CatalogRevision != 47 {
|
||||
t.Errorf("reserved from %+v; want one version reserved from source revision 45 at catalog revision 47 (H-A-218)", res.sources)
|
||||
}
|
||||
// H-A-489: once the picture heard the newer entry of m on the first branch, the older ask is refused superseded and
|
||||
// nothing is built or reserved for it; the newer entry's build keeps the series.
|
||||
// H-A-489, H-A-508: once the picture heard the newer entry of m on the first branch, the older ask ends superseded (never
|
||||
// failed) and nothing is built or reserved for it; the newer entry's build keeps the series.
|
||||
rn, resn, entryn := revisionRig(t, &held, make(chan struct{}, 1))
|
||||
rn.b.RevisionWait = time.Nanosecond
|
||||
rn.b.FirstBranch = r.b.FirstBranch
|
||||
@@ -487,8 +512,8 @@ func anOlderKeptRevisionIsReadByNumber(t *testing.T) {
|
||||
entryn.Fp = fp2
|
||||
rn.b.Entry(context.Background(), Origin{Branch: "main", Source: 46, First: true}, entryn)
|
||||
rn.b.Wait()
|
||||
if endn := rn.b.BuildStep(t.Context(), "a1", run); endn.Outcome != meshbuilds.StepEndedOutcomeFailed || !strings.Contains(endn.Said, "superseded by "+fp2) {
|
||||
t.Errorf("the older ask after the newer entry: end = %+v; want failed, superseded by %s", endn, fp2)
|
||||
if endn := rn.b.BuildStep(t.Context(), "a1", run); endn.Outcome != meshbuilds.StepEndedOutcomeSuperseded || !strings.Contains(endn.Said, "superseded by "+fp2) {
|
||||
t.Errorf("the older ask after the newer entry: end = %+v; want superseded by %s", endn, fp2)
|
||||
}
|
||||
rn.b.Wait()
|
||||
if _, built := rn.st.vals[rn.key]; built || len(resn.sources) != 1 || resn.sources[0].Fingerprint != fp2 {
|
||||
@@ -499,8 +524,10 @@ func anOlderKeptRevisionIsReadByNumber(t *testing.T) {
|
||||
r2.b.KeptRevision = func(context.Context, string, int64) (int64, map[string]string, error) {
|
||||
return 45, map[string]string{"m": "src2:other"}, nil
|
||||
}
|
||||
if end := r2.b.BuildStep(t.Context(), "a1", run); end.Outcome != meshbuilds.StepEndedOutcomeFailed || !strings.Contains(end.Said, "names m at \"src2:other\"") {
|
||||
t.Errorf("end = %+v; want failed naming the fingerprint the kept revision names", end)
|
||||
// H-A-508 second addendum: below the picture, a kept revision naming another fingerprint of the module superseded the
|
||||
// ask's: the step ends superseded naming it, never failed with the "below" words.
|
||||
if end := r2.b.BuildStep(t.Context(), "a1", run); end.Outcome != meshbuilds.StepEndedOutcomeSuperseded || end.Said != stepSuperseded("m", fp1, "src2:other") {
|
||||
t.Errorf("end = %+v; want superseded naming the fingerprint the kept revision names", end)
|
||||
}
|
||||
// H-A-222: an ask of the very source the picture holds, whose entries the picture no longer names (a re-pin kept revision 48
|
||||
// of the same source 46 and the picture took its entries in), is held by its revision read by number, never waited for.
|
||||
@@ -519,7 +546,7 @@ func anOlderKeptRevisionIsReadByNumber(t *testing.T) {
|
||||
if end3.Outcome != meshbuilds.StepEndedOutcomePassed || !slices.Equal(read3, []string{"main 48"}) || len(res3.sources) != 1 || res3.sources[0].CatalogRevision != 48 {
|
||||
t.Errorf("end = %+v, kept revisions read %v, reserved %+v; want passed, revision 48 of main read once and reserved at it", end3, read3, res3.sources)
|
||||
}
|
||||
// H-A-218, H-A-222: a kept revision of another source than the ask names, or naming another fingerprint, is a mismatch:
|
||||
// H-A-218, H-A-222: a kept revision of another source than the ask names is a mismatch:
|
||||
// the step fails at once naming it, never waiting out its bound (the bound here is long, the ask is not below the picture).
|
||||
for _, c := range []struct {
|
||||
name string
|
||||
@@ -528,7 +555,6 @@ func anOlderKeptRevisionIsReadByNumber(t *testing.T) {
|
||||
said string
|
||||
}{
|
||||
{"another source", 45, fp1, "the catalog's revision 48 is of source revision 45, the ask names 46"},
|
||||
{"another fingerprint", 46, "src2:other", "names m at \"src2:other\""},
|
||||
} {
|
||||
rc, resc, _ := revisionRig(t, &held, make(chan struct{}, 1))
|
||||
rc.b.RevisionWait = time.Hour
|
||||
@@ -541,6 +567,18 @@ func anOlderKeptRevisionIsReadByNumber(t *testing.T) {
|
||||
t.Errorf("%s: end = %+v, reserved %+v; want failed at once saying %q, nothing reserved", c.name, end, resc.sources, c.said)
|
||||
}
|
||||
}
|
||||
// H-A-508 second addendum, found by either check: a revision read by its number (H-A-222) whose kept revision names another
|
||||
// fingerprint of m superseded the ask's: it ends superseded at once naming it, never failed and never waiting its bound.
|
||||
rs, ress, _ := revisionRig(t, &held, make(chan struct{}, 1))
|
||||
rs.b.RevisionWait = time.Hour
|
||||
rs.b.KeptRevision = func(context.Context, string, int64) (int64, map[string]string, error) {
|
||||
return 46, map[string]string{"m": "src2:other"}, nil
|
||||
}
|
||||
ends := rs.b.BuildStep(t.Context(), "a1", same)
|
||||
rs.b.Wait()
|
||||
if ends.Outcome != meshbuilds.StepEndedOutcomeSuperseded || ends.Said != stepSuperseded("m", fp1, "src2:other") || len(ress.sources) != 0 {
|
||||
t.Errorf("by its number, another fingerprint: end = %+v, reserved %+v; want superseded by src2:other at once, nothing reserved", ends, ress.sources)
|
||||
}
|
||||
}
|
||||
|
||||
func aStepAskPastItsRevisionBoundFails(t *testing.T) {
|
||||
@@ -568,3 +606,65 @@ func digestOf(unreadable bool) string {
|
||||
}
|
||||
return mdigest('a')
|
||||
}
|
||||
|
||||
// H-A-508 (review rounds 1, 2): a newer entry of the branch heard while the step's build runs withdraws that build (the key
|
||||
// ends "withdrawn: … superseded by …", as main.327's mesh-delivery-gate build did); the step waiting on it ends superseded,
|
||||
// naming the newer fingerprint, judged before the build's failed end, never failed.
|
||||
func aNewerEntryWhileTheBuildRunsSupersedesTheStep(t *testing.T) {
|
||||
r := newRig(t, goBundle)
|
||||
var asked int32
|
||||
running := make(chan struct{})
|
||||
r.asks.Answer = func(a buildstep.StepAsk) buildstep.Step {
|
||||
if atomic.AddInt32(&asked, 1) == 1 { // fp1's ask runs until it is withdrawn
|
||||
defer close(running)
|
||||
return buildstep.Step{ID: a.ID, Node: "ace", State: buildstep.StepRunning, Started: time.Now()}
|
||||
}
|
||||
return r.answer(a)
|
||||
}
|
||||
r.b.Asks = buildrun.Asker{Seats: testSeats(), Publisher: r.asks, Waiter: r.asks, Bound: 2 * time.Second, Dropper: &seatDrops{}}
|
||||
r.b.StepEntry = func(context.Context, string) (meshcatalog.CatalogEntry, error) {
|
||||
return meshcatalog.CatalogEntry{Module: "m", Repository: "novox/mesh-catalog", Commit: "7a74cee83f88e6585a5511c3cc53bdf0f5303d20", Fp: fp1, ManifestDigest: mdigest('a'), Path: "modules/m"}, nil
|
||||
}
|
||||
r.b.Module(t.Context(), "m", moduleValue(t, "modules/m")) // fp1, the newest entry heard, is built
|
||||
<-running
|
||||
ended := make(chan meshbuilds.StepEnded, 1)
|
||||
go func() {
|
||||
ended <- r.b.BuildStep(t.Context(), "a1", meshbuilds.StepRun{Pipeline: "main.1.m", Step: meshbuilds.StepRunStepBuild, Entries: []meshbuilds.BuildEntry{{Module: "m", Fingerprint: fp1}}})
|
||||
}()
|
||||
// The step waits on the end of fp1's build in flight before the newer entry is heard.
|
||||
for deadline := time.Now().Add(5 * time.Second); ; runtime.Gosched() {
|
||||
r.b.mu.Lock()
|
||||
n := len(r.b.stepWaits[r.key])
|
||||
r.b.mu.Unlock()
|
||||
if n > 0 {
|
||||
break
|
||||
}
|
||||
select {
|
||||
case end := <-ended:
|
||||
t.Fatalf("the step ended before it waited on the build in flight: %+v", end)
|
||||
default:
|
||||
}
|
||||
if time.Now().After(deadline) {
|
||||
t.Fatal("the step never waited on the build in flight")
|
||||
}
|
||||
}
|
||||
newer, err := meshcatalogclient.EncodeModule(meshcatalog.ModulesByModuleValue{Repository: "novox/mesh-catalog", Commit: "7a74cee83f88e6585a5511c3cc53bdf0f5303d20",
|
||||
Fp: "src1:" + hex64('f'), Fp2: fp2, Manifest: mdigest('a'), Path: "modules/m", Toolchains: CatalogToolchains(agreedToolchains)})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r.b.Module(t.Context(), "m", newer)
|
||||
var end meshbuilds.StepEnded
|
||||
select {
|
||||
case end = <-ended:
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Fatal("the step never ended")
|
||||
}
|
||||
r.b.Wait()
|
||||
if v := valueOf(t, r.st, r.key); v.State != builds.BuildFailed || !strings.HasPrefix(v.Error, withdrawnPrefix) || !strings.Contains(v.Error, "superseded by the fingerprint "+fp2) {
|
||||
t.Fatalf("fp1's key = %+v, want its build withdrawn, superseded by %s", v, fp2)
|
||||
}
|
||||
if end.Outcome != meshbuilds.StepEndedOutcomeSuperseded || !strings.Contains(end.Said, "m at "+fp1+" is superseded by "+fp2) {
|
||||
t.Errorf("end = %+v, want superseded by %s", end, fp2)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -424,6 +424,9 @@ type ReleasedBuild struct {
|
||||
Version string `json:"version"`
|
||||
// Digests are the published digest of each artifact, by reference (H-A-331); absent for a release kept before.
|
||||
Digests map[string]string `json:"digests,omitempty"`
|
||||
// Withdrawn are the fingerprints whose numbers the released version took over, by the number withdrawn (H-A-226), so a
|
||||
// takeover still answers once the release deleted the series key (H-A-508); absent for a release that took none over.
|
||||
Withdrawn map[string]string `json:"withdrawn,omitempty"`
|
||||
}
|
||||
|
||||
// ReleasedFor says whether the builder saw a version released for the build of fingerprint among the module's last releases.
|
||||
@@ -494,7 +497,7 @@ func (r *Reserver) PublishedOf(ctx context.Context, module, artifact, fingerprin
|
||||
}
|
||||
|
||||
// keepRelease adds a release to the module's record, dropping the oldest past ReleasedKept.
|
||||
func (r *Reserver) keepRelease(ctx context.Context, module, fingerprint, version string, digests map[string]string) error {
|
||||
func (r *Reserver) keepRelease(ctx context.Context, module, fingerprint, version string, digests, withdrawn map[string]string) error {
|
||||
n := r.ReleasedKept
|
||||
if n < 1 {
|
||||
n = DefaultReleasedKept
|
||||
@@ -514,7 +517,7 @@ func (r *Reserver) keepRelease(ctx context.Context, module, fingerprint, version
|
||||
kept = append(kept, k)
|
||||
}
|
||||
}
|
||||
kept = append(kept, ReleasedBuild{Fingerprint: fingerprint, Version: version, Digests: digests})
|
||||
kept = append(kept, ReleasedBuild{Fingerprint: fingerprint, Version: version, Digests: digests, Withdrawn: maps.Clone(withdrawn)})
|
||||
if len(kept) > n {
|
||||
kept = kept[len(kept)-n:]
|
||||
}
|
||||
@@ -553,7 +556,7 @@ func (r *Reserver) Released(ctx context.Context, module, version string) ([]stri
|
||||
continue
|
||||
}
|
||||
if cur.Version == version && cur.Fingerprint != "" && r.Releases != nil {
|
||||
if err := r.keepRelease(ctx, module, cur.Fingerprint, version, cur.Artifacts); err != nil {
|
||||
if err := r.keepRelease(ctx, module, cur.Fingerprint, version, cur.Artifacts, cur.Withdrawn); err != nil {
|
||||
return gone, fmt.Errorf("the release of %s %s cannot be recorded: %w", module, version, err)
|
||||
}
|
||||
}
|
||||
@@ -625,7 +628,9 @@ func (r *Reserver) All(ctx context.Context) ([]ReservedVersion, error) {
|
||||
}
|
||||
|
||||
// TakenOver is the reservation of module's series whose withdrawn numbers hold one of the build of fingerprint (design 47 H
|
||||
// H-A-226), and whether there is one: the series moved to that reservation's fingerprint and version (H-A-244).
|
||||
// H-A-226), and whether there is one: the series moved to that reservation's fingerprint and version (H-A-244). Once that
|
||||
// version is released and its series key deleted, the release record answers it, naming the fingerprints it withdrew
|
||||
// (H-A-508): the newest such release, as a reservation of its fingerprint and version.
|
||||
func (r *Reserver) TakenOver(ctx context.Context, module, fingerprint string) (ReservedVersion, bool, error) {
|
||||
all, err := r.All(ctx)
|
||||
if err != nil {
|
||||
@@ -641,6 +646,30 @@ func (r *Reserver) TakenOver(ctx context.Context, module, fingerprint string) (R
|
||||
}
|
||||
}
|
||||
}
|
||||
if r.Releases == nil {
|
||||
return ReservedVersion{}, false, nil
|
||||
}
|
||||
raw, _, found, err := r.Releases.Get(ctx, ReleasedKey(module))
|
||||
if err != nil || !found {
|
||||
return ReservedVersion{}, false, err
|
||||
}
|
||||
var rec ReleasedRecord
|
||||
if err := json.Unmarshal(raw, &rec); err != nil {
|
||||
// A record that cannot be read answers no "not taken over": the caller says it cannot judge (H-A-508).
|
||||
return ReservedVersion{}, false, fmt.Errorf("the release record of %s cannot be read: %w", module, err)
|
||||
}
|
||||
for i := len(rec.Kept) - 1; i >= 0; i-- {
|
||||
k := rec.Kept[i]
|
||||
if k.Fingerprint == fingerprint {
|
||||
continue
|
||||
}
|
||||
for _, fp := range k.Withdrawn {
|
||||
if fp == fingerprint {
|
||||
series, _, _ := SplitVersion(k.Version)
|
||||
return ReservedVersion{V: 1, Module: module, Series: series, Version: k.Version, Fingerprint: k.Fingerprint}, true, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return ReservedVersion{}, false, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -326,7 +326,7 @@ func TestTheWithdrawnVersionsAreDroppedOnceReleasedPast(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
store := &reserveMem{mem: newMem()}
|
||||
highest := "0.1.3"
|
||||
r := &Reserver{Store: store, Filled: func() bool { return true },
|
||||
r := &Reserver{Store: store, Releases: &reserveMem{mem: newMem()}, Filled: func() bool { return true },
|
||||
ReleasedOf: func(context.Context, string) ([]string, error) { return []string{highest}, nil }}
|
||||
for _, fp := range []string{"src2:a", "src2:b", "src2:c"} {
|
||||
if _, err := r.Reserve(ctx, "m", "0.1", []string{"m:a"}, Source{Fingerprint: fp}); err != nil {
|
||||
@@ -349,6 +349,27 @@ func TestTheWithdrawnVersionsAreDroppedOnceReleasedPast(t *testing.T) {
|
||||
if err != nil || got.Version != "0.1.7" || len(got.Withdrawn) != 1 || got.Withdrawn["0.1.6"] != "src2:c" {
|
||||
t.Errorf("reserved %+v (%v); want 0.1.7 keeping only 0.1.6 withdrawn", got, err)
|
||||
}
|
||||
// H-A-508: the release of the version that took over deletes the series key; the release record still names the
|
||||
// fingerprint it withdrew, so the stale build finds the series moved, never "no version is reserved".
|
||||
if _, err := r.Released(ctx, "m", "0.1.7"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, _, found, _ := r.get(ctx, ReservedKey("m", "0.1")); found {
|
||||
t.Fatal("the released series key stands")
|
||||
}
|
||||
if by, took, err := r.TakenOver(ctx, "m", "src2:c"); err != nil || !took || by.Fingerprint != "src2:d" || by.Version != "0.1.7" {
|
||||
t.Errorf("after the release taken over from src2:c by %+v (%v, %v); want src2:d 0.1.7", by, took, err)
|
||||
}
|
||||
if _, took, err := r.TakenOver(ctx, "m", "src2:d"); err != nil || took {
|
||||
t.Errorf("the released build src2:d is said taken over (%v, %v)", took, err)
|
||||
}
|
||||
// A release record that cannot be read answers its error, never "not taken over".
|
||||
if _, err := r.Releases.Create(ctx, ReleasedKey("n"), []byte("{not json")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, took, err := r.TakenOver(ctx, "n", "src2:x"); err == nil || took {
|
||||
t.Errorf("an unreadable release record answered taken over %v, %v; want its error", took, err)
|
||||
}
|
||||
}
|
||||
|
||||
// TestARebuildReservesAboveTheCatalogsHighestWhateverItsStandingNumberWas: design 47 G A-490b as H-A-225 amends it — a build again
|
||||
|
||||
@@ -13,13 +13,13 @@ const Seat = "mesh-builds"
|
||||
|
||||
// Form is the form of the seat's values, events and answers this contract was generated at (design 47 H2 §780):
|
||||
// a reader of a value of another form says "form N, this reader knows M".
|
||||
const Form = 1
|
||||
const Form = 2
|
||||
|
||||
// The forms and the digest of the fields this contract was generated from: the generator's compare fails a definition
|
||||
// whose fields changed while its forms did not (design 47 H2 §780).
|
||||
const (
|
||||
generatedForms = "1"
|
||||
generatedFieldsDigest = "AskTakenEvent=6d5d3da7ac39 BuildEntry=3c829a0a3d58 Dependency=90a32b07c563 DropAnswer=7538f2f5e68e PackagePublished=34dd069a6aab PackagePublishedEvent=8e12888c1559 PublishQueueAnswer=0f1326e35e17 PublishQueueAnswerCountsItem=b770db2f0920 PublishQueueAnswerQueueItem=b1eebc09f41e PublishedAnswer=69a801982819 ReservedAnswer=2272a4d6f0f4 ReservedAnswerArtifactsItem=d74eb6e00abb StepAccept=18efeefb6c34 StepEnded=09a07bfbcb15 StepEndedEvent=207787118dac StepRun=dc5893aef7e5 ToolchainAgreed=f3d9ce993734 ToolchainAgreedDigestsItem=1d42893a96b9 ToolchainAgreedEvent=e3502d6f194d VersionReservedEvent=984547d6ad07"
|
||||
generatedForms = "2"
|
||||
generatedFieldsDigest = "AskTakenEvent=6d5d3da7ac39 BuildEntry=3c829a0a3d58 Dependency=90a32b07c563 DropAnswer=7538f2f5e68e PackagePublished=34dd069a6aab PackagePublishedEvent=8e12888c1559 PublishQueueAnswer=0f1326e35e17 PublishQueueAnswerCountsItem=b770db2f0920 PublishQueueAnswerQueueItem=b1eebc09f41e PublishedAnswer=69a801982819 ReservedAnswer=2272a4d6f0f4 ReservedAnswerArtifactsItem=d74eb6e00abb StepAccept=18efeefb6c34 StepEnded=40a0090f7cb5 StepEndedEvent=207787118dac StepRun=dc5893aef7e5 ToolchainAgreed=f3d9ce993734 ToolchainAgreedDigestsItem=1d42893a96b9 ToolchainAgreedEvent=e3502d6f194d VersionReservedEvent=984547d6ad07"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -163,13 +163,13 @@ type StepEnded struct {
|
||||
ID string `json:"id"`
|
||||
// the node the builder ran it on, as in the subject
|
||||
Node string `json:"node"`
|
||||
// never passed for a build that built nothing
|
||||
// never passed for a build that built nothing; superseded for an entry whose fingerprint a newer entry of its branch superseded, built or not (design 47 H2 H-A-508): the mover moved to the newer revision's pipeline, never a failure
|
||||
Outcome string `json:"outcome"`
|
||||
// the pins the step's entries were built with, each mesh package's version by its module path, the ones the builder took from the registry for a package the entry named with none included; the runner asks the entry's held test steps with them (H-A-207)
|
||||
Packages map[string]string `json:"packages,omitempty"`
|
||||
Pipeline string `json:"pipeline"`
|
||||
Rerun bool `json:"rerun,omitempty"`
|
||||
// why it failed or could not run: the entry not built, the part not heard
|
||||
// why it failed, could not run or was superseded: the entry not built, the part not heard, the superseding fingerprint
|
||||
Said string `json:"said,omitempty"`
|
||||
Started *time.Time `json:"started,omitempty"`
|
||||
Step string `json:"step"`
|
||||
@@ -183,6 +183,7 @@ const (
|
||||
StepEndedOutcomeFailed = "failed"
|
||||
StepEndedOutcomeNothingToRun = "nothing to run"
|
||||
StepEndedOutcomeCouldNotRun = "could not run"
|
||||
StepEndedOutcomeSuperseded = "superseded"
|
||||
)
|
||||
|
||||
// The values of StepEnded's step.
|
||||
|
||||
@@ -25,6 +25,8 @@ func TestFixtures(t *testing.T) {
|
||||
decode: func(b []byte) (any, error) { var v StepEndedEvent; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-builds\\.event\\.step-ended\\.[^.*> ]+$")},
|
||||
{name: "the build step failed on its entry", subject: "mesh.seat.mesh-builds.event.step-ended.laptop", given: "{\"entries\":[{\"fingerprint\":\"fp-0123\",\"module\":\"nats\"}],\"id\":\"m2kx9a1b3c4d6b\",\"node\":\"laptop\",\"outcome\":\"failed\",\"pipeline\":\"main.12.nats\",\"said\":\"nats:program did not build\",\"step\":\"build\",\"v\":1}", wire: "{\"entries\":[{\"fingerprint\":\"fp-0123\",\"module\":\"nats\"}],\"id\":\"m2kx9a1b3c4d6b\",\"node\":\"laptop\",\"outcome\":\"failed\",\"pipeline\":\"main.12.nats\",\"said\":\"nats:program did not build\",\"step\":\"build\",\"v\":1}",
|
||||
decode: func(b []byte) (any, error) { var v StepEndedEvent; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-builds\\.event\\.step-ended\\.[^.*> ]+$")},
|
||||
{name: "the build step ended superseded: a newer entry of its branch superseded its fingerprint (H-A-508)", subject: "mesh.seat.mesh-builds.event.step-ended.laptop", given: "{\"entries\":[{\"fingerprint\":\"fp-0123\",\"module\":\"nats\"}],\"form\":2,\"id\":\"m2kx9a1b3c4d6c\",\"node\":\"laptop\",\"outcome\":\"superseded\",\"pipeline\":\"main.12.nats\",\"said\":\"nats at fp-0123 is superseded by fp-0456, the newest entry heard on its first branch\",\"step\":\"build\",\"v\":1}", wire: "{\"entries\":[{\"fingerprint\":\"fp-0123\",\"module\":\"nats\"}],\"form\":2,\"id\":\"m2kx9a1b3c4d6c\",\"node\":\"laptop\",\"outcome\":\"superseded\",\"pipeline\":\"main.12.nats\",\"said\":\"nats at fp-0123 is superseded by fp-0456, the newest entry heard on its first branch\",\"step\":\"build\",\"v\":1}",
|
||||
decode: func(b []byte) (any, error) { var v StepEndedEvent; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-builds\\.event\\.step-ended\\.[^.*> ]+$")},
|
||||
{name: "an ask taken at the pull", subject: "mesh.seat.mesh-builds.event.ask-taken.main-3589-mesh-sdk-unit", given: "{\"ask\":\"main-3589-mesh-sdk-unit\",\"at\":\"2026-11-21T22:00:00Z\",\"node\":\"anchor\"}", wire: "{\"ask\":\"main-3589-mesh-sdk-unit\",\"at\":\"2026-11-21T22:00:00Z\",\"node\":\"anchor\"}",
|
||||
decode: func(b []byte) (any, error) { var v AskTakenEvent; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-builds\\.event\\.ask-taken\\.[^.*> ]+$")},
|
||||
{name: "a version reserved at a fingerprint", subject: "mesh.seat.mesh-builds.event.version-reserved", given: "{\"artifact\":\"mesh-sdk:go\",\"fingerprint\":\"sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\",\"form\":1,\"module\":\"mesh-sdk\",\"path\":\"git.novox.be/novox/mesh-sdk/go\",\"revision\":\"412\",\"version\":\"0.1.21\"}", wire: "{\"artifact\":\"mesh-sdk:go\",\"fingerprint\":\"sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\",\"form\":1,\"module\":\"mesh-sdk\",\"path\":\"git.novox.be/novox/mesh-sdk/go\",\"revision\":\"412\",\"version\":\"0.1.21\"}",
|
||||
|
||||
@@ -14,13 +14,13 @@ const Seat = "mesh-pipeline-runner"
|
||||
|
||||
// Form is the form of the seat's values, events and answers this contract was generated at (design 47 H2 §780):
|
||||
// a reader of a value of another form says "form N, this reader knows M".
|
||||
const Form = 8
|
||||
const Form = 10
|
||||
|
||||
// The forms and the digest of the fields this contract was generated from: the generator's compare fails a definition
|
||||
// whose fields changed while its forms did not (design 47 H2 §780).
|
||||
const (
|
||||
generatedForms = "8"
|
||||
generatedFieldsDigest = "AcceptAnswer=224df0394653 Accepted=d2b011e5090f AskAgainAnswer=224df0394653 CancelAnswer=a0dcc32b3f57 EndAgainAnswer=a0dcc32b3f57 FailedStep=cd7184342136 Fill=7a76c9ceb157 FillingEvent=5bd4df78ed84 FullEvent=5bd4df78ed84 KeptAnswer=dfe0d48bc169 KeptByLevelDigestValue=f06c90f7da7f KeptResult=af5f81f189b7 ListAnswer=284210b3c054 LogEntry=b059967b2ae4 Member=8a103baec01f Mover=5db376275bcf MoverEnded=4b35095f6829 MoverRow=b61f41d131a3 Pipeline=2663792125bf PipelineEnded=523f8fc0fe41 PipelineEndedEvent=cb44007f7173 PipelineEndedPhases=9d1c33ce4cc4 PipelineEndedPhasesBuild=a08d49692a09 PipelineEndedPhasesComposition=a08d49692a09 PipelineEndedPhasesIntegration=a08d49692a09 PipelineEndedPhasesLint=a08d49692a09 PipelineEndedPhasesUnit=a08d49692a09 PipelineEndedPhasesValidate=a08d49692a09 PipelineRow=f58dbdcaf2d4 PipelineStarted=a3d000f095db PipelineStartedEvent=eaa401af4117 PipelinesByBranchRevisionAgainNValue=693580eed498 PipelinesByBranchRevisionUnfinishedModuleValue=693580eed498 PipelinesByBranchRevisionValue=693580eed498 PipelinesByBranchRunRunValue=693580eed498 PipelinesByBranchSourcePublishedPackageVersionValue=693580eed498 PipelinesByStepsPipelineMoverValue=94de99db7816 PlaceAnswer=a0dcc32b3f57 PlaceUnfinishedAnswer=ed94ced4513a Published=d9af3024dacc QueueByQueueNextValue=765a2918a728 QueueByRunningPipelineValue=ed94ced4513a QueueByWaitingSequenceValue=99605298ae13 RePinnedEvent=92fd04bfa6d3 RerunAnswer=9b7efd0df344 ReviewAnswer=f397b8965179 RoomEvent=5bd4df78ed84 RunAnswer=96bd45aa2e62 RunStarted=b280617410c3 RunStartedEvent=0767a9358fa3 Shared=c981cf6aa860 SharedAskedBy=c9b30cc4d0d0 ShowAnswer=48b8cecc529a StandsAnswer=0afa3693bf3b StartAnswer=ed94ced4513a StepEndedEvent=799020642c19 StepEvent=64f18c40ed5d StepLogByPipelineValue=ffdde090a101 StepResult=0dac0e15d017 StepStartedEvent=799020642c19 TestCounts=9c1332427159 TestRun=ca5a87f3b6b8 TestRunPackage=a7d30558470d TestRunReader=c9b30cc4d0d0 TestRunsAnswer=7ab81a45ca33 TestRunsDropAnswer=8ee70b35469d ToolchainUsed=43b6d42376fb Wait=21e4ee7a3ef1 WaitEndedEvent=2bf6d38041c0 WaitHeldEvent=2bf6d38041c0 Waiting=ed94ced4513a WhyCarriedAnswer=8e2fcea6479f Widening=e2790a307466"
|
||||
generatedForms = "10"
|
||||
generatedFieldsDigest = "AcceptAnswer=224df0394653 Accepted=d2b011e5090f AskAgainAnswer=224df0394653 CancelAnswer=a0dcc32b3f57 EndAgainAnswer=a0dcc32b3f57 FailedStep=cd7184342136 Fill=7a76c9ceb157 FillingEvent=5bd4df78ed84 FullEvent=5bd4df78ed84 KeptAnswer=dfe0d48bc169 KeptByLevelDigestValue=f06c90f7da7f KeptResult=af5f81f189b7 ListAnswer=284210b3c054 LogEntry=b059967b2ae4 Member=8a103baec01f Mover=5db376275bcf MoverEnded=4b35095f6829 MoverRow=b61f41d131a3 Pipeline=2663792125bf PipelineEnded=e3f4c58f93c8 PipelineEndedEvent=cb44007f7173 PipelineEndedPhases=9d1c33ce4cc4 PipelineEndedPhasesBuild=a08d49692a09 PipelineEndedPhasesComposition=a08d49692a09 PipelineEndedPhasesIntegration=a08d49692a09 PipelineEndedPhasesLint=a08d49692a09 PipelineEndedPhasesUnit=a08d49692a09 PipelineEndedPhasesValidate=a08d49692a09 PipelineRow=f58dbdcaf2d4 PipelineStarted=582f8ff3b28d PipelineStartedEvent=eaa401af4117 PipelinesByBranchRevisionAgainNValue=693580eed498 PipelinesByBranchRevisionUnfinishedModuleValue=693580eed498 PipelinesByBranchRevisionValue=693580eed498 PipelinesByBranchRunRunValue=693580eed498 PipelinesByBranchSourcePublishedPackageVersionValue=693580eed498 PipelinesByStepsPipelineMoverValue=94de99db7816 PlaceAnswer=a0dcc32b3f57 PlaceUnfinishedAnswer=ed94ced4513a Published=d9af3024dacc QueueByQueueNextValue=765a2918a728 QueueByRunningPipelineValue=ed94ced4513a QueueByWaitingSequenceValue=99605298ae13 RePinnedEvent=92fd04bfa6d3 RerunAnswer=9b7efd0df344 ReviewAnswer=f397b8965179 RoomEvent=5bd4df78ed84 RunAnswer=96bd45aa2e62 RunStarted=b280617410c3 RunStartedEvent=0767a9358fa3 Shared=c981cf6aa860 SharedAskedBy=c9b30cc4d0d0 ShowAnswer=48b8cecc529a StandsAnswer=0afa3693bf3b StartAnswer=ed94ced4513a StepEndedEvent=799020642c19 StepEvent=64f18c40ed5d StepLogByPipelineValue=ffdde090a101 StepResult=0dac0e15d017 StepStartedEvent=799020642c19 TestCounts=9c1332427159 TestRun=ca5a87f3b6b8 TestRunPackage=a7d30558470d TestRunReader=c9b30cc4d0d0 TestRunsAnswer=7ab81a45ca33 TestRunsDropAnswer=8ee70b35469d ToolchainUsed=43b6d42376fb Wait=21e4ee7a3ef1 WaitEndedEvent=2bf6d38041c0 WaitHeldEvent=2bf6d38041c0 Waiting=ed94ced4513a WhyCarriedAnswer=8e2fcea6479f Widening=e2790a307466"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -775,7 +775,7 @@ type Pipeline struct {
|
||||
Revision int64 `json:"revision,omitempty"`
|
||||
// the run on request's id, for a pipeline of a run; such a pipeline delivers nothing
|
||||
Run string `json:"run,omitempty"`
|
||||
// for a pipeline written over pipelines-at-once, its place in the queue: the runner's counter queue.next at its write (design 47 H §748)
|
||||
// its place in the runner's sequence: the runner's counter queue.next at its write, taken for every pipeline it writes, queued or placed at once, so it grows across the pipelines of a branch (design 47 H §748; H2 §813 (1), H-A-504 addendum)
|
||||
Seq int64 `json:"seq,omitempty"`
|
||||
// the source revision of the watched branch; the pipeline is keyed by it (ADR 0666 section 9)
|
||||
Source int64 `json:"source"`
|
||||
@@ -897,6 +897,8 @@ type PipelineEnded struct {
|
||||
Revision int64 `json:"revision,omitempty"`
|
||||
// the run on request's id, for a pipeline of a run; such a pipeline delivers nothing
|
||||
Run string `json:"run,omitempty"`
|
||||
// the pipeline's sequence, its record's seq: the assigner writes it as the run of the wants the pipeline's pass writes (design 47 H2 §813 (1), H-A-504 addendum)
|
||||
Seq int64 `json:"seq,omitempty"`
|
||||
// the source revision of the watched branch; the pipeline is keyed by it (ADR 0666 section 9)
|
||||
Source int64 `json:"source"`
|
||||
Started *time.Time `json:"started,omitempty"`
|
||||
@@ -948,7 +950,7 @@ const (
|
||||
PipelineRowOutcomeCancelled = "cancelled"
|
||||
)
|
||||
|
||||
// PipelineStarted is a pipeline's start, said at its write, a waiting one's too (design 47 H §746, H-A-52).
|
||||
// PipelineStarted is a pipeline's start, said at its write, a waiting one's too (design 47 H §746, H-A-52), and again at a re-pin with its kept revisions (H2 H-A-496).
|
||||
type PipelineStarted struct {
|
||||
At *time.Time `json:"at,omitempty"`
|
||||
// the watched branch, or the branch of a run on request
|
||||
@@ -957,6 +959,8 @@ type PipelineStarted struct {
|
||||
Call string `json:"call,omitempty"`
|
||||
// is the form of what this value carries, left out while it is 1 (design 47 H2 §780).
|
||||
Form int64 `json:"form,omitempty"`
|
||||
// every catalog revision the pipeline's movers are kept at, said again in full at each re-pin, so the indexer pins each while the pipeline runs (design 47 H2 H-A-496 and its addendum)
|
||||
Kept []int64 `json:"kept,omitempty"`
|
||||
// the pipeline's movers
|
||||
Movers []Mover `json:"movers"`
|
||||
// the pipeline's key, <branch>.<revision>, or <branch>.<source>.published.<package>.<version> for a pipeline a publish started; a branch escaped as a key's name is (design 47 H §746, §747)
|
||||
|
||||
@@ -19,6 +19,10 @@ func TestFixtures(t *testing.T) {
|
||||
}{
|
||||
{name: "a take-in's pipeline started with its two movers", subject: "mesh.seat.mesh-pipeline-runner.event.pipeline-started.main.3589", given: "{\"at\":\"2026-11-10T10:00:00Z\",\"branch\":\"main\",\"call\":\"0123456789abcdef\",\"movers\":[{\"commit\":\"0123456789abcdef0123456789abcdef01234567\",\"fingerprint\":\"fp-sdk\",\"module\":\"mesh-sdk\",\"repository\":\"mesh-sdk\",\"tier\":1},{\"commit\":\"0123456789abcdef0123456789abcdef01234567\",\"fingerprint\":\"fp-0123\",\"module\":\"nats\",\"repository\":\"mesh-networking\",\"tier\":2}],\"pipeline\":\"main.3589\",\"revision\":12,\"source\":3589,\"v\":1}", wire: "{\"at\":\"2026-11-10T10:00:00Z\",\"branch\":\"main\",\"call\":\"0123456789abcdef\",\"movers\":[{\"commit\":\"0123456789abcdef0123456789abcdef01234567\",\"fingerprint\":\"fp-sdk\",\"module\":\"mesh-sdk\",\"repository\":\"mesh-sdk\",\"tier\":1},{\"commit\":\"0123456789abcdef0123456789abcdef01234567\",\"fingerprint\":\"fp-0123\",\"module\":\"nats\",\"repository\":\"mesh-networking\",\"tier\":2}],\"pipeline\":\"main.3589\",\"revision\":12,\"source\":3589,\"v\":1}",
|
||||
decode: func(b []byte) (any, error) { var v PipelineStartedEvent; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-pipeline-runner\\.event\\.pipeline-started\\.[^.*> ]+\\.[^.*> ]+$")},
|
||||
{name: "a pipeline started again at a re-pin, with the three revisions its movers are kept at (H-A-496)", subject: "mesh.seat.mesh-pipeline-runner.event.pipeline-started.main.291", given: "{\"at\":\"2026-11-22T20:00:00Z\",\"branch\":\"main\",\"kept\":[292,295,298],\"movers\":[{\"commit\":\"0123456789abcdef0123456789abcdef01234567\",\"fingerprint\":\"fp-0123\",\"module\":\"nats\",\"repository\":\"mesh-networking\",\"tier\":1}],\"pipeline\":\"main.291\",\"revision\":291,\"source\":114,\"v\":1}", wire: "{\"at\":\"2026-11-22T20:00:00Z\",\"branch\":\"main\",\"kept\":[292,295,298],\"movers\":[{\"commit\":\"0123456789abcdef0123456789abcdef01234567\",\"fingerprint\":\"fp-0123\",\"module\":\"nats\",\"repository\":\"mesh-networking\",\"tier\":1}],\"pipeline\":\"main.291\",\"revision\":291,\"source\":114,\"v\":1}",
|
||||
decode: func(b []byte) (any, error) { var v PipelineStartedEvent; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-pipeline-runner\\.event\\.pipeline-started\\.[^.*> ]+\\.[^.*> ]+$")},
|
||||
{name: "an again pipeline ended passed, with its sequence (H-A-504 addendum)", subject: "mesh.seat.mesh-pipeline-runner.event.pipeline-ended.main.320", given: "{\"branch\":\"main\",\"end-count\":1,\"movers\":[{\"fingerprint\":\"fp-0123\",\"module\":\"node-tools\",\"steps\":[],\"tier\":1,\"version\":\"0.1.115\"}],\"outcome\":\"passed\",\"pipeline\":\"main.320.again.1\",\"revision\":320,\"seq\":269,\"source\":119,\"v\":1}", wire: "{\"branch\":\"main\",\"end-count\":1,\"movers\":[{\"fingerprint\":\"fp-0123\",\"module\":\"node-tools\",\"steps\":[],\"tier\":1,\"version\":\"0.1.115\"}],\"outcome\":\"passed\",\"pipeline\":\"main.320.again.1\",\"revision\":320,\"seq\":269,\"source\":119,\"v\":1}",
|
||||
decode: func(b []byte) (any, error) { var v PipelineEndedEvent; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-pipeline-runner\\.event\\.pipeline-ended\\.[^.*> ]+\\.[^.*> ]+$")},
|
||||
{name: "a pipeline ended passed: per mover its version, steps and tier, an optional step failed", subject: "mesh.seat.mesh-pipeline-runner.event.pipeline-ended.main.3589", given: "{\"branch\":\"main\",\"call\":\"0123456789abcdef\",\"end-count\":1,\"ended\":\"2026-11-10T10:20:00Z\",\"movers\":[{\"commit\":\"0123456789abcdef0123456789abcdef01234567\",\"fingerprint\":\"fp-sdk\",\"module\":\"mesh-sdk\",\"steps\":[{\"module\":\"mesh-sdk\",\"outcome\":\"passed\",\"seat\":\"mesh-wants\",\"status\":\"required\",\"step\":\"validate\"}],\"tier\":1,\"version\":\"0.1.21\",\"widens\":[{\"name\":\"seat:mesh-wants.input\",\"what\":\"grant\"}]},{\"fingerprint\":\"fp-0123\",\"module\":\"nats\",\"steps\":[{\"artifact\":\"nats:program\",\"ask\":\"m2kx9a1b3c4d5e\",\"fingerprint\":\"fp-0123\",\"module\":\"nats\",\"node\":\"anchor\",\"outcome\":\"passed\",\"seat\":\"node-build-go\",\"status\":\"required\",\"step\":\"lint\"},{\"artifact\":\"nats:program\",\"carried-from\":\"main.3588\",\"fingerprint\":\"fp-0123\",\"module\":\"nats\",\"outcome\":\"carried\",\"status\":\"required\",\"step\":\"unit\",\"tests\":{\"unit\":42}},{\"artifact\":\"nats:program\",\"fingerprint\":\"fp-0123\",\"module\":\"nats\",\"node\":\"home-server\",\"outcome\":\"failed\",\"seat\":\"node-build-go\",\"status\":\"optional\",\"step\":\"integration\",\"tests\":{\"integration\":3},\"why\":\"TestTheBusWhole failed\"},{\"module\":\"nats\",\"outcome\":\"passed\",\"seat\":\"mesh-wants\",\"status\":\"required\",\"step\":\"composition\"},{\"module\":\"nats\",\"outcome\":\"bypassed\",\"status\":\"bypass\",\"step\":\"review\"},{\"module\":\"nats\",\"outcome\":\"passed\",\"status\":\"required\",\"step\":\"approval\"}],\"tier\":2,\"version\":\"0.1.15\"}],\"outcome\":\"passed\",\"pipeline\":\"main.3589\",\"revision\":12,\"source\":3589,\"started\":\"2026-11-10T10:00:00Z\",\"v\":1}", wire: "{\"branch\":\"main\",\"call\":\"0123456789abcdef\",\"end-count\":1,\"ended\":\"2026-11-10T10:20:00Z\",\"movers\":[{\"commit\":\"0123456789abcdef0123456789abcdef01234567\",\"fingerprint\":\"fp-sdk\",\"module\":\"mesh-sdk\",\"steps\":[{\"module\":\"mesh-sdk\",\"outcome\":\"passed\",\"seat\":\"mesh-wants\",\"status\":\"required\",\"step\":\"validate\"}],\"tier\":1,\"version\":\"0.1.21\",\"widens\":[{\"name\":\"seat:mesh-wants.input\",\"what\":\"grant\"}]},{\"fingerprint\":\"fp-0123\",\"module\":\"nats\",\"steps\":[{\"artifact\":\"nats:program\",\"ask\":\"m2kx9a1b3c4d5e\",\"fingerprint\":\"fp-0123\",\"module\":\"nats\",\"node\":\"anchor\",\"outcome\":\"passed\",\"seat\":\"node-build-go\",\"status\":\"required\",\"step\":\"lint\"},{\"artifact\":\"nats:program\",\"carried-from\":\"main.3588\",\"fingerprint\":\"fp-0123\",\"module\":\"nats\",\"outcome\":\"carried\",\"status\":\"required\",\"step\":\"unit\",\"tests\":{\"unit\":42}},{\"artifact\":\"nats:program\",\"fingerprint\":\"fp-0123\",\"module\":\"nats\",\"node\":\"home-server\",\"outcome\":\"failed\",\"seat\":\"node-build-go\",\"status\":\"optional\",\"step\":\"integration\",\"tests\":{\"integration\":3},\"why\":\"TestTheBusWhole failed\"},{\"module\":\"nats\",\"outcome\":\"passed\",\"seat\":\"mesh-wants\",\"status\":\"required\",\"step\":\"composition\"},{\"module\":\"nats\",\"outcome\":\"bypassed\",\"status\":\"bypass\",\"step\":\"review\"},{\"module\":\"nats\",\"outcome\":\"passed\",\"status\":\"required\",\"step\":\"approval\"}],\"tier\":2,\"version\":\"0.1.15\"}],\"outcome\":\"passed\",\"pipeline\":\"main.3589\",\"revision\":12,\"source\":3589,\"started\":\"2026-11-10T10:00:00Z\",\"v\":1}",
|
||||
decode: func(b []byte) (any, error) { var v PipelineEndedEvent; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-pipeline-runner\\.event\\.pipeline-ended\\.[^.*> ]+\\.[^.*> ]+$")},
|
||||
{name: "a pipeline of two movers ended with its phases and one mover left unfinished", subject: "mesh.seat.mesh-pipeline-runner.event.pipeline-ended.main.3589", given: "{\"branch\":\"main\",\"call\":\"0123456789abcdef\",\"end-count\":1,\"ended\":\"2026-11-10T10:20:00Z\",\"form\":2,\"movers\":[{\"commit\":\"0123456789abcdef0123456789abcdef01234567\",\"fingerprint\":\"fp-sdk\",\"module\":\"mesh-sdk\",\"steps\":[{\"module\":\"mesh-sdk\",\"outcome\":\"passed\",\"seat\":\"mesh-wants\",\"status\":\"required\",\"step\":\"validate\"}],\"tier\":1,\"version\":\"0.1.21\",\"widens\":[{\"name\":\"seat:mesh-wants.input\",\"what\":\"grant\"}]},{\"fingerprint\":\"fp-0123\",\"module\":\"nats\",\"steps\":[{\"artifact\":\"nats:program\",\"ask\":\"m2kx9a1b3c4d5e\",\"fingerprint\":\"fp-0123\",\"module\":\"nats\",\"node\":\"anchor\",\"outcome\":\"passed\",\"seat\":\"node-build-go\",\"status\":\"required\",\"step\":\"lint\"},{\"artifact\":\"nats:program\",\"carried-from\":\"main.3588\",\"fingerprint\":\"fp-0123\",\"module\":\"nats\",\"outcome\":\"carried\",\"status\":\"required\",\"step\":\"unit\",\"tests\":{\"unit\":42}},{\"artifact\":\"nats:program\",\"fingerprint\":\"fp-0123\",\"module\":\"nats\",\"node\":\"home-server\",\"outcome\":\"failed\",\"seat\":\"node-build-go\",\"status\":\"optional\",\"step\":\"integration\",\"tests\":{\"integration\":3},\"why\":\"TestTheBusWhole failed\"},{\"module\":\"nats\",\"outcome\":\"passed\",\"seat\":\"mesh-wants\",\"status\":\"required\",\"step\":\"composition\"},{\"module\":\"nats\",\"outcome\":\"bypassed\",\"status\":\"bypass\",\"step\":\"review\"},{\"module\":\"nats\",\"outcome\":\"passed\",\"status\":\"required\",\"step\":\"approval\"}],\"tier\":2,\"version\":\"0.1.15\"}],\"outcome\":\"passed\",\"phases\":{\"build\":{\"end\":\"2026-11-21T22:02:00Z\",\"start\":\"2026-11-21T22:00:06Z\"},\"composition\":{\"end\":\"2026-11-21T22:06:00Z\",\"start\":\"2026-11-21T22:04:01Z\"},\"ended\":\"2026-11-21T22:06:00Z\",\"placed\":\"2026-11-21T22:00:05Z\",\"taken\":\"2026-11-21T22:00:00Z\",\"unit\":{\"end\":\"2026-11-21T22:04:00Z\",\"start\":\"2026-11-21T22:02:01Z\"}},\"pipeline\":\"main.3589\",\"revision\":12,\"source\":3589,\"started\":\"2026-11-10T10:00:00Z\",\"unfinished\":[\"mesh-delivery-view\"],\"v\":1}", wire: "{\"branch\":\"main\",\"call\":\"0123456789abcdef\",\"end-count\":1,\"ended\":\"2026-11-10T10:20:00Z\",\"form\":2,\"movers\":[{\"commit\":\"0123456789abcdef0123456789abcdef01234567\",\"fingerprint\":\"fp-sdk\",\"module\":\"mesh-sdk\",\"steps\":[{\"module\":\"mesh-sdk\",\"outcome\":\"passed\",\"seat\":\"mesh-wants\",\"status\":\"required\",\"step\":\"validate\"}],\"tier\":1,\"version\":\"0.1.21\",\"widens\":[{\"name\":\"seat:mesh-wants.input\",\"what\":\"grant\"}]},{\"fingerprint\":\"fp-0123\",\"module\":\"nats\",\"steps\":[{\"artifact\":\"nats:program\",\"ask\":\"m2kx9a1b3c4d5e\",\"fingerprint\":\"fp-0123\",\"module\":\"nats\",\"node\":\"anchor\",\"outcome\":\"passed\",\"seat\":\"node-build-go\",\"status\":\"required\",\"step\":\"lint\"},{\"artifact\":\"nats:program\",\"carried-from\":\"main.3588\",\"fingerprint\":\"fp-0123\",\"module\":\"nats\",\"outcome\":\"carried\",\"status\":\"required\",\"step\":\"unit\",\"tests\":{\"unit\":42}},{\"artifact\":\"nats:program\",\"fingerprint\":\"fp-0123\",\"module\":\"nats\",\"node\":\"home-server\",\"outcome\":\"failed\",\"seat\":\"node-build-go\",\"status\":\"optional\",\"step\":\"integration\",\"tests\":{\"integration\":3},\"why\":\"TestTheBusWhole failed\"},{\"module\":\"nats\",\"outcome\":\"passed\",\"seat\":\"mesh-wants\",\"status\":\"required\",\"step\":\"composition\"},{\"module\":\"nats\",\"outcome\":\"bypassed\",\"status\":\"bypass\",\"step\":\"review\"},{\"module\":\"nats\",\"outcome\":\"passed\",\"status\":\"required\",\"step\":\"approval\"}],\"tier\":2,\"version\":\"0.1.15\"}],\"outcome\":\"passed\",\"phases\":{\"build\":{\"end\":\"2026-11-21T22:02:00Z\",\"start\":\"2026-11-21T22:00:06Z\"},\"composition\":{\"end\":\"2026-11-21T22:06:00Z\",\"start\":\"2026-11-21T22:04:01Z\"},\"ended\":\"2026-11-21T22:06:00Z\",\"placed\":\"2026-11-21T22:00:05Z\",\"taken\":\"2026-11-21T22:00:00Z\",\"unit\":{\"end\":\"2026-11-21T22:04:00Z\",\"start\":\"2026-11-21T22:02:01Z\"}},\"pipeline\":\"main.3589\",\"revision\":12,\"source\":3589,\"started\":\"2026-11-10T10:00:00Z\",\"unfinished\":[\"mesh-delivery-view\"],\"v\":1}",
|
||||
|
||||
@@ -96,6 +96,27 @@
|
||||
"said": "nats:program did not build"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "the build step ended superseded: a newer entry of its branch superseded its fingerprint (H-A-508)",
|
||||
"of": "event:step-ended",
|
||||
"subject": "mesh.seat.mesh-builds.event.step-ended.laptop",
|
||||
"given": {
|
||||
"v": 1,
|
||||
"form": 2,
|
||||
"id": "m2kx9a1b3c4d6c",
|
||||
"pipeline": "main.12.nats",
|
||||
"step": "build",
|
||||
"node": "laptop",
|
||||
"outcome": "superseded",
|
||||
"entries": [
|
||||
{
|
||||
"module": "nats",
|
||||
"fingerprint": "fp-0123"
|
||||
}
|
||||
],
|
||||
"said": "nats at fp-0123 is superseded by fp-0456, the newest entry heard on its first branch"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "an ask taken at the pull",
|
||||
"of": "event:ask-taken",
|
||||
|
||||
@@ -636,13 +636,14 @@
|
||||
"passed",
|
||||
"failed",
|
||||
"nothing to run",
|
||||
"could not run"
|
||||
"could not run",
|
||||
"superseded"
|
||||
],
|
||||
"description": "never passed for a build that built nothing"
|
||||
"description": "never passed for a build that built nothing; superseded for an entry whose fingerprint a newer entry of its branch superseded, built or not (design 47 H2 H-A-508): the mover moved to the newer revision's pipeline, never a failure"
|
||||
},
|
||||
"said": {
|
||||
"type": "string",
|
||||
"description": "why it failed or could not run: the entry not built, the part not heard"
|
||||
"description": "why it failed, could not run or was superseded: the entry not built, the part not heard, the superseding fingerprint"
|
||||
},
|
||||
"rerun": {
|
||||
"type": "boolean"
|
||||
@@ -703,5 +704,6 @@
|
||||
"fingerprint"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"form": 2
|
||||
}
|
||||
|
||||
@@ -29,6 +29,53 @@
|
||||
"at": "2026-11-10T10:00:00Z"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "a pipeline started again at a re-pin, with the three revisions its movers are kept at (H-A-496)",
|
||||
"of": "event:pipeline-started",
|
||||
"subject": "mesh.seat.mesh-pipeline-runner.event.pipeline-started.main.291",
|
||||
"given": {
|
||||
"pipeline": "main.291",
|
||||
"branch": "main",
|
||||
"revision": 291,
|
||||
"source": 114,
|
||||
"v": 1,
|
||||
"movers": [
|
||||
{
|
||||
"module": "nats",
|
||||
"commit": "0123456789abcdef0123456789abcdef01234567",
|
||||
"fingerprint": "fp-0123",
|
||||
"repository": "mesh-networking",
|
||||
"tier": 1
|
||||
}
|
||||
],
|
||||
"kept": [292, 295, 298],
|
||||
"at": "2026-11-22T20:00:00Z"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "an again pipeline ended passed, with its sequence (H-A-504 addendum)",
|
||||
"of": "event:pipeline-ended",
|
||||
"subject": "mesh.seat.mesh-pipeline-runner.event.pipeline-ended.main.320",
|
||||
"given": {
|
||||
"pipeline": "main.320.again.1",
|
||||
"branch": "main",
|
||||
"revision": 320,
|
||||
"seq": 269,
|
||||
"source": 119,
|
||||
"end-count": 1,
|
||||
"v": 1,
|
||||
"outcome": "passed",
|
||||
"movers": [
|
||||
{
|
||||
"module": "node-tools",
|
||||
"fingerprint": "fp-0123",
|
||||
"steps": [],
|
||||
"tier": 1,
|
||||
"version": "0.1.115"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "a pipeline ended passed: per mover its version, steps and tier, an optional step failed",
|
||||
"of": "event:pipeline-ended",
|
||||
|
||||
@@ -1357,7 +1357,7 @@
|
||||
},
|
||||
"seq": {
|
||||
"type": "integer",
|
||||
"description": "for a pipeline written over pipelines-at-once, its place in the queue: the runner's counter queue.next at its write (design 47 H §748)"
|
||||
"description": "its place in the runner's sequence: the runner's counter queue.next at its write, taken for every pipeline it writes, queued or placed at once, so it grows across the pipelines of a branch (design 47 H §748; H2 §813 (1), H-A-504 addendum)"
|
||||
},
|
||||
"end-count": {
|
||||
"type": "integer",
|
||||
@@ -1455,6 +1455,10 @@
|
||||
"type": "integer",
|
||||
"description": "the catalog graph revision of the branch the pipeline runs for"
|
||||
},
|
||||
"seq": {
|
||||
"type": "integer",
|
||||
"description": "the pipeline's sequence, its record's seq: the assigner writes it as the run of the wants the pipeline's pass writes (design 47 H2 §813 (1), H-A-504 addendum)"
|
||||
},
|
||||
"end-count": {
|
||||
"type": "integer",
|
||||
"description": "how often the pipeline has ended: 1 at its first end, one higher at each end again after a passing rerun, so the assigner takes a later end of the same source revision (design 47 G sections 29, 325)"
|
||||
@@ -1675,9 +1679,16 @@
|
||||
"published": {
|
||||
"$ref": "#/defs/Published",
|
||||
"description": "for a pipeline a package's publish started, that publish (A-202)"
|
||||
},
|
||||
"kept": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "integer"
|
||||
},
|
||||
"description": "every catalog revision the pipeline's movers are kept at, said again in full at each re-pin, so the indexer pins each while the pipeline runs (design 47 H2 H-A-496 and its addendum)"
|
||||
}
|
||||
},
|
||||
"description": "a pipeline's start, said at its write, a waiting one's too (design 47 H §746, H-A-52)",
|
||||
"description": "a pipeline's start, said at its write, a waiting one's too (design 47 H §746, H-A-52), and again at a re-pin with its kept revisions (H2 H-A-496)",
|
||||
"required": [
|
||||
"v",
|
||||
"pipeline",
|
||||
@@ -2367,5 +2378,5 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"form": 8
|
||||
"form": 10
|
||||
}
|
||||
|
||||
@@ -104,13 +104,13 @@ export interface StepEnded {
|
||||
"id": string;
|
||||
/** the node the builder ran it on, as in the subject */
|
||||
"node": string;
|
||||
/** never passed for a build that built nothing */
|
||||
"outcome": "passed" | "failed" | "nothing to run" | "could not run";
|
||||
/** never passed for a build that built nothing; superseded for an entry whose fingerprint a newer entry of its branch superseded, built or not (design 47 H2 H-A-508): the mover moved to the newer revision's pipeline, never a failure */
|
||||
"outcome": "passed" | "failed" | "nothing to run" | "could not run" | "superseded";
|
||||
/** the pins the step's entries were built with, each mesh package's version by its module path, the ones the builder took from the registry for a package the entry named with none included; the runner asks the entry's held test steps with them (H-A-207) */
|
||||
"packages"?: Record<string, string>;
|
||||
"pipeline": string;
|
||||
"rerun"?: boolean;
|
||||
/** why it failed or could not run: the entry not built, the part not heard */
|
||||
/** why it failed, could not run or was superseded: the entry not built, the part not heard, the superseding fingerprint */
|
||||
"said"?: string;
|
||||
"started"?: string;
|
||||
"step": "build";
|
||||
|
||||
@@ -306,7 +306,7 @@ export interface Pipeline {
|
||||
"revision"?: number;
|
||||
/** the run on request's id, for a pipeline of a run; such a pipeline delivers nothing */
|
||||
"run"?: string;
|
||||
/** for a pipeline written over pipelines-at-once, its place in the queue: the runner's counter queue.next at its write (design 47 H §748) */
|
||||
/** its place in the runner's sequence: the runner's counter queue.next at its write, taken for every pipeline it writes, queued or placed at once, so it grows across the pipelines of a branch (design 47 H §748; H2 §813 (1), H-A-504 addendum) */
|
||||
"seq"?: number;
|
||||
/** the source revision of the watched branch; the pipeline is keyed by it (ADR 0666 section 9) */
|
||||
"source": number;
|
||||
@@ -417,6 +417,8 @@ export interface PipelineEnded {
|
||||
"revision"?: number;
|
||||
/** the run on request's id, for a pipeline of a run; such a pipeline delivers nothing */
|
||||
"run"?: string;
|
||||
/** the pipeline's sequence, its record's seq: the assigner writes it as the run of the wants the pipeline's pass writes (design 47 H2 §813 (1), H-A-504 addendum) */
|
||||
"seq"?: number;
|
||||
/** the source revision of the watched branch; the pipeline is keyed by it (ADR 0666 section 9) */
|
||||
"source": number;
|
||||
"started"?: string;
|
||||
@@ -446,7 +448,7 @@ export interface PipelineRow {
|
||||
"steps"?: Record<string, number>;
|
||||
}
|
||||
|
||||
/** a pipeline's start, said at its write, a waiting one's too (design 47 H §746, H-A-52) */
|
||||
/** a pipeline's start, said at its write, a waiting one's too (design 47 H §746, H-A-52), and again at a re-pin with its kept revisions (H2 H-A-496) */
|
||||
export interface PipelineStarted {
|
||||
"at"?: string;
|
||||
/** the watched branch, or the branch of a run on request */
|
||||
@@ -455,6 +457,8 @@ export interface PipelineStarted {
|
||||
"call"?: string;
|
||||
/** is the form of what this value carries, left out while it is 1 (design 47 H2 §780). */
|
||||
"form"?: number;
|
||||
/** every catalog revision the pipeline's movers are kept at, said again in full at each re-pin, so the indexer pins each while the pipeline runs (design 47 H2 H-A-496 and its addendum) */
|
||||
"kept"?: number[];
|
||||
/** the pipeline's movers */
|
||||
"movers": Mover[];
|
||||
/** the pipeline's key, <branch>.<revision>, or <branch>.<source>.published.<package>.<version> for a pipeline a publish started; a branch escaped as a key's name is (design 47 H §746, §747) */
|
||||
|
||||
@@ -31,6 +31,7 @@ import (
|
||||
"git.novox.be/novox/mesh-contracts/go/seats/nodeengine"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/gopackageregistry"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdelivery"
|
||||
@@ -800,8 +801,10 @@ func serveAssignerAssignments(t *testing.T, ctx context.Context, js jetstream.Je
|
||||
}
|
||||
if _, err := js.CreateOrUpdateConsumer(ctx, "EVENTS", jetstream.ConsumerConfig{Durable: "n1_mesh-delivery-indexer", AckPolicy: jetstream.AckExplicitPolicy,
|
||||
// and the build seat's step-ended the manifest's consumes names (design 47 G §713: the end of a validation ask), and the
|
||||
// builder's version-reserved, which no stream of its own keeps (design 47 H2 §805).
|
||||
FilterSubjects: []string{"mesh.mod." + assignerHolderModule + ".event.views.>", meshcatalog.SubjectRoom, nodebuildgo.SubjectStepEndedAll, meshbuilds.SubjectVersionReserved}}); err != nil {
|
||||
// builder's version-reserved, which no stream of its own keeps (design 47 H2 §805), and the Go package registry seat's
|
||||
// published, a series' newest a pin names (H-A-495 addendum).
|
||||
FilterSubjects: []string{"mesh.mod." + assignerHolderModule + ".event.views.>", meshcatalog.SubjectRoom, nodebuildgo.SubjectStepEndedAll, meshbuilds.SubjectVersionReserved,
|
||||
gopackageregistry.SubjectPublished}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
em := views.Emitter{Owner: assignerHolderModule, Subject: process.Account{Node: "n1", Module: assignerHolderModule}.EventSubject,
|
||||
|
||||
@@ -664,7 +664,8 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
sources.refresh()
|
||||
})
|
||||
// The held take-ins are taken in again from the state held at the start, before a branch's consumer gives a later one
|
||||
// (design 47 H, H-A-114, H-A-118).
|
||||
// (design 47 H, H-A-114, H-A-118); a chain's key a stop left is deleted first (H2 H-A-497 addendum).
|
||||
ix.EndChains(ctx)
|
||||
sources.takeAgain()
|
||||
sources.refresh()
|
||||
if stopped != nil {
|
||||
|
||||
+76
-12
@@ -19,9 +19,11 @@ import (
|
||||
"github.com/nats-io/nats.go/jetstream"
|
||||
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/gopackageregistry"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdelivery"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildgo"
|
||||
|
||||
"mesh-delivery-indexer/internal/index"
|
||||
@@ -76,10 +78,11 @@ func untilModule(t *testing.T, ctx context.Context, js jetstream.JetStream, name
|
||||
// of lib-a and one of lib-b, and so their trees alone, moves lib-a, lib-b and their importers alone, never the other 32
|
||||
// modules whose repository's commit moved too.
|
||||
//
|
||||
// Design 47 H2 §805 (H-A-453 (3)): the builder's twenty version-reserved of mesh-sdk in that revision's pipeline (twenty
|
||||
// artifacts of its Go package, as repin_test.go reads them) are kept in heard and gathered, and its pipeline-started keeps one
|
||||
// re-pin revision of main, importer its mover pinned to the reserved version; the next pipeline's reservation keeps the
|
||||
// revision after it, so none came between.
|
||||
// Design 47 H2 §805 (H-A-453 (3)) and H-A-495 with its addendum: the builder's twenty version-reserved of mesh-sdk in that
|
||||
// revision's pipeline (twenty artifacts of its Go package, as repin_test.go reads them) are kept in heard and gathered, and
|
||||
// they and its pipeline-started move no pin: a pin names only a published version. The release of the reserved version (the
|
||||
// Go package registry seat's published and every artifact's package-published) keeps one re-pin revision of main, importer
|
||||
// its mover pinned to it; the next pipeline's reservation keeps none, so the revision after it is the next release's.
|
||||
func TestASourceRevisionMovingMeshSDKNamesItAndItsImporters(t *testing.T) {
|
||||
const (
|
||||
sdkGo = "git.novox.be/novox/mesh-sdk/go"
|
||||
@@ -143,6 +146,24 @@ func TestASourceRevisionMovingMeshSDKNamesItAndItsImporters(t *testing.T) {
|
||||
if heardKV, err = js.CreateKeyValue(ctx, jetstream.KeyValueConfig{Bucket: index.Bucket(testIndexer, index.HeardState), History: 64, LimitMarkerTTL: time.Minute}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// package-published on its kept stream with the indexer's durable, as the grants part makes them, and the state versions
|
||||
// a release is recorded in (H-A-495: the release re-pins).
|
||||
if _, err := js.CreateKeyValue(ctx, jetstream.KeyValueConfig{Bucket: index.Bucket(testIndexer, index.VersionsState), History: 1}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := js.CreateStream(ctx, jetstream.StreamConfig{Name: meshbuilds.StreamPackagePublished, Subjects: []string{meshbuilds.SubjectPackagePublished}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := js.CreateOrUpdateConsumer(ctx, meshbuilds.StreamPackagePublished, jetstream.ConsumerConfig{Durable: "n1_mesh-delivery-indexer", AckPolicy: jetstream.AckExplicitPolicy,
|
||||
MaxDeliver: EventDeliveries}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// The indexer's durable on pipeline-started samples every acknowledgement, so the bed hears that the settle a
|
||||
// pipeline-started makes (H-A-424 (1)) has ended before it releases, never by sleeping.
|
||||
if _, err := js.CreateOrUpdateConsumer(ctx, meshpipelinerunner.StreamPipelineStarted, jetstream.ConsumerConfig{Durable: "n1_mesh-delivery-indexer",
|
||||
AckPolicy: jetstream.AckExplicitPolicy, FilterSubjects: []string{meshpipelinerunner.SubjectPipelineStartedAll}, SampleFrequency: "100%"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// A dry run's key left by an indexer that stopped mid-run (§804).
|
||||
if dryRuns, err = js.KeyValue(ctx, index.Bucket(testIndexer, index.DryRunsState)); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -260,8 +281,9 @@ func TestASourceRevisionMovingMeshSDKNamesItAndItsImporters(t *testing.T) {
|
||||
t.Errorf("the catalogue's commit changing lib-a's and lib-b's tests moves %v of its 36 modules, want lib-a, lib-b and their importers alone", movers)
|
||||
}
|
||||
|
||||
// §805: twenty reservations of mesh-sdk's packages in main's revision of source 12, kept and gathered; its pipeline-started
|
||||
// keeps one re-pin revision of main, and the next pipeline's reservation the one after it.
|
||||
// §805, H-A-495: twenty reservations of mesh-sdk's packages in main's revision of source 12, kept and gathered, and its
|
||||
// pipeline-started move no pin; the release of the reserved version keeps one re-pin revision of main, and the next
|
||||
// pipeline's reservation none, so the revision after it is the next release's.
|
||||
objects := newBusObjects(js, testAccount, index.CatalogRevisionsObjects)
|
||||
untilRevision := func(n int64) meshcatalog.CatalogRevision {
|
||||
t.Helper()
|
||||
@@ -299,19 +321,61 @@ func TestASourceRevisionMovingMeshSDKNamesItAndItsImporters(t *testing.T) {
|
||||
return v != nil && json.Unmarshal(v, &r) == nil && len(r.Reservations) == artifacts
|
||||
})
|
||||
}
|
||||
// release publishes mesh-sdk's Go package at version, as the registry seat says it (the series' newest a pin names,
|
||||
// H-A-495 addendum), and every artifact of mesh-sdk's entry in main's revision n, as the builder says them.
|
||||
release := func(n int64, version string) {
|
||||
t.Helper()
|
||||
raw, _ := json.Marshal(gopackageregistry.PublishedEvent{Kind: "package", Name: sdkGo, Module: sdkGo, Version: version, Commit: m2, Digest: "sha256:" + version})
|
||||
if _, err := js.Publish(ctx, gopackageregistry.SubjectPublished, raw); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, entries, err := index.ReadRevision(ctx, objects, index.BranchObject("main", n))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
i := slices.IndexFunc(entries, func(e meshcatalog.CatalogEntry) bool { return e.Module == "mesh-sdk" })
|
||||
if i < 0 {
|
||||
t.Fatalf("main.%d holds no entry of mesh-sdk", n)
|
||||
}
|
||||
for _, a := range entries[i].Artifacts {
|
||||
raw, _ := json.Marshal(meshbuilds.PackagePublished{Module: "mesh-sdk", Artifact: a.Ref, Digest: "sha256:" + a.Ref + version, Version: version, Source: 12, Branch: "main"})
|
||||
if _, err := js.Publish(ctx, meshbuilds.SubjectPackagePublished, raw); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
// started says pipeline-started of main's revision n and waits for the indexer's acknowledgement of it, which follows its settle.
|
||||
started := func(n int64) {
|
||||
t.Helper()
|
||||
acks, err := js.Conn().SubscribeSync("$JS.EVENT.METRIC.CONSUMER.ACK." + meshpipelinerunner.StreamPipelineStarted + ".n1_mesh-delivery-indexer")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer func() { _ = acks.Unsubscribe() }()
|
||||
if err := js.Conn().Flush(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
sayPipeline(t, ctx, js, false, "main", n)
|
||||
if _, err := acks.NextMsg(waitBound); err != nil {
|
||||
t.Fatalf("the pipeline-started of main.%d is not acknowledged after %s: %v", n, waitBound, err)
|
||||
}
|
||||
}
|
||||
r := taken.Revision
|
||||
reserve(r, "0.1.28", 20)
|
||||
sayPipeline(t, ctx, js, false, "main", r)
|
||||
if rev := untilRevision(r + 1); rev.CallKind != meshcatalog.CatalogRevisionCallKindRelease || !strings.Contains(rev.Call, index.BranchObject("main", r)+"'s") ||
|
||||
started(r)
|
||||
release(r, "0.1.28")
|
||||
if rev := untilRevision(r + 1); rev.CallKind != meshcatalog.CatalogRevisionCallKindRelease || rev.Call != index.ReleaseCall("mesh-sdk", "0.1.28") ||
|
||||
len(rev.Movers) != 1 || rev.Movers[0].Module != "importer" {
|
||||
t.Errorf("main.%d = %+v, want one re-pin revision of the twenty reservations, importer its mover", r+1, rev)
|
||||
t.Errorf("main.%d = %+v, want the re-pin revision of the release of mesh-sdk 0.1.28, importer its mover: twenty reservations move no pin", r+1, rev)
|
||||
}
|
||||
untilModule(t, ctx, js, "importer", func(m meshcatalog.ModulesByModuleValue) bool { return m.Packages[sdkGo] == "v0.1.28" })
|
||||
reserve(r+1, "0.1.29", 1)
|
||||
sayPipeline(t, ctx, js, false, "main", r+1)
|
||||
if rev := untilRevision(r + 2); !strings.Contains(rev.Call, index.BranchObject("main", r+1)+"'s") {
|
||||
t.Errorf("main.%d = %+v, want the next pipeline's re-pin: the twenty reservations kept more than one revision", r+2, rev)
|
||||
started(r + 1)
|
||||
release(r+1, "0.1.29")
|
||||
if rev := untilRevision(r + 2); rev.Call != index.ReleaseCall("mesh-sdk", "0.1.29") {
|
||||
t.Errorf("main.%d = %+v, want the re-pin of the release of mesh-sdk 0.1.29: the reservation of 0.1.29 keeps no revision", r+2, rev)
|
||||
}
|
||||
untilModule(t, ctx, js, "importer", func(m meshcatalog.ModulesByModuleValue) bool { return m.Packages[sdkGo] == "v0.1.29" })
|
||||
|
||||
// A branch's take-in moving mesh-sdk to m3 is a dry run: its packages stay in dry-runs while it runs, the trunk's are
|
||||
// untouched, and its keys go once it answered (§804).
|
||||
|
||||
@@ -265,24 +265,34 @@ type actor struct {
|
||||
s *sourceMoved
|
||||
}
|
||||
|
||||
// HeldAgain takes a branch's held source revisions in again now (indexer_take_in_pending).
|
||||
// HeldAgain takes a branch's held source revisions in again now (indexer_take_in_pending), beside the asks' loop, and answers
|
||||
// at once (design 47 H2 H-A-497 and its addendum): a chain that runs already answers its state from the state takeins; held
|
||||
// sources start the chain at the first, written there before it runs, answered with how many wait.
|
||||
func (a actor) HeldAgain(ctx context.Context, branch string) index.TakenIn {
|
||||
r := index.TakenIn{Module: branch}
|
||||
if hs, err := a.HeldOf(ctx, branch); err != nil || len(hs) == 0 {
|
||||
if c, running, err := a.ChainOf(ctx, branch); err != nil {
|
||||
r.Answer = "the state takeins is not read: " + err.Error()
|
||||
return r
|
||||
} else if running {
|
||||
r.Held = true
|
||||
r.Answer = fmt.Sprintf("a chain runs: source %d taken in since %s, %d wait", c.Source, c.Since.Format(time.RFC3339), c.Waiting)
|
||||
return r
|
||||
}
|
||||
hs, err := a.HeldOf(ctx, branch)
|
||||
if err != nil || len(hs) == 0 {
|
||||
r.Answer = "the branch " + branch + " holds no source-moved"
|
||||
if err != nil {
|
||||
r.Answer = "the state held is not read: " + err.Error()
|
||||
}
|
||||
return r
|
||||
}
|
||||
a.s.takeAgain()
|
||||
hs, err := a.HeldOf(ctx, branch)
|
||||
still := err != nil || len(hs) > 0
|
||||
r.Stored, r.Held = !still, still
|
||||
r.Answer = "taken in"
|
||||
if still {
|
||||
r.Answer = "still held: indexer_pending says why"
|
||||
}
|
||||
c := a.StartChain(ctx, hs)
|
||||
go func() {
|
||||
a.s.takeAgain()
|
||||
a.EndChain(a.s.ctx, branch)
|
||||
}()
|
||||
r.Held = true
|
||||
r.Answer = fmt.Sprintf("chain started at source %d, %d wait", c.Source, c.Waiting)
|
||||
return r
|
||||
}
|
||||
|
||||
|
||||
@@ -97,6 +97,98 @@ func TestAHeldSourceMovedIsSkippedByHand(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// chainStore is a takeins state in memory, safe beside the chain's own goroutine, which says on ended when a chain key goes.
|
||||
type chainStore struct {
|
||||
mu sync.Mutex
|
||||
vals map[string][]byte
|
||||
ended chan string
|
||||
}
|
||||
|
||||
func (c *chainStore) Get(_ context.Context, k string) ([]byte, uint64, bool, error) {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
v, ok := c.vals[k]
|
||||
return v, 1, ok, nil
|
||||
}
|
||||
func (c *chainStore) Keys(context.Context) ([]string, error) {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
var out []string
|
||||
for k := range c.vals {
|
||||
out = append(out, k)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
func (c *chainStore) Create(_ context.Context, k string, v []byte) error {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
c.vals[k] = v
|
||||
return nil
|
||||
}
|
||||
func (c *chainStore) Update(ctx context.Context, k string, v []byte, _ uint64) error {
|
||||
return c.Create(ctx, k, v)
|
||||
}
|
||||
func (c *chainStore) Delete(_ context.Context, k string, _ uint64) error {
|
||||
c.mu.Lock()
|
||||
_, had := c.vals[k]
|
||||
delete(c.vals, k)
|
||||
c.mu.Unlock()
|
||||
if had && strings.HasPrefix(k, index.ChainPrefix) {
|
||||
c.ended <- k
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Design 47 H2 H-A-497 and its addendum: a hand ask of a branch with held sources starts the chain beside the asks' loop
|
||||
// and answers at once; an ask that meets the running chain answers its state, which the state takeins holds and
|
||||
// indexer_pending shows; the chain's key goes at its end.
|
||||
func TestAHandAskOfAHeldBranchAnswersAtOnce(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
held := &memStore{vals: map[string][]byte{}}
|
||||
takeIns := &chainStore{vals: map[string][]byte{}, ended: make(chan string, 4)}
|
||||
ix := &index.Indexer{Held: held, TakeIns: takeIns, Logf: func(string, ...any) {},
|
||||
Now: func() time.Time { return time.Date(2026, 11, 22, 21, 7, 0, 0, time.UTC) }}
|
||||
handlers := map[string]func(jetstream.Msg){}
|
||||
s := &sourceMoved{ctx: ctx, ix: ix,
|
||||
branches: func(context.Context) ([]string, error) { return []string{"main"}, nil },
|
||||
bind: func(_ context.Context, branch string, each func(jetstream.Msg)) (func(), error) {
|
||||
handlers[branch] = each
|
||||
return func() {}, nil
|
||||
},
|
||||
logf: func(string, ...any) {}}
|
||||
s.refresh()
|
||||
for _, n := range []int{114, 115, 116} {
|
||||
m := &fakeMsg{subject: fmt.Sprintf("mesh.seat.mesh-delivery.event.source-moved.main.%d", n),
|
||||
data: []byte(fmt.Sprintf(`{"v":1,"branch":"main","source":%d,"call":"%d123456789abcde","heads":[]}`, n, n))}
|
||||
handlers["main"](msgOf{f: m})
|
||||
}
|
||||
a := actor{ix, s}
|
||||
s.again.Lock() // the chain waits for the lock, so it is still running at the second ask
|
||||
if r := a.HeldAgain(ctx, "main"); r.Answer != "chain started at source 114, 2 wait" {
|
||||
s.again.Unlock()
|
||||
t.Fatalf("the first ask answered %+v, want the chain started at once", r)
|
||||
}
|
||||
r := a.HeldAgain(ctx, "main")
|
||||
var pending any
|
||||
var err error
|
||||
for _, tool := range index.HeldTools(held, takeIns, nil, ix.Now, nil) {
|
||||
if tool.Name == index.PendingTool {
|
||||
pending, err = tool.Run(map[string]any{})
|
||||
}
|
||||
}
|
||||
s.again.Unlock()
|
||||
chains := pending.(index.PendingAnswer).Chains
|
||||
if r.Answer != "a chain runs: source 114 taken in since 2026-11-22T21:07:00Z, 2 wait" || !r.Held {
|
||||
t.Errorf("the ask meeting the chain answered %+v, want its state at once", r)
|
||||
}
|
||||
if err != nil || len(chains) != 1 || chains[0].Branch != "main" || chains[0].Source != 114 || chains[0].Waiting != 2 {
|
||||
t.Errorf("indexer_pending shows chains %+v (%v), want main's at 114 with 2 waiting", chains, err)
|
||||
}
|
||||
if k := <-takeIns.ended; k != index.ChainKey("main") {
|
||||
t.Errorf("the key %s went, want main's chain", k)
|
||||
}
|
||||
}
|
||||
|
||||
// revisionObjects is the catalog revisions' object bucket in memory.
|
||||
type revisionObjects map[string][]byte
|
||||
|
||||
|
||||
@@ -33,8 +33,8 @@ type takerIn interface {
|
||||
// written back, by compare-and-set at its revision, with what the indexer stored or why not. A value
|
||||
// answered already (this indexer's own write) or deleted is left.
|
||||
func takenIn(ctx context.Context, ix takerIn, kv jetstream.KeyValue, e jetstream.KeyValueEntry, logf func(string, ...any)) {
|
||||
if e.Operation() != jetstream.KeyValuePut || strings.HasPrefix(e.Key(), index.RunningPrefix) {
|
||||
return // a running take-in's waiting-on is the indexer's own record, no ask (H-A-409)
|
||||
if e.Operation() != jetstream.KeyValuePut || strings.HasPrefix(e.Key(), index.RunningPrefix) || strings.HasPrefix(e.Key(), index.ChainPrefix) {
|
||||
return // a running take-in's waiting-on and a running chain are the indexer's own records, no ask (H-A-409, H-A-497)
|
||||
}
|
||||
a, err := index.DecodeTakeIn(e.Value())
|
||||
if err != nil {
|
||||
|
||||
@@ -51,6 +51,9 @@ type PendingAnswer struct {
|
||||
Held []HeldTakeIn `json:"held"`
|
||||
// Running are the take-ins that run, each with what it waits on (design 47 H2 §803, H-A-409).
|
||||
Running []RunningTakeIn `json:"running,omitempty"`
|
||||
// Chains are the running chains of held take-ins, each branch's source being taken in, since when and how many wait
|
||||
// (H-A-497 addendum).
|
||||
Chains []HeldChain `json:"chains,omitempty"`
|
||||
}
|
||||
|
||||
// ErrHeldUnwritten says a source-moved that could not be taken in is not written into the state held either: its message
|
||||
@@ -167,26 +170,153 @@ func (ix *Indexer) unhold(ctx context.Context, branch string, source int64) {
|
||||
}
|
||||
}
|
||||
|
||||
// TakeHeldIn takes every branch's held source revisions in, each branch in its order, on the indexer's own room and at its
|
||||
// start (H-A-114, H-A-118): a branch stops at the first that still cannot be taken in, which stays held with those behind it.
|
||||
// TakeHeldIn takes every branch's held source revisions in, each branch in its order, on the indexer's own room, at its
|
||||
// start and by hand (H-A-114, H-A-118): a branch stops at the first that still cannot be taken in, which stays held with those
|
||||
// behind it. Once a held one is taken in, the next held of its branch is taken in at once, each such start said in the journal
|
||||
// (design 47 H2 H-A-497).
|
||||
func (ix *Indexer) TakeHeldIn(ctx context.Context) {
|
||||
all, err := ReadHeld(ctx, ix.Held)
|
||||
if err != nil {
|
||||
ix.logf("take-in: the state %s is not read, so no held take-in is taken in again now: %v", HeldState, err)
|
||||
return
|
||||
}
|
||||
stopped := map[string]bool{}
|
||||
stopped, landed := map[string]bool{}, map[string]int64{}
|
||||
behind := map[string]int{}
|
||||
for _, h := range all {
|
||||
behind[h.Branch]++
|
||||
}
|
||||
for i, h := range all {
|
||||
behind[h.Branch]--
|
||||
if stopped[h.Branch] {
|
||||
continue
|
||||
}
|
||||
if _, err := ix.TakeInSource(ctx, h.Event()); err != nil {
|
||||
if prev, ok := landed[h.Branch]; ok {
|
||||
ix.logf("take-in: held source %d of %s taken in next, after %d (H-A-497)", h.Source, h.Branch, prev)
|
||||
}
|
||||
ix.writeChain(ctx, HeldChain{Branch: h.Branch, Source: h.Source, Since: ix.now().UTC(), Waiting: behind[h.Branch]})
|
||||
if _, err := ix.TakeInSource(ctx, h.Event()); err == nil {
|
||||
landed[h.Branch] = h.Source
|
||||
} else {
|
||||
ix.logf("take-in: source revision %d of %s is still held: %v", h.Source, h.Branch, err)
|
||||
stopped[h.Branch] = true
|
||||
}
|
||||
// The chain of a branch ends at its first held again or its last held (H-A-497 addendum).
|
||||
if stopped[h.Branch] || !slices.ContainsFunc(all[i+1:], func(n HeldTakeIn) bool { return n.Branch == h.Branch }) {
|
||||
ix.endChain(ctx, h.Branch)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ChainPrefix is the takeins keys of the chains of held take-ins: `chain.<branch>`, the branch escaped as a key's name is,
|
||||
// holding the branch's chain while it runs (design 47 H2 H-A-497 and its addendum): written at each step, deleted at its end.
|
||||
const ChainPrefix = "chain."
|
||||
|
||||
// ChainKey is the takeins key of branch's chain.
|
||||
func ChainKey(branch string) string { return ChainPrefix + keys.EscapeName(branch) }
|
||||
|
||||
// HeldChain is a running chain of a branch's held take-ins (H-A-497 addendum): the source being taken in, since when, and
|
||||
// how many held sources of the branch wait behind it.
|
||||
type HeldChain struct {
|
||||
Branch string `json:"branch"`
|
||||
Source int64 `json:"source"`
|
||||
Since time.Time `json:"since"`
|
||||
Waiting int `json:"waiting"`
|
||||
}
|
||||
|
||||
// writeChain writes branch's chain at its step c into the state takeins; a failed write is said.
|
||||
func (ix *Indexer) writeChain(ctx context.Context, c HeldChain) {
|
||||
if ix.TakeIns == nil {
|
||||
return
|
||||
}
|
||||
data, err := json.Marshal(c)
|
||||
if err == nil {
|
||||
err = write(ctx, ix.TakeIns, ChainKey(c.Branch), func([]byte, bool) ([]byte, bool, error) { return data, false, nil })
|
||||
}
|
||||
if err != nil {
|
||||
ix.logf("take-in: the chain of %s at source revision %d is not written into %s: %v", c.Branch, c.Source, TakeInsState, err)
|
||||
}
|
||||
}
|
||||
|
||||
// EndChain deletes branch's chain from the state takeins once the take-in its ask started returned, so a chain whose held
|
||||
// sources another act took first is never left running.
|
||||
func (ix *Indexer) EndChain(ctx context.Context, branch string) { ix.endChain(ctx, branch) }
|
||||
|
||||
// EndChains deletes every chain the state takeins holds, at the indexer's start (H-A-497 addendum): no chain runs before the
|
||||
// start's take-in, so a key left by a stop between a chain's last take-in and its end would answer "a chain runs" for good.
|
||||
func (ix *Indexer) EndChains(ctx context.Context) {
|
||||
chains, err := ReadChains(ctx, ix.TakeIns)
|
||||
if err != nil {
|
||||
ix.logf("take-in: the chains in %s are not read, so none left by a stop is deleted: %v", TakeInsState, err)
|
||||
return
|
||||
}
|
||||
for _, c := range chains {
|
||||
ix.logf("take-in: the chain of %s at source revision %d, left by a stop, is deleted at the start", c.Branch, c.Source)
|
||||
ix.endChain(ctx, c.Branch)
|
||||
}
|
||||
}
|
||||
|
||||
// endChain deletes branch's chain from the state takeins.
|
||||
func (ix *Indexer) endChain(ctx context.Context, branch string) {
|
||||
if ix.TakeIns == nil {
|
||||
return
|
||||
}
|
||||
if err := write(ctx, ix.TakeIns, ChainKey(branch), func([]byte, bool) ([]byte, bool, error) { return nil, true, nil }); err != nil {
|
||||
ix.logf("take-in: the chain of %s is not deleted from %s: %v", branch, TakeInsState, err)
|
||||
}
|
||||
}
|
||||
|
||||
// StartChain writes branch's chain at its first held source, before the chain is taken in beside the asks (H-A-497
|
||||
// addendum), so an ask after it finds it running; it answers that chain.
|
||||
func (ix *Indexer) StartChain(ctx context.Context, held []HeldTakeIn) HeldChain {
|
||||
c := HeldChain{Branch: held[0].Branch, Source: held[0].Source, Since: ix.now().UTC(), Waiting: len(held) - 1}
|
||||
ix.writeChain(ctx, c)
|
||||
return c
|
||||
}
|
||||
|
||||
// ChainOf is branch's running chain in the state takeins, and whether one runs.
|
||||
func (ix *Indexer) ChainOf(ctx context.Context, branch string) (HeldChain, bool, error) {
|
||||
if ix.TakeIns == nil {
|
||||
return HeldChain{}, false, nil
|
||||
}
|
||||
v, _, found, err := ix.TakeIns.Get(ctx, ChainKey(branch))
|
||||
if err != nil || !found {
|
||||
return HeldChain{}, false, err
|
||||
}
|
||||
var c HeldChain
|
||||
if err := json.Unmarshal(v, &c); err != nil {
|
||||
return HeldChain{}, false, fmt.Errorf("%s.%s: %w", TakeInsState, ChainKey(branch), err)
|
||||
}
|
||||
return c, true, nil
|
||||
}
|
||||
|
||||
// ReadChains are the running chains the state takeins holds (H-A-497 addendum), each branch's once.
|
||||
func ReadChains(ctx context.Context, st Store) ([]HeldChain, error) {
|
||||
if st == nil {
|
||||
return nil, nil
|
||||
}
|
||||
ks, err := st.Keys(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
slices.Sort(ks)
|
||||
var out []HeldChain
|
||||
for _, k := range ks {
|
||||
if !strings.HasPrefix(k, ChainPrefix) {
|
||||
continue
|
||||
}
|
||||
v, _, found, err := st.Get(ctx, k)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var c HeldChain
|
||||
if !found || json.Unmarshal(v, &c) != nil {
|
||||
continue
|
||||
}
|
||||
out = append(out, c)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// SkipTakeIn ends a held source revision unwritten by hand (indexer_take_in_skip, §744): it says take-in.taken with no entries,
|
||||
// skipped, by and why, and deletes the branch's held take-in; the caller acknowledges the source-moved.
|
||||
func (ix *Indexer) SkipTakeIn(ctx context.Context, e meshdelivery.SourceMovedEvent, by, why string) error {
|
||||
@@ -236,7 +366,7 @@ func HeldTools(held, takeIns Store, ask func(key string, value []byte) (TakeInAs
|
||||
{Name: PendingTool,
|
||||
Description: "Each watched branch's held take-in (design 47 H §744): the source revision of the gate's source-moved the indexer " +
|
||||
"could not take in (the catalog store full, a read of the forge unanswered), why and since when, in order, each kept here once " +
|
||||
"acknowledged and taken in again on the indexer's room and at its start; and each running take-in that waits over a minute on another part, its waiting-on (part, verb, since). indexer_take_in_pending takes it again now, indexer_take_in_skip ends it unwritten.",
|
||||
"acknowledged and taken in again on the indexer's room and at its start; each running take-in that waits over a minute on another part, its waiting-on (part, verb, since); and each running chain of held take-ins, the source being taken in, since when and how many wait. indexer_take_in_pending takes it again now, indexer_take_in_skip ends it unwritten.",
|
||||
Input: map[string]any{"type": "object", "properties": map[string]any{}},
|
||||
Run: func(map[string]any) (any, error) {
|
||||
h, err := ReadHeld(context.Background(), held)
|
||||
@@ -244,11 +374,16 @@ func HeldTools(held, takeIns Store, ask func(key string, value []byte) (TakeInAs
|
||||
return PendingAnswer{Held: h}, err
|
||||
}
|
||||
r, err := ReadRunning(context.Background(), takeIns)
|
||||
return PendingAnswer{Held: h, Running: r}, err
|
||||
if err != nil {
|
||||
return PendingAnswer{Held: h, Running: r}, err
|
||||
}
|
||||
c, err := ReadChains(context.Background(), takeIns)
|
||||
return PendingAnswer{Held: h, Running: r, Chains: c}, err
|
||||
}},
|
||||
{Name: TakeInPendingTool,
|
||||
Description: "Take a watched branch's held source-moved in again now (design 47 H §744), as the indexer's room would: " +
|
||||
"answers whether it was taken in. indexer_pending names the held branches.",
|
||||
"the held sources are taken in in order beside the asks, and it answers at once that the chain started at a source and " +
|
||||
"how many wait, or, while a chain runs, its state (design 47 H2 H-A-497). indexer_pending names the held branches and the running chains.",
|
||||
Input: map[string]any{"type": "object", "required": []string{"branch"}, "properties": map[string]any{
|
||||
"branch": map[string]any{"type": "string", "description": "the watched branch, as indexer_pending names it"},
|
||||
"why": map[string]any{"type": "string", "description": "why it is taken again now"}}},
|
||||
|
||||
@@ -73,8 +73,8 @@ func pinObject(key string) (string, bool) {
|
||||
}
|
||||
|
||||
// HeardPins applies one event of the seat mesh-pipeline-runner the indexer's durable consumers gave it (design 47 H §749): a
|
||||
// pipeline-started pins the revision it names under the record `pipeline.<pipeline>`, its pipeline-ended frees it and every
|
||||
// other revision the record pins (H-A-147). A body
|
||||
// pipeline-started pins the revision it names, and each revision its movers are kept at (design 47 H2 H-A-496), under the
|
||||
// record `pipeline.<pipeline>`, its pipeline-ended frees it and every other revision the record pins (H-A-147). A body
|
||||
// that is no such event, or names no revision, changes nothing; an error leaves the event unacknowledged, so the bus gives it
|
||||
// again; one applied twice changes nothing.
|
||||
func (ix *Indexer) HeardPins(ctx context.Context, started *runner.PipelineStarted, ended *runner.PipelineEnded) error {
|
||||
@@ -83,7 +83,15 @@ func (ix *Indexer) HeardPins(ctx context.Context, started *runner.PipelineStarte
|
||||
}
|
||||
switch {
|
||||
case started != nil && started.Revision > 0 && started.Pipeline != "":
|
||||
if err := ix.pin(ctx, PinKey(started.Branch, started.Revision), PipelineRecord(started.Pipeline)); err != nil {
|
||||
record := PipelineRecord(started.Pipeline)
|
||||
if err := ix.pin(ctx, PinKey(started.Branch, started.Revision), record); err != nil {
|
||||
return err
|
||||
}
|
||||
// Every revision the pipeline's movers are kept at is pinned under its record too, so no judge removes one it still
|
||||
// reads (design 47 H2 H-A-496); the latest started's kept set is the pipeline's kept pins, so a kept revision the
|
||||
// record pins that this started no longer names is freed (H-A-496 addendum). A kept revision is always newer than the
|
||||
// pipeline's own (a re-pin of its own source, H-A-283), so its own revision and its validate base stay pinned.
|
||||
if err := ix.pinKept(ctx, started.Branch, started.Revision, started.Kept, record); err != nil {
|
||||
return err
|
||||
}
|
||||
// The reservations of the pipeline's revision settle at its start, if they gather (design 47 H2 §805, H-A-424 (1)).
|
||||
@@ -229,6 +237,41 @@ func (ix *Indexer) unpinElsewhere(ctx context.Context, record string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// pinKept pins each of kept, the revisions a pipeline of branch at revision own keeps movers at, under record, and frees
|
||||
// every revision newer than own the record pins that kept does not name (design 47 H2 H-A-496 and its addendum).
|
||||
func (ix *Indexer) pinKept(ctx context.Context, branch string, own int64, kept []int64, record string) error {
|
||||
for _, r := range kept {
|
||||
if r <= 0 || r == own {
|
||||
continue
|
||||
}
|
||||
if err := ix.pin(ctx, PinKey(branch, r), record); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
pinKeys, err := ix.Pins.Keys(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, k := range pinKeys {
|
||||
b, r, ok := ParsePinKey(k)
|
||||
if !ok || b != branch || r <= own || slices.Contains(kept, r) {
|
||||
continue
|
||||
}
|
||||
v, _, found, err := ix.Pins.Get(ctx, k)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var pv PinValue
|
||||
if !found || json.Unmarshal(v, &pv) != nil || !slices.Contains(pv.Records, record) {
|
||||
continue
|
||||
}
|
||||
if err := ix.unpin(ctx, k, record); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// PipelineRecord is the record a pipeline pins its revision under: `pipeline.<branch>.<source>` (design 47 H §743, A-449a).
|
||||
func PipelineRecord(pipeline string) string { return "pipeline." + pipeline }
|
||||
|
||||
|
||||
@@ -13,6 +13,47 @@ import (
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||
)
|
||||
|
||||
// Design 47 H2 H-A-496 and its addendum: a pipeline-started pins the pipeline's own revision and each revision its movers
|
||||
// are kept at under the pipeline's record; a later started (said again at a re-pin) is the pipeline's kept set, freeing a
|
||||
// kept revision it no longer names but never the pipeline's own; pipeline-ended frees them all.
|
||||
func TestAPipelinesKeptRevisionsArePinnedUntilItEnds(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
pending := uint64(1) // the keeps judge nothing while the consumer is behind
|
||||
ix := &Indexer{Module: testSelf, Revisions: newMemObjects(1 << 20), Pins: newMem(), Findings: newFindings(),
|
||||
Now: func() time.Time { return time.Date(2026, 11, 22, 20, 0, 0, 0, time.UTC) }, PinsPending: func(context.Context) (uint64, error) { return pending, nil }}
|
||||
kept := func() []string {
|
||||
n, _ := ix.Revisions.Names(ctx)
|
||||
return slices.DeleteFunc(n, func(s string) bool { _, _, ok := RevisionGroup(s); return !ok })
|
||||
}
|
||||
reader := meshcatalog.CatalogEntry{Module: "reader", Repository: "novox/r", Manifest: map[string]any{}}
|
||||
for source := int64(1); source <= 6; source++ {
|
||||
e := reader
|
||||
e.Commit = fmt.Sprintf("c%d", source)
|
||||
if err := ix.KeepBranchEntries(ctx, "main", source, map[string]meshcatalog.CatalogEntry{"reader": e}, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
pending = 0
|
||||
heard := func(started *runner.PipelineStarted, ended *runner.PipelineEnded, want ...string) {
|
||||
t.Helper()
|
||||
if err := ix.HeardPins(ctx, started, ended); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ix.JudgePins(ctx)
|
||||
if got := kept(); !slices.Equal(got, want) {
|
||||
t.Errorf("kept %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
heard(&runner.PipelineStarted{Branch: "main", Pipeline: "main.1", Revision: 1, Kept: []int64{2, 3, 4}}, nil,
|
||||
"main.1", "main.2", "main.3", "main.4", "main.6")
|
||||
if v, _, _, _ := ix.Pins.Get(ctx, "main.3"); !slices.Equal(mustRecords(t, v), []string{"pipeline.main.1"}) {
|
||||
t.Errorf("the pin of main.3 holds %s, want the pipeline's record", v)
|
||||
}
|
||||
heard(&runner.PipelineStarted{Branch: "main", Pipeline: "main.1", Revision: 1, Kept: []int64{3, 4}}, nil,
|
||||
"main.1", "main.3", "main.4", "main.6")
|
||||
heard(nil, &runner.PipelineEnded{Branch: "main", Pipeline: "main.1", Revision: 1, Outcome: runner.PipelineEndedOutcomeFailed}, "main.6")
|
||||
}
|
||||
|
||||
// Design 47 H §749 (G §579, A-169, A-171): the indexer pins a revision on a pipeline-started that names it and frees it on its
|
||||
// pipeline-ended, counts a record once, and removes a revision only while its consumers are caught up, judged against the pins
|
||||
// its own state holds, never a count of pins stated: one two pipelines pin stays until both free it, one neither pinned nor
|
||||
|
||||
@@ -371,11 +371,35 @@ func TestATakeInOnAFullStoreIsHeldAndSaidOnce(t *testing.T) {
|
||||
len(held[0].Heads) != 1 || held[0].Heads[0] != moved.Heads[0] || !reflect.DeepEqual(held[0].Event(), moved) {
|
||||
t.Fatalf("held = %+v, want 3 then 4, each with its event whole", held)
|
||||
}
|
||||
// H-A-497: behind them a source whose head the forge does not answer, and one more behind it.
|
||||
for _, n := range []struct {
|
||||
source int64
|
||||
commit string
|
||||
}{{5, "c-unread"}, {6, f.Merge}} {
|
||||
e := moved
|
||||
e.Source, e.Call, e.Heads = n.source, fmt.Sprintf("%d123456789abcdef", n.source), []meshdelivery.SourceMovedEventHeadsItem{{Repository: f.Repository, Commit: n.commit}}
|
||||
if behind, err := ix.HoldBehind(ctx, e); err != nil || !behind {
|
||||
t.Fatalf("source %d held behind: %v (%v)", n.source, behind, err)
|
||||
}
|
||||
}
|
||||
var lines []string
|
||||
ix.Logf = func(format string, args ...any) { lines = append(lines, fmt.Sprintf(format, args...)) }
|
||||
ix.TakeIns = newMem()
|
||||
// H-A-497 addendum: while the chain runs, its key names the source being taken in and how many wait behind it.
|
||||
var steps []string
|
||||
read := ix.Read
|
||||
ix.Read = func(ctx context.Context, repository, sha, dir string) (RepoRead, error) {
|
||||
if c, ok, _ := ix.ChainOf(ctx, "main"); ok {
|
||||
steps = append(steps, fmt.Sprintf("%d/%d", c.Source, c.Waiting))
|
||||
}
|
||||
return read(ctx, repository, sha, dir)
|
||||
}
|
||||
objects.capacity = 1 << 22
|
||||
if ok, err := ix.RoomAgain(ctx); err != nil || !ok || rooms != 1 {
|
||||
t.Fatalf("room said %v %d times (%v), want once the store has room", ok, rooms, err)
|
||||
}
|
||||
// H-A-114: on room (and at start) the held ones are taken in again from the state held alone, in their order.
|
||||
// H-A-114, H-A-497: on room (and at start, and by hand) the held ones are taken in again from the state held alone, in
|
||||
// their order, each next one at once and said in the journal, until one is held again: those behind it stay held.
|
||||
ix.TakeHeldIn(ctx)
|
||||
var taken []int64
|
||||
for _, e := range *said {
|
||||
@@ -386,8 +410,38 @@ func TestATakeInOnAFullStoreIsHeldAndSaidOnce(t *testing.T) {
|
||||
if !reflect.DeepEqual(taken, []int64{3, 4}) {
|
||||
t.Errorf("taken again on room: %v of %+v, want 3 then 4", taken, *said)
|
||||
}
|
||||
if held, _ := ReadHeld(ctx, ix.Held); len(held) != 0 {
|
||||
t.Errorf("held = %+v after the take-in, want none", held)
|
||||
if held, _ := ReadHeld(ctx, ix.Held); len(held) != 2 || held[0].Source != 5 || held[1].Source != 6 {
|
||||
t.Errorf("held = %+v after the take-in, want 5 held again and 6 behind it", held)
|
||||
}
|
||||
for _, want := range []string{
|
||||
"take-in: held source 4 of main taken in next, after 3 (H-A-497)",
|
||||
"take-in: held source 5 of main taken in next, after 4 (H-A-497)",
|
||||
} {
|
||||
if !slices.Contains(lines, want) {
|
||||
t.Errorf("the journal holds no line %q: %q", want, lines)
|
||||
}
|
||||
}
|
||||
for _, l := range lines {
|
||||
if strings.Contains(l, "held source 6 of main taken in") {
|
||||
t.Errorf("source 6 was taken in behind a held one: %q", l)
|
||||
}
|
||||
}
|
||||
if !slices.Contains(steps, "4/2") || !slices.Contains(steps, "5/1") {
|
||||
t.Errorf("the chain's key read at each take-in %v, want main at 4 with 2 waiting and at 5 with 1", steps)
|
||||
}
|
||||
// H-A-497 addendum: the chain's key in the state takeins goes at its end, here its first held again, and one a stop
|
||||
// left is deleted at the start.
|
||||
if chains, err := ReadChains(ctx, ix.TakeIns); err != nil || len(chains) != 0 {
|
||||
t.Errorf("chains %+v (%v) after the chain stopped, want none", chains, err)
|
||||
}
|
||||
ix.writeChain(ctx, HeldChain{Branch: "main", Source: 9, Waiting: 1})
|
||||
if ix.EndChains(ctx); func() bool { c, _ := ReadChains(ctx, ix.TakeIns); return len(c) != 0 }() {
|
||||
t.Error("a chain's key left by a stop stays after the start")
|
||||
}
|
||||
ix.Read = read
|
||||
ix.Logf, ix.TakeIns = nil, nil
|
||||
for _, src := range []int64{5, 6} {
|
||||
ix.unhold(ctx, "main", src)
|
||||
}
|
||||
// A skip ends a held source revision unwritten: take-in.taken with no entries, skipped, by and why; held is deleted.
|
||||
ix.hold(ctx, meshdelivery.SourceMovedEvent{Branch: "nox-mesh", Source: 9, Call: "fedcba9876543210"}, "the catalog store is full")
|
||||
|
||||
@@ -10,11 +10,11 @@ import (
|
||||
)
|
||||
|
||||
// TestRunsTools are runner_test_runs and runner_test_runs_drop (design 47 G §728; A-469f, A-469u): each calls its seat verb
|
||||
// over the bus, both answered by the runner's process, which holds test-runs-cap-mib (A-469g, A-470i).
|
||||
// over the bus, both answered by the runner's process, which reads test-runs' fill against its bucket's max bytes (A-469g, A-470i, H-A-510).
|
||||
func TestRunsTools(ask func(key string, body any) (json.RawMessage, error)) []stdio.Tool {
|
||||
return []stdio.Tool{
|
||||
{Name: Prefix + "_test_runs",
|
||||
Description: "The pipeline runner's test runs, one per candidate, level and tested packages (the state test-runs): each with its packages read from its output object, its ask, node, readers, outcome and counts, and the state's fill against its cap setting test-runs-cap-mib; filtered by a candidate, a level, a digest or a module, or none.",
|
||||
Description: "The pipeline runner's test runs, one per candidate, level and tested packages (the state test-runs): each with its packages read from its output object, its ask, node, readers, outcome and counts, and the state's fill against its cap, the bucket's max bytes (the manifest's max-mib); filtered by a candidate, a level, a digest or a module, or none.",
|
||||
Input: map[string]any{"type": "object", "properties": map[string]any{
|
||||
"candidate": map[string]any{"type": "string"}, "level": map[string]any{"type": "string"},
|
||||
"digest": map[string]any{"type": "string"}, "module": map[string]any{"type": "string"}}},
|
||||
|
||||
@@ -60,3 +60,37 @@ func TestAgedHub(t *testing.T) {
|
||||
t.Errorf("a message asked again is noted applied: %+v", last)
|
||||
}
|
||||
}
|
||||
|
||||
// TestTheTakeInsSwitch: until the takeins durable is bound, the main durable works every take-in; from the bind, it works
|
||||
// only those said at or before the sequence the durable delivers after, and acknowledges the rest with no work
|
||||
// (design 47 H2 H-A-500 fourth addendum).
|
||||
func TestTheTakeInsSwitch(t *testing.T) {
|
||||
for _, row := range []struct {
|
||||
name string
|
||||
boundFrom uint64
|
||||
bound bool
|
||||
seq uint64
|
||||
delivers bool
|
||||
}{
|
||||
{"not bound, any sequence is worked", 0, false, 7, false},
|
||||
{"bound after 5, the take-in at 5 is worked", 5, true, 5, false},
|
||||
{"bound after 5, the take-in at 6 is the durable's", 5, true, 6, true},
|
||||
{"bound on an empty stream, the first take-in is the durable's", 0, true, 1, true},
|
||||
} {
|
||||
t.Run(row.name, func(t *testing.T) {
|
||||
sw := &takeInsSwitch{}
|
||||
if row.bound {
|
||||
sw.boundFrom(row.boundFrom)
|
||||
}
|
||||
hub := &oneHub{}
|
||||
worked := false
|
||||
if err := dropTakenIn(hub, sw, func(jetstream.Msg) { worked = true }); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
hub.handle(ackedMsg{seq: row.seq})
|
||||
if worked == row.delivers {
|
||||
t.Errorf("worked by the main durable: %v, want %v", worked, !row.delivers)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,8 +188,10 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
clock := askClock(ctx, bounds, askBound, rv.Findings, cred.Module, time.Now)
|
||||
starter.Asks, hearer.Asks = clock, clock
|
||||
starter.Supersede = func(newer seat.Pipeline) { hearer.SupersedeRunning(newer) }
|
||||
starter.Left = hearer.LeftInPlace // a same-source re-pin's superseded steps leave their runs (H-A-284)
|
||||
starter.Revision = widener.Revision // a kept mover is placed from its kept revision (H-A-286)
|
||||
starter.Drop = hearer.DropOpen // a placing's end drops the asks still open (H-A-506)
|
||||
hearer.Aside = func(do func()) { go do() } // each drop of an ended pipeline's asks beside its end (H-A-506)
|
||||
starter.Left = hearer.LeftInPlace // a same-source re-pin's superseded steps leave their runs (H-A-284)
|
||||
starter.Revision = widener.Revision // a kept mover is placed from its kept revision (H-A-286)
|
||||
// A mover's wait on a package is read first: a package published before the wait places it at once (H-A-326, H-A-328).
|
||||
// It is a kept call within ask-unanswered-bound (design 47 H2 §775).
|
||||
starter.AskPublished = publishedOf(func(key string, body any) (json.RawMessage, error) {
|
||||
@@ -237,8 +239,13 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
}
|
||||
}
|
||||
advancer.Store(&advance)
|
||||
// A registration-changed places the steps of its module's pipelines started before it, from it (A-327).
|
||||
// A registration-changed places the steps of its module's pipelines started before it, from it (A-327), and binds the
|
||||
// takeins durable when its bind failed at the start (H-A-500 fifth addendum).
|
||||
var bindTakeInsAgain atomic.Pointer[func()]
|
||||
register := func(reg catalog.Registration) {
|
||||
if f := bindTakeInsAgain.Load(); f != nil {
|
||||
(*f)()
|
||||
}
|
||||
if n, err := starter.Registered(store, reg, rv.Catalog.View); err != nil || n > 0 {
|
||||
logger.Printf("the pipelines of %s started before its registration: %d placed (%v)", reg.Module, n, err)
|
||||
}
|
||||
@@ -321,6 +328,9 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
return err
|
||||
}
|
||||
if err := hearStepProgress(heard, func(onSeat, ask string) error {
|
||||
if hearer.LateRunAsk("step-progress", ask) {
|
||||
return nil // an ended run's ask: acknowledged at once, nothing read but its ask key and run (H-A-500 (a))
|
||||
}
|
||||
progressed(clock, onSeat, ask, logger.Printf) // the ask's bound is armed again from now (H-A-395)
|
||||
return hearer.RunProgress(ask)
|
||||
}, logger.Printf); err != nil {
|
||||
@@ -333,6 +343,9 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
return err
|
||||
}
|
||||
taken := func(ask, node string, at time.Time) (*time.Time, error) {
|
||||
if hearer.LateRunAsk("ask-taken", ask) {
|
||||
return nil, nil // an ended run's ask: acknowledged at once, nothing read but its ask key and run (H-A-500 (a))
|
||||
}
|
||||
takenAt, err := hearer.Taken(ask, node, at)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -370,7 +383,17 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
if err := hearRecovery(heard, kvRecoveries{ctx, recovered}, logger.Printf); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := hearTakenIn(heard, starter, rv.Catalog, logger.Printf); err != nil {
|
||||
// take-in.taken is acted on on the runner's own takeins durable once that is bound, so no step traffic holds a take-in;
|
||||
// until then the main durable works it, and from the bind acknowledges it at once (design 47 H2 H-A-500 (b) and its
|
||||
// addenda, the fourth: no take-in said while the runner was down is lost).
|
||||
takeInsBound := &takeInsSwitch{}
|
||||
if err := dropTakenIn(heard, takeInsBound, takenIn(starter, rv.Catalog, logger.Printf)); err != nil {
|
||||
return err
|
||||
}
|
||||
takeIns := &oneHandler{}
|
||||
takeInsName := cred.EventConsumerName() + "_" + takeInsSuffix
|
||||
takeInsHeard := agedHub{hub: takeIns, ledger: process.NewConsumerLedger(process.EventsStream, takeInsName, consumersSink(consumers), nil, logger.Printf)}
|
||||
if err := hearTakenIn(takeInsHeard, starter, rv.Catalog, logger.Printf); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := hearReleased(heard, hearer, starter.Registration, logger.Printf); err != nil {
|
||||
@@ -387,6 +410,8 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
// their callers against (A-186): registered before the hub starts, read again once its events are live.
|
||||
seats := seatlist.NewPart("runner")
|
||||
seats.Follow(seatlist.ProcessBus(calls.Call, hub), nil, logger.Printf)
|
||||
again := bindTakeIns(ctx, js, cred, takeIns.handle, takeInsBound, logger.Printf)
|
||||
bindTakeInsAgain.Store(&again)
|
||||
if err := hub.StartUntilBound(ctx, js, cred, nil, seats.EventsLive); err != nil {
|
||||
logger.Printf("the consumer %s is not bound yet (%v): bound once the bus makes it", cred.EventConsumerName(), err)
|
||||
}
|
||||
|
||||
@@ -172,6 +172,7 @@ func testTheQueueRunsPipelinesInTurn(t *testing.T) {
|
||||
return ""
|
||||
}, logs)
|
||||
}()
|
||||
takeInsHeard(t, ctx, logs)
|
||||
return func() { stop(); <-done }
|
||||
}
|
||||
stopRunner := start()
|
||||
@@ -267,13 +268,16 @@ func testTheQueueRunsPipelinesInTurn(t *testing.T) {
|
||||
waitFor(t, ctx, logs, func() bool { return get(key).Outcome == want })
|
||||
}
|
||||
|
||||
// Two take-ins in a row: the first runs, its build asked; the second is written waiting under sequence 1 with no step,
|
||||
// says pipeline-started and wait-held.
|
||||
// Two take-ins in a row: the first runs at sequence 1 (every pipeline has one, H-A-504 addendum), its build asked; the
|
||||
// second is written waiting under sequence 2 with no step, says pipeline-started and wait-held.
|
||||
take(3, "app")
|
||||
outcome("main.3", seat.PipelineOutcomeRunning)
|
||||
if p := get("main.3"); p.Seq != 1 {
|
||||
t.Fatalf("main.3 placed at once has seq %d, want 1", p.Seq)
|
||||
}
|
||||
take(4, "lib")
|
||||
if p := get("main.4"); p.Outcome != seat.PipelineOutcomeWaiting || p.Seq != 1 || len(p.Steps) != 0 {
|
||||
t.Fatalf("main.4 = %s seq %d with %d steps, want waiting at 1 with none", p.Outcome, p.Seq, len(p.Steps))
|
||||
if p := get("main.4"); p.Outcome != seat.PipelineOutcomeWaiting || p.Seq != 2 || len(p.Steps) != 0 {
|
||||
t.Fatalf("main.4 = %s seq %d with %d steps, want waiting at 2 with none", p.Outcome, p.Seq, len(p.Steps))
|
||||
}
|
||||
waitFor(t, ctx, logs, func() bool { return wasSaid("wait-held.main.4") && wasSaid("pipeline-started.main.4") })
|
||||
if r := running(); !slices.Equal(r, []string{"main.3"}) {
|
||||
|
||||
@@ -52,6 +52,9 @@ func (s *syncBuffer) String() string { s.mu.Lock(); defer s.mu.Unlock(); return
|
||||
// bus proved; the pipeline then ends passed.
|
||||
func TestTheRunnerPlacesAPipelineAsksItsBuildTakesItsEndAndAnswersAReview(t *testing.T) {
|
||||
t.Run("the queue runs pipelines in turn", testTheQueueRunsPipelinesInTurn)
|
||||
t.Run("a take-in is heard while late events queue on the main durable", testATakeInIsHeardWhileLateEventsQueue)
|
||||
t.Run("a take-in said before the bind is still worked", testATakeInSaidBeforeTheBindIsStillWorked)
|
||||
t.Run("a takeins bind that failed is bound again on registration-changed", testATakeInsBindThatFailedIsBoundAgainOnRegistrationChanged)
|
||||
t.Run("step log read does not wait for a batch it cannot fill", testStepLogReadDoesNotWaitForABatchItCannotFill)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer cancel()
|
||||
@@ -384,6 +387,7 @@ func startWhole(t *testing.T, ctx context.Context, regs []catalog.Registration,
|
||||
}, logs)
|
||||
}()
|
||||
t.Cleanup(func() { stop(); <-done })
|
||||
takeInsHeard(t, ctx, logs)
|
||||
pipelines, err := js.KeyValue(ctx, module+"_pipelines")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -500,6 +504,14 @@ func findingsStream(t *testing.T, ctx context.Context, js jetstream.JetStream, m
|
||||
}
|
||||
}
|
||||
|
||||
// takeInsHeard waits until the runner's takeins durable is bound, which the runner makes at its first start from the
|
||||
// moment it is made (H-A-500 (b)); a take-in said before is worked by the main durable (the fourth addendum), but the tests
|
||||
// publish after the bind so that each take-in is heard where the running runner hears it.
|
||||
func takeInsHeard(t *testing.T, ctx context.Context, logs *syncBuffer) {
|
||||
t.Helper()
|
||||
waitFor(t, ctx, logs, func() bool { return strings.Contains(logs.String(), "take-ins: heard on the consumer") })
|
||||
}
|
||||
|
||||
func waitFor(t *testing.T, ctx context.Context, logs *syncBuffer, cond func() bool) {
|
||||
t.Helper()
|
||||
for ctx.Err() == nil {
|
||||
|
||||
@@ -3,12 +3,19 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/nats-io/nats.go/jetstream"
|
||||
|
||||
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"
|
||||
|
||||
"git.novox.be/novox/mesh-sdk/go/process"
|
||||
|
||||
"mesh-delivery-pipeline/internal/pipeline"
|
||||
)
|
||||
|
||||
@@ -57,10 +64,140 @@ func revisedHear(revised func(ev catalog.CatalogRevisionEvent) (int, error), log
|
||||
}
|
||||
}
|
||||
|
||||
// takeInsSuffix names the runner's own second durable on the shared events stream, `<node>_<module>_takeins`, on which alone
|
||||
// take-in.taken is acted on, so a pipeline starts within seconds of its take-in whatever the step traffic on the runner's
|
||||
// main durable (design 47 H2 H-A-500 (b) and its addenda).
|
||||
const takeInsSuffix = "takeins"
|
||||
|
||||
// The ack wait and the deliveries of the takeins durable, as the grants part gives a module's consumers (H-A-500 (b)).
|
||||
const (
|
||||
takeInsAckWait = 30 * time.Second
|
||||
takeInsMaxDeliver = 5
|
||||
)
|
||||
|
||||
// takeInsConsumerConfig is the takeins durable as the runner makes it: take-in.taken alone, acknowledged one by one, from
|
||||
// the moment it is made (H-A-500 (b)).
|
||||
func takeInsConsumerConfig(cred process.Account) jetstream.ConsumerConfig {
|
||||
cfg := cred.SeatEventConsumerConfig([]string{pipeline.TakenInSubject}, false)
|
||||
cfg.Durable = cred.EventConsumerName() + "_" + takeInsSuffix
|
||||
cfg.AckWait, cfg.MaxDeliver = takeInsAckWait, takeInsMaxDeliver
|
||||
cfg.DeliverPolicy = jetstream.DeliverNewPolicy
|
||||
return cfg
|
||||
}
|
||||
|
||||
// oneHandler is the handlers of one durable that hears one pattern: the takeins durable's (H-A-500 (b)).
|
||||
type oneHandler struct {
|
||||
pattern string
|
||||
handle func(jetstream.Msg)
|
||||
}
|
||||
|
||||
func (o *oneHandler) Handle(pattern string, handle func(jetstream.Msg)) error {
|
||||
if o.handle != nil {
|
||||
return fmt.Errorf("the durable hears %q already, so %q has no taker", o.pattern, pattern)
|
||||
}
|
||||
o.pattern, o.handle = pattern, handle
|
||||
return nil
|
||||
}
|
||||
|
||||
// takeInsSwitch says which durable a take-in.taken is worked on (H-A-500 fourth addendum): until the runner's takeins
|
||||
// durable is bound, the main durable does the work, so a take-in said while the runner was down is lost to no one; from
|
||||
// the bind, the takeins durable alone works the take-ins said after it was made, and the main durable acknowledges those
|
||||
// at once with no work. The boundary is the stream sequence the takeins durable delivers from, so a take-in said before
|
||||
// the durable was made and still waiting on the main durable is worked there whatever the moment it is heard.
|
||||
type takeInsSwitch struct {
|
||||
// from holds 1 + the stream sequence the takeins durable delivers after; 0 while it is not bound.
|
||||
from atomic.Uint64
|
||||
}
|
||||
|
||||
// boundFrom says the takeins durable is bound and delivers every take-in said after stream sequence seq.
|
||||
func (s *takeInsSwitch) boundFrom(seq uint64) { s.from.Store(seq + 1) }
|
||||
|
||||
// delivers says whether the takeins durable delivers m, so the main durable has no work on it.
|
||||
func (s *takeInsSwitch) delivers(m jetstream.Msg) bool {
|
||||
from := s.from.Load()
|
||||
if from == 0 {
|
||||
return false
|
||||
}
|
||||
meta, err := m.Metadata()
|
||||
if err != nil {
|
||||
// A message whose sequence is unknown is worked rather than dropped: the work is done once per key, never twice.
|
||||
return false
|
||||
}
|
||||
return meta.Sequence.Stream >= from
|
||||
}
|
||||
|
||||
// dropTakenIn has the main durable work each take-in.taken the takeins durable does not deliver, and acknowledge the rest at
|
||||
// once with no work, so the finding event-unhandled stays clear (H-A-500 third and fourth addenda).
|
||||
func dropTakenIn(hub handlers, sw *takeInsSwitch, work func(jetstream.Msg)) error {
|
||||
return hub.Handle(pipeline.TakenInSubject, func(m jetstream.Msg) {
|
||||
if sw.delivers(m) {
|
||||
_ = m.Ack()
|
||||
return
|
||||
}
|
||||
work(m)
|
||||
})
|
||||
}
|
||||
|
||||
// bindTakeIns binds the runner's takeins durable and hears it with handle, the durable made when the bus does not hold it
|
||||
// (H-A-500 (b)): bound at once when it can be, so no take-in said after the runner's start is missed. A bind that fails
|
||||
// (the bus has not made the runner's grant yet) is said, and the answered func binds again, called on each
|
||||
// registration-changed as the indexer binds a branch's consumer on each (H-A-500 fifth addendum: nothing waits on a timer
|
||||
// for another part); once bound it does nothing. Once bound, sw says so with the stream sequence the durable delivers
|
||||
// after, and the main durable stops working the take-ins it delivers (the fourth addendum).
|
||||
func bindTakeIns(ctx context.Context, js jetstream.JetStream, cred process.Account, handle func(jetstream.Msg), sw *takeInsSwitch,
|
||||
logf func(string, ...any)) (again func()) {
|
||||
bind := func() error {
|
||||
cons, err := cred.NamedEventConsumer(ctx, js, process.EventsStream, takeInsSuffix)
|
||||
if errors.Is(err, jetstream.ErrConsumerNotFound) {
|
||||
cfg := takeInsConsumerConfig(cred)
|
||||
if cons, err = js.CreateConsumer(ctx, process.EventsStream, cfg); err != nil {
|
||||
return fmt.Errorf("the consumer %s on %s is not there and is not made: %w", cfg.Durable, process.EventsStream, err)
|
||||
}
|
||||
logf("take-ins: the consumer %s on %s was not there: the runner made it (H-A-500 (b))", cfg.Durable, process.EventsStream)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// A durable just made delivers after the stream's last sequence; one found, after what it delivered already.
|
||||
info, err := cons.Info(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("the consumer %s_%s is not read: %w", cred.EventConsumerName(), takeInsSuffix, err)
|
||||
}
|
||||
if _, err = process.HearEvents(cons, handle, logf); err != nil {
|
||||
return err
|
||||
}
|
||||
sw.boundFrom(info.Delivered.Stream)
|
||||
return nil
|
||||
}
|
||||
var mu sync.Mutex
|
||||
bound := false
|
||||
try := func() {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
if bound || ctx.Err() != nil {
|
||||
return
|
||||
}
|
||||
if err := bind(); err != nil {
|
||||
logf("take-ins: the consumer %s_%s is not bound, so the main durable works each take-in; bound again at the next registration-changed: %v",
|
||||
cred.EventConsumerName(), takeInsSuffix, err)
|
||||
return
|
||||
}
|
||||
bound = true
|
||||
logf("take-ins: heard on the consumer %s_%s (H-A-500 (b))", cred.EventConsumerName(), takeInsSuffix)
|
||||
}
|
||||
try()
|
||||
return try
|
||||
}
|
||||
|
||||
// hearTakenIn starts the pipeline of each take-in.taken heard (design 47 H §746): one per take-in, the message acknowledged
|
||||
// once it is written, and heard again when a write failed, so the key already written starts nothing twice.
|
||||
func hearTakenIn(hub handlers, starter *pipeline.Starter, v *pipeline.Views, logf func(string, ...any)) error {
|
||||
return hub.Handle(pipeline.TakenInSubject, func(m jetstream.Msg) {
|
||||
return hub.Handle(pipeline.TakenInSubject, takenIn(starter, v, logf))
|
||||
}
|
||||
|
||||
// takenIn is the work of one take-in.taken, on whichever durable delivers it (H-A-500 fourth addendum).
|
||||
func takenIn(starter *pipeline.Starter, v *pipeline.Views, logf func(string, ...any)) func(jetstream.Msg) {
|
||||
return func(m jetstream.Msg) {
|
||||
// An event of the old form is refused by the contract's strict decode, said in one journal line and ended (§765, H-A-98).
|
||||
ev, err := pipeline.DecodeTakenIn(m.Data())
|
||||
if err != nil {
|
||||
@@ -76,7 +213,7 @@ func hearTakenIn(hub handlers, starter *pipeline.Starter, v *pipeline.Views, log
|
||||
}
|
||||
logf("the take-in of %s source %d started %d pipelines", ev.Branch, ev.Source, n)
|
||||
_ = m.Ack()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// hearReleased writes each version-released's version into its mover (design 47 H §746, H-A-52), so the pipeline's end names
|
||||
|
||||
+221
@@ -0,0 +1,221 @@
|
||||
//go:build integration
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/nats-io/nats.go"
|
||||
"github.com/nats-io/nats.go/jetstream"
|
||||
|
||||
"git.novox.be/novox/mesh-sdk/go/process"
|
||||
"git.novox.be/novox/mesh-sdk/go/testbus"
|
||||
|
||||
"mesh-delivery-pipeline/internal/pipeline"
|
||||
)
|
||||
|
||||
// Design 47 H2 H-A-500 (b) and its addenda: a take-in.taken said while 500 late step-progress events wait on the runner's
|
||||
// main durable, its handler held, is heard at once on the runner's own takeins durable, which the runner makes itself; the
|
||||
// main durable acknowledges the take-in with no work. testATakeInIsHeardWhileLateEventsQueue is a row of
|
||||
// TestTheRunnerPlacesAPipelineAsksItsBuildTakesItsEndAndAnswersAReview (the module's tests are folded under its budget).
|
||||
func testATakeInIsHeardWhileLateEventsQueue(t *testing.T) {
|
||||
url := testbus.URL(t)
|
||||
nc, err := nats.Connect(url)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer nc.Close()
|
||||
js, err := jetstream.New(nc)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer cancel()
|
||||
cred := process.Account{URL: url, Node: "n1", Module: "mesh-delivery-pipeline"}
|
||||
events, err := js.CreateStream(ctx, jetstream.StreamConfig{Name: process.EventsStream, Subjects: []string{"mesh.mod.*.event.>", "mesh.seat.*.event.>"}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := events.CreateOrUpdateConsumer(ctx, jetstream.ConsumerConfig{Durable: cred.EventConsumerName(), AckPolicy: jetstream.AckExplicitPolicy}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
const progress = "mesh.seat.node-build-go.event.step-progress.n1"
|
||||
for i := 0; i < 500; i++ {
|
||||
if _, err := js.Publish(ctx, progress, []byte(`{"ask":"late","phase":"run"}`)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
// The main durable's step-progress handler is held until the test ends: every late event waits behind the first.
|
||||
held := make(chan struct{})
|
||||
defer close(held)
|
||||
hub := process.NewEventHub(t.Logf)
|
||||
if err := hub.Handle(progress, func(m jetstream.Msg) { <-held; _ = m.Ack() }); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
sw := &takeInsSwitch{}
|
||||
if err := dropTakenIn(hub, sw, func(m jetstream.Msg) { t.Errorf("the main durable worked %s after the bind", m.Subject()); _ = m.Ack() }); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := hub.Start(ctx, js, cred); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer hub.Stop()
|
||||
heard := make(chan string, 1)
|
||||
takeIns := &oneHandler{}
|
||||
if err := takeIns.Handle(pipeline.TakenInSubject, func(m jetstream.Msg) { heard <- m.Subject(); _ = m.Ack() }); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
bindTakeIns(ctx, js, cred, takeIns.handle, sw, t.Logf)
|
||||
if _, err := js.Publish(ctx, "mesh.mod.mesh-delivery-indexer.event.take-in.taken", []byte(`{}`)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
select {
|
||||
case s := <-heard:
|
||||
if s != "mesh.mod.mesh-delivery-indexer.event.take-in.taken" {
|
||||
t.Errorf("the takeins durable heard %s", s)
|
||||
}
|
||||
case <-ctx.Done():
|
||||
t.Fatal("the take-in is not heard while late events wait on the main durable")
|
||||
}
|
||||
info, err := events.Consumer(ctx, cred.EventConsumerName()+"_"+takeInsSuffix)
|
||||
if err != nil {
|
||||
t.Fatalf("the takeins durable is not made: %v", err)
|
||||
}
|
||||
if f := info.CachedInfo().Config.FilterSubjects; len(f) != 1 || f[0] != pipeline.TakenInSubject {
|
||||
t.Errorf("the takeins durable filters %v, want take-in.taken alone", f)
|
||||
}
|
||||
}
|
||||
|
||||
// Design 47 H2 H-A-500 fourth addendum: a take-in.taken said before the runner's takeins durable is bound (the runner was
|
||||
// down, or the bind failed) is worked by the main durable, so it starts its pipeline; one said after the bind is worked by
|
||||
// the takeins durable alone and the main durable acknowledges it with no work. A row of
|
||||
// TestTheRunnerPlacesAPipelineAsksItsBuildTakesItsEndAndAnswersAReview.
|
||||
func testATakeInSaidBeforeTheBindIsStillWorked(t *testing.T) {
|
||||
url := testbus.URL(t)
|
||||
nc, err := nats.Connect(url)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer nc.Close()
|
||||
js, err := jetstream.New(nc)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer cancel()
|
||||
cred := process.Account{URL: url, Node: "n1", Module: "mesh-delivery-pipeline"}
|
||||
events, err := js.CreateStream(ctx, jetstream.StreamConfig{Name: process.EventsStream, Subjects: []string{"mesh.mod.*.event.>", "mesh.seat.*.event.>"}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := events.CreateOrUpdateConsumer(ctx, jetstream.ConsumerConfig{Durable: cred.EventConsumerName(), AckPolicy: jetstream.AckExplicitPolicy}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
const subject = "mesh.mod.mesh-delivery-indexer.event.take-in.taken"
|
||||
// Said while the runner was down: the main durable holds it, the takeins durable does not exist yet.
|
||||
if _, err := js.Publish(ctx, subject, []byte(`{"before":true}`)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// The main durable's take-in handler is held until the takeins durable is bound, as a main durable busy with step
|
||||
// events would be: the take-in said before the bind is still worked, by its sequence, not by the moment it is heard.
|
||||
held := make(chan struct{})
|
||||
worked, heard := make(chan string, 2), make(chan string, 2)
|
||||
hub := process.NewEventHub(t.Logf)
|
||||
sw := &takeInsSwitch{}
|
||||
if err := dropTakenIn(hub, sw, func(m jetstream.Msg) { <-held; worked <- string(m.Data()); _ = m.Ack() }); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := hub.Start(ctx, js, cred); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer hub.Stop()
|
||||
takeIns := &oneHandler{}
|
||||
if err := takeIns.Handle(pipeline.TakenInSubject, func(m jetstream.Msg) { heard <- string(m.Data()); _ = m.Ack() }); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
bindTakeIns(ctx, js, cred, takeIns.handle, sw, t.Logf)
|
||||
if sw.from.Load() == 0 {
|
||||
t.Fatal("the takeins durable is not bound")
|
||||
}
|
||||
// Said after the bind: the takeins durable's alone.
|
||||
if _, err := js.Publish(ctx, subject, []byte(`{"after":true}`)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
close(held)
|
||||
select {
|
||||
case d := <-worked:
|
||||
if d != `{"before":true}` {
|
||||
t.Errorf("the main durable worked %s, want the take-in said before the bind", d)
|
||||
}
|
||||
case <-ctx.Done():
|
||||
t.Fatal("the take-in said before the bind is worked by no durable")
|
||||
}
|
||||
select {
|
||||
case d := <-heard:
|
||||
if d != `{"after":true}` {
|
||||
t.Errorf("the takeins durable heard %s, want the take-in said after the bind", d)
|
||||
}
|
||||
case <-ctx.Done():
|
||||
t.Fatal("the take-in said after the bind is not heard on the takeins durable")
|
||||
}
|
||||
// The main durable acknowledged the second with no work: nothing more is worked once its queue is drained.
|
||||
select {
|
||||
case d := <-worked:
|
||||
t.Errorf("the main durable worked %s after the bind", d)
|
||||
case <-time.After(2 * time.Second):
|
||||
}
|
||||
info, err := events.Consumer(ctx, cred.EventConsumerName())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ci, err := info.Info(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if ci.NumAckPending != 0 || ci.NumPending != 0 {
|
||||
t.Errorf("the main durable holds %d pending and %d unacknowledged, want none", ci.NumPending, ci.NumAckPending)
|
||||
}
|
||||
}
|
||||
|
||||
// Design 47 H2 H-A-500 fifth addendum: a takeins bind that failed at the start (here the events stream is not there yet, as
|
||||
// the runner's grant is not there before the bus composes its account) is said and bound again on the next
|
||||
// registration-changed, never on a timer. A row of TestTheRunnerPlacesAPipelineAsksItsBuildTakesItsEndAndAnswersAReview.
|
||||
func testATakeInsBindThatFailedIsBoundAgainOnRegistrationChanged(t *testing.T) {
|
||||
url := testbus.URL(t)
|
||||
nc, err := nats.Connect(url)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer nc.Close()
|
||||
js, err := jetstream.New(nc)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer cancel()
|
||||
cred := process.Account{URL: url, Node: "n1", Module: "mesh-delivery-pipeline"}
|
||||
sw := &takeInsSwitch{}
|
||||
heard := make(chan string, 1)
|
||||
again := bindTakeIns(ctx, js, cred, func(m jetstream.Msg) { heard <- m.Subject(); _ = m.Ack() }, sw, t.Logf)
|
||||
if sw.from.Load() != 0 {
|
||||
t.Fatal("the takeins durable is bound with no events stream")
|
||||
}
|
||||
if _, err := js.CreateStream(ctx, jetstream.StreamConfig{Name: process.EventsStream, Subjects: []string{"mesh.mod.*.event.>", "mesh.seat.*.event.>"}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
again() // the registration-changed heard once the bus holds the stream and the grant
|
||||
if sw.from.Load() == 0 {
|
||||
t.Fatal("the takeins durable is not bound again on registration-changed")
|
||||
}
|
||||
if _, err := js.Publish(ctx, "mesh.mod.mesh-delivery-indexer.event.take-in.taken", []byte(`{}`)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
select {
|
||||
case <-heard:
|
||||
case <-ctx.Done():
|
||||
t.Fatal("the take-in is not heard on the durable bound again")
|
||||
}
|
||||
again() // bound already: nothing is bound twice
|
||||
}
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -166,6 +165,34 @@ func (t testRunsKV) Has(key string) (bool, error) {
|
||||
return err == nil, err
|
||||
}
|
||||
|
||||
// MarkAsk creates the ask key of ask holding mark (H-A-506 addendum); one written already is kept.
|
||||
func (t testRunsKV) MarkAsk(ask string, mark pipeline.AskMark) error {
|
||||
raw, err := json.Marshal(mark)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := t.kv.Create(t.ctx, pipeline.AskKey(ask), raw); err != nil && !errors.Is(err, jetstream.ErrKeyExists) {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// AskOf reads the ask key of ask: the mark it holds, a key written before the H-A-506 addendum naming its run alone.
|
||||
func (t testRunsKV) AskOf(ask string) (pipeline.AskMark, bool, error) {
|
||||
e, err := t.kv.Get(t.ctx, pipeline.AskKey(ask))
|
||||
if errors.Is(err, jetstream.ErrKeyNotFound) {
|
||||
return pipeline.AskMark{}, false, nil
|
||||
}
|
||||
if err != nil {
|
||||
return pipeline.AskMark{}, false, err
|
||||
}
|
||||
var m pipeline.AskMark
|
||||
if err := json.Unmarshal(e.Value(), &m); err != nil || (m.Run == "" && m.Pipeline == "") {
|
||||
return pipeline.AskMark{}, false, fmt.Errorf("the ask key of ask %s names no pipeline and no run: %v", ask, err)
|
||||
}
|
||||
return m, true, nil
|
||||
}
|
||||
|
||||
func (t testRunsKV) Keys() ([]string, error) {
|
||||
all, err := t.kv.Keys(t.ctx)
|
||||
if errors.Is(err, jetstream.ErrNoKeysFound) {
|
||||
@@ -255,7 +282,8 @@ func (o *runObjects) Delete(name string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// runsFill reads test-runs' fill, its key-value stream's bytes (A-469d): judged by the process against its cap setting.
|
||||
// runsFill reads test-runs' fill, its key-value stream's bytes, against its cap, the stream's max bytes (A-469d, H-A-510
|
||||
// addendum): the bucket on the bus is the one truth of the manifest's max-mib, so the runner keeps no second number.
|
||||
func runsFill(ctx context.Context, js jetstream.JetStream, module string, now func() time.Time) func() (seat.Fill, error) {
|
||||
return func() (seat.Fill, error) {
|
||||
st, err := js.Stream(ctx, "KV_"+ownBucket(module, TestRunsState))
|
||||
@@ -273,7 +301,6 @@ func runsFill(ctx context.Context, js jetstream.JetStream, module string, now fu
|
||||
|
||||
// The files the manifest writes each setting of the test runs into, `${config:<key>}`, named by the environment (A-469x).
|
||||
const (
|
||||
envRunsCap = "MESH_RUNNER_TEST_RUNS_CAP_FILE"
|
||||
envRunsKept = "MESH_RUNNER_TEST_RUNS_KEPT_FILE"
|
||||
envStepBound = "MESH_RUNNER_TEST_STEP_BOUND_FILE"
|
||||
envUntakenBound = "MESH_RUNNER_RUN_UNTAKEN_BOUND_FILE"
|
||||
@@ -282,20 +309,11 @@ const (
|
||||
// maxRunsKept is test-runs-kept's maximum (A-470a): the pipeline naming a run's key is kept at least that long.
|
||||
const maxRunsKept = 168 * time.Hour
|
||||
|
||||
// runSettings reads the settings of the test runs at the start (§725; A-469x): test-runs-cap-mib a whole number of MiB,
|
||||
// test-runs-kept, test-step-bound and run-untaken-bound Go durations. A setting whose file is missing or empty is its
|
||||
// runSettings reads the settings of the test runs at the start (§725; A-469x): test-runs-kept, test-step-bound and
|
||||
// run-untaken-bound Go durations. A setting whose file is missing or empty is its
|
||||
// default; a content that is neither is an error naming the file.
|
||||
func runSettings(getenv func(string) string) (pipeline.RunSettings, error) {
|
||||
s := pipeline.DefaultRunSettings
|
||||
if v, err := settingText(getenv(envRunsCap)); err != nil {
|
||||
return s, err
|
||||
} else if v != "" {
|
||||
n, err := strconv.Atoi(v)
|
||||
if err != nil || n < 1 {
|
||||
return s, fmt.Errorf("%s holds %q, which is not a positive whole number", getenv(envRunsCap), v)
|
||||
}
|
||||
s.CapBytes = int64(n) << 20
|
||||
}
|
||||
for _, d := range []struct {
|
||||
env string
|
||||
to *time.Duration
|
||||
@@ -416,8 +434,9 @@ func openTestRuns(ctx context.Context, js jetstream.JetStream, cred process.Acco
|
||||
hearer.TestRuns, hearer.Clock, hearer.Runs, hearer.DropRun = runs, runs, settings, drop
|
||||
hearer.RunOutputs = objects
|
||||
if hearer.Ager != nil {
|
||||
hearer.Ager.Runs, hearer.Ager.RunOutputs, hearer.Ager.RunsKept = runs, objects.Delete, settings.Kept
|
||||
hearer.Ager.Runs, hearer.Ager.RunOutputs, hearer.Ager.RunsKept, hearer.Ager.Clock = runs, objects.Delete, settings.Kept, runs
|
||||
hearer.Ager.RunsFill = starter.TestRunsFill
|
||||
}
|
||||
logf("test runs: cap %d bytes, kept %s, step bound %s, untaken bound %s", settings.CapBytes, settings.Kept, settings.StepBound, settings.Untaken)
|
||||
logf("test runs: the cap is the bucket's max bytes, kept %s, step bound %s, untaken bound %s", settings.Kept, settings.StepBound, settings.Untaken)
|
||||
return kv, objects, nil
|
||||
}
|
||||
|
||||
+19
-14
@@ -40,8 +40,9 @@ import (
|
||||
// a run that keeps saying its progress past its bound is not ended,
|
||||
// and a taken ask silent for its bound ends could not run with its readers, its ask dropped; a second revision with the
|
||||
// same digests asks its own runs; a seat the seat-holders view names no holder for ends its pipeline failed at once, its
|
||||
// other steps not asked (A-470g, A-470h); the process answers test-runs with its fill against test-runs-cap-mib and
|
||||
// test-runs-drop deletes the key and its output object (A-470i); at the cap a step ends could not run, naming the fill.
|
||||
// other steps not asked (A-470g, A-470h); the process answers test-runs with its fill against the bucket's max bytes and
|
||||
// test-runs-drop deletes the key and its output object (A-470i); at nine tenths of the bucket a step's end ages the oldest
|
||||
// ended runs, said in one journal line (H-A-510).
|
||||
// The step bound is two seconds here, as the setting test-step-bound names it, where the mesh's is 30 minutes.
|
||||
func TestTestRunsAreAskedOncePerLevelAndMoveEveryReader(t *testing.T) {
|
||||
url := testbus.URL(t)
|
||||
@@ -63,8 +64,9 @@ func TestTestRunsAreAskedOncePerLevelAndMoveEveryReader(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
for _, state := range []string{"bounds", TestRunsState} {
|
||||
if _, err := js.CreateKeyValue(ctx, jetstream.KeyValueConfig{Bucket: module + "_" + state, History: 1, LimitMarkerTTL: time.Minute}); err != nil {
|
||||
// test-runs is 1 MiB here, as the manifest's max-mib makes its bucket: its cap (H-A-510 addendum).
|
||||
for state, max := range map[string]int64{"bounds": 0, TestRunsState: 1 << 20} {
|
||||
if _, err := js.CreateKeyValue(ctx, jetstream.KeyValueConfig{Bucket: module + "_" + state, History: 1, LimitMarkerTTL: time.Minute, MaxBytes: max}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
@@ -75,7 +77,10 @@ func TestTestRunsAreAskedOncePerLevelAndMoveEveryReader(t *testing.T) {
|
||||
if _, err := js.CreateStream(ctx, jetstream.StreamConfig{Name: buscompose.LogStreamName(module, seat.StateStepLog), Subjects: []string{buscompose.LogSubject(module, seat.StateStepLog) + ".>"}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
events, err := js.CreateStream(ctx, jetstream.StreamConfig{Name: process.EventsStream, Subjects: []string{"mesh.mod.*.event.>", "mesh.seat.*.event.>", "mesh.stream.*.event.>"}})
|
||||
// The runner's findings ride its own stream, as its manifest declares, never EVENTS: on EVENTS each one would reach its
|
||||
// main durable unhandled and write event-unhandled again, a flood a take-in on its own durable overtakes (H-A-500 (b)).
|
||||
findingsStream(t, ctx, js, module)
|
||||
events, err := js.CreateStream(ctx, jetstream.StreamConfig{Name: process.EventsStream, Subjects: []string{"mesh.mod.*.event.>", "mesh.seat.*.event.>"}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -201,10 +206,10 @@ func TestTestRunsAreAskedOncePerLevelAndMoveEveryReader(t *testing.T) {
|
||||
return out
|
||||
}
|
||||
|
||||
// The settings, as the manifest's resources write them (A-469x): a cap of 1 MiB, a step bound of two seconds; the
|
||||
// The settings, as the manifest's resources write them (A-469x): a step bound of two seconds; the
|
||||
// candidates' pipelines run side by side, so pipelines-at-once is its most, 8 (§748).
|
||||
dir := t.TempDir()
|
||||
files := map[string]string{envRunsCap: "1", envStepBound: "2s", envPipelinesAtOnce: "8"}
|
||||
files := map[string]string{envStepBound: "2s", envPipelinesAtOnce: "8"}
|
||||
env := map[string]string{}
|
||||
for name, content := range files {
|
||||
path := filepath.Join(dir, name)
|
||||
@@ -224,6 +229,7 @@ func TestTestRunsAreAskedOncePerLevelAndMoveEveryReader(t *testing.T) {
|
||||
runCtx, stop := context.WithCancel(ctx)
|
||||
done := make(chan error, 1)
|
||||
go func() { done <- run(runCtx, func(k string) string { return env[k] }, logs) }()
|
||||
takeInsHeard(t, ctx, logs)
|
||||
return func() { stop(); <-done }
|
||||
}
|
||||
stop := start()
|
||||
@@ -548,7 +554,7 @@ func TestTestRunsAreAskedOncePerLevelAndMoveEveryReader(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// test-runs is answered by the process, its fill against test-runs-cap-mib (A-470i), each run's packages from its output
|
||||
// test-runs is answered by the process, its fill against the bucket's max bytes (A-470i, H-A-510), each run's packages from its output
|
||||
// object; test-runs-drop deletes the key and its object (§728).
|
||||
var runs seat.TestRunsAnswer
|
||||
if e := call(seat.VerbTestRuns, seat.TestRunsInput{Candidate: "main.1"}, &runs); e != "" || len(runs.Runs) != 2 || runs.Fill.Cap != 1<<20 || runs.Fill.Store != TestRunsState {
|
||||
@@ -572,8 +578,8 @@ func TestTestRunsAreAskedOncePerLevelAndMoveEveryReader(t *testing.T) {
|
||||
t.Error("the dropped run's output object is kept")
|
||||
}
|
||||
|
||||
// At the cap a step ends could not run, naming the fill (§725, A-469d).
|
||||
pad := make([]byte, 600<<10)
|
||||
// At nine tenths of the bucket a step's end ages the oldest ended runs, said in one journal line (H-A-510).
|
||||
pad := make([]byte, 470<<10)
|
||||
for _, k := range []string{"pad.a", "pad.b"} {
|
||||
if _, err := runsKV.Put(ctx, k, pad); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -583,10 +589,9 @@ func TestTestRunsAreAskedOncePerLevelAndMoveEveryReader(t *testing.T) {
|
||||
publish(catalog.SubjectCatalogRevision("main"), catalog.CatalogRevisionEvent{V: 1, Revision: 4, Kind: "trunk", Branch: "main", Source: 6})
|
||||
const p6 = "main.4"
|
||||
takeIn("app", "c1", "src2:aa", 6, 4)
|
||||
waitFor(t, ctx, logs, func() bool {
|
||||
s := step(read(p6), "app:program", "unit")
|
||||
return s.Outcome == seat.StepResultOutcomeCouldNotRun && strings.Contains(s.Why, "test-runs-cap-mib")
|
||||
})
|
||||
placed(p6)
|
||||
passBuild(p6, "app", "c1", "src2:aa")
|
||||
waitFor(t, ctx, logs, func() bool { return strings.Contains(logs.String(), "of its 1048576 bytes, nine tenths or more") })
|
||||
}
|
||||
|
||||
func mustJSON(v any) []byte {
|
||||
|
||||
@@ -8,8 +8,8 @@ import (
|
||||
)
|
||||
|
||||
// The test runs' settings reach the process through the files the manifest writes (design 47 G §725; A-469x, A-470a): the
|
||||
// cap a whole number of MiB, the times Go durations, a missing file its default, a content that is neither, or a kept time
|
||||
// past 168h, an error naming the file.
|
||||
// times Go durations, test-runs-kept 48h by default (H-A-510), a missing file its default, a content that is no duration,
|
||||
// or a kept time past 168h, an error naming the file. The cap is no setting: a cap file is not read (H-A-510 addendum).
|
||||
func TestTheTestRunsSettingsAreReadFromTheirFiles(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
write := func(name, content string) string {
|
||||
@@ -23,20 +23,20 @@ func TestTheTestRunsSettingsAreReadFromTheirFiles(t *testing.T) {
|
||||
name string
|
||||
files map[string]string
|
||||
ok bool
|
||||
check func(t *testing.T, cap int64, kept, step, untaken time.Duration)
|
||||
check func(t *testing.T, kept, step, untaken time.Duration)
|
||||
}{
|
||||
{"defaults", nil, true, func(t *testing.T, cap int64, kept, step, untaken time.Duration) {
|
||||
if cap != 16<<20 || kept != 168*time.Hour || step != 30*time.Minute || untaken != 24*time.Hour {
|
||||
t.Errorf("defaults = %d %s %s %s", cap, kept, step, untaken)
|
||||
{"defaults", nil, true, func(t *testing.T, kept, step, untaken time.Duration) {
|
||||
if kept != 48*time.Hour || step != 30*time.Minute || untaken != 24*time.Hour {
|
||||
t.Errorf("defaults = %s %s %s", kept, step, untaken)
|
||||
}
|
||||
}},
|
||||
{"set", map[string]string{envRunsCap: "8\n", envRunsKept: "48h", envStepBound: "2s", envUntakenBound: "1m"}, true,
|
||||
func(t *testing.T, cap int64, kept, step, untaken time.Duration) {
|
||||
if cap != 8<<20 || kept != 48*time.Hour || step != 2*time.Second || untaken != time.Minute {
|
||||
t.Errorf("settings = %d %s %s %s", cap, kept, step, untaken)
|
||||
{"set", map[string]string{envRunsKept: "72h\n", envStepBound: "2s", envUntakenBound: "1m"}, true,
|
||||
func(t *testing.T, kept, step, untaken time.Duration) {
|
||||
if kept != 72*time.Hour || step != 2*time.Second || untaken != time.Minute {
|
||||
t.Errorf("settings = %s %s %s", kept, step, untaken)
|
||||
}
|
||||
}},
|
||||
{"a cap that is no whole number", map[string]string{envRunsCap: "8.5"}, false, nil},
|
||||
{"a cap file is not read", map[string]string{"MESH_RUNNER_TEST_RUNS_CAP_FILE": "8.5"}, true, nil},
|
||||
{"a time that is no duration", map[string]string{envStepBound: "30"}, false, nil},
|
||||
{"kept past its maximum", map[string]string{envRunsKept: "169h"}, false, nil},
|
||||
}
|
||||
@@ -51,7 +51,7 @@ func TestTheTestRunsSettingsAreReadFromTheirFiles(t *testing.T) {
|
||||
t.Fatalf("runSettings = %+v, %v", s, err)
|
||||
}
|
||||
if r.check != nil {
|
||||
r.check(t, s.CapBytes, s.Kept, s.StepBound, s.Untaken)
|
||||
r.check(t, s.Kept, s.StepBound, s.Untaken)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ func writeHandlers(v pipeline.Verbs) map[string]process.SeatHandler {
|
||||
seat.VerbAskAgain: verbOf(func(c string, in seat.AskAgainInput) (any, error) { return v.AskAgain(c, in) }),
|
||||
// §728, A-469g: a test run's drop is answered by the process, the only writer of pipelines and test-runs.
|
||||
seat.VerbTestRunsDrop: verbOf(func(c string, in seat.TestRunsDropInput) (any, error) { return v.TestRunsDrop(c, in) }),
|
||||
// A-470i: test-runs too, since the process holds test-runs-cap-mib, the cap its fill is said against.
|
||||
// A-470i: test-runs too, since the process reads its fill against the bucket's max bytes (H-A-510).
|
||||
seat.VerbTestRuns: verbOf(func(_ string, in seat.TestRunsInput) (any, error) { return v.Runs.TestRuns(in) }),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -150,10 +151,17 @@ func catalogRevision(call func(string, any) (json.RawMessage, error), kept *revi
|
||||
for {
|
||||
raw, err := call("seat:"+catalog.Seat+"."+catalog.VerbRevision, in)
|
||||
if err != nil {
|
||||
// A revision the catalog answers "no such object" for is gone (design 47 H2 H-A-496): a kept mover's wait on it ends.
|
||||
if strings.Contains(err.Error(), "no such object") {
|
||||
return pipeline.Half{}, fmt.Errorf("%w: %v", pipeline.ErrRevisionGone, err)
|
||||
}
|
||||
return pipeline.Half{}, err
|
||||
}
|
||||
answer, said, ok := buscalls.Unwrap(raw)
|
||||
if !ok {
|
||||
if strings.Contains(said, "no such object") {
|
||||
return pipeline.Half{}, fmt.Errorf("%w: %s answered: %s", pipeline.ErrRevisionGone, catalog.VerbRevision, said)
|
||||
}
|
||||
return pipeline.Half{}, fmt.Errorf("%s answered: %s", catalog.VerbRevision, said)
|
||||
}
|
||||
var a catalog.RevisionAnswer
|
||||
|
||||
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -63,6 +64,19 @@ func TestCatalogRevisionIsKeptOnceRead(t *testing.T) {
|
||||
if h, err := read("main", 0); err != nil || calls != 3 || len(h.Entries) != 2 {
|
||||
t.Fatalf("the newest made calls %d, %+v, %v; want its first page only", calls, h, err)
|
||||
}
|
||||
// A revision the catalog answers "no such object" for is gone, whether refused or answered so (design 47 H2 H-A-496).
|
||||
for _, gone := range []func(string, any) (json.RawMessage, error){
|
||||
func(string, any) (json.RawMessage, error) {
|
||||
return nil, fmt.Errorf("revision main.292: no such object")
|
||||
},
|
||||
func(string, any) (json.RawMessage, error) {
|
||||
return json.RawMessage(`{"content":[{"text":"revision main.292: no such object"}],"isError":true}`), nil
|
||||
},
|
||||
} {
|
||||
if _, err := catalogRevision(gone, newRevisionCache(1))("main", 292); !errors.Is(err, pipeline.ErrRevisionGone) {
|
||||
t.Errorf("a revision the catalog has no object of reads %v, want it gone", err)
|
||||
}
|
||||
}
|
||||
c := newRevisionCache(1)
|
||||
c.put("main", pipeline.Half{Revision: 1})
|
||||
c.put("main", pipeline.Half{Revision: 2})
|
||||
|
||||
@@ -57,7 +57,12 @@ type Ager struct {
|
||||
Runs TestRuns
|
||||
RunOutputs func(name string) error
|
||||
RunsKept time.Duration
|
||||
Now func() time.Time
|
||||
// RunsFill is test-runs' fill against its bucket's max bytes (Starter.TestRunsFill): at nine tenths of it the oldest
|
||||
// ended runs are deleted, their outputs with them, until it is under eight tenths (H-A-510); nil ages by time only.
|
||||
RunsFill func() (seat.Fill, error)
|
||||
// Clock is test-runs' bound and ask keys: a run's ask keys are deleted with the run (H-A-500 addendum (1)); nil keeps them.
|
||||
Clock RunClock
|
||||
Now func() time.Time
|
||||
// Logf is the runner's journal: each delete writes a line naming the key or object and its retention.
|
||||
Logf func(string, ...any)
|
||||
}
|
||||
@@ -82,13 +87,97 @@ func (a *Ager) Age() {
|
||||
}
|
||||
retentions = append([]Retention{{RetentionTestRuns, kept}}, retentions...)
|
||||
}
|
||||
for _, r := range retentions {
|
||||
for i, r := range retentions {
|
||||
if err := a.ageAt(r); err != nil {
|
||||
a.logf("aged: the data past %s are not aged: %v", r.Name, err)
|
||||
}
|
||||
// By fill after by time, before the pipelines age, so the pipeline that names a run's key is still kept.
|
||||
if i == 0 && a.Runs != nil {
|
||||
if err := a.ageByFill(); err != nil {
|
||||
a.logf("aged: the test runs are not aged by their fill: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The fill of test-runs, in tenths of its cap, at which the Ager deletes its oldest ended runs and under which it stops
|
||||
// (H-A-510).
|
||||
const (
|
||||
runsFillAgeTenths = 9
|
||||
runsFillUnderTenths = 8
|
||||
)
|
||||
|
||||
// ageByFill deletes the oldest ended test runs, with their output objects, once test-runs holds nine tenths of its cap,
|
||||
// until it holds under eight tenths (H-A-510): in the step log's order onward from the test runs' retention, as the Ager
|
||||
// ages by time (§330), so nothing is scanned whole; a run not ended is never deleted. It says how many and how old in one
|
||||
// journal line.
|
||||
func (a *Ager) ageByFill() error {
|
||||
if a.RunsFill == nil {
|
||||
return nil
|
||||
}
|
||||
f, err := a.RunsFill()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if f.Cap <= 0 || f.Bytes*10 < f.Cap*runsFillAgeTenths {
|
||||
return nil
|
||||
}
|
||||
now := time.Now().UTC()
|
||||
if a.Now != nil {
|
||||
now = a.Now().UTC()
|
||||
}
|
||||
held := f.Bytes
|
||||
last, err := a.Aged.Get(RetentionTestRuns)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
moved, deleted := last, 0
|
||||
var oldest, newest time.Time
|
||||
defer func() {
|
||||
if moved != last {
|
||||
if err := a.Aged.Put(RetentionTestRuns, moved); err != nil {
|
||||
a.logf("aged: the test runs' retention is not moved to %d: %v", moved, err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
for f.Bytes*10 >= f.Cap*runsFillUnderTenths {
|
||||
entries, err := a.Log(moved+1, AgedPerStep)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(entries) == 0 {
|
||||
break
|
||||
}
|
||||
for _, e := range entries {
|
||||
moved = e.Sequence
|
||||
_, ended, ok := a.deleteRun(e.Entry)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
deleted++
|
||||
if oldest.IsZero() || ended.Before(oldest) {
|
||||
oldest = ended
|
||||
}
|
||||
if ended.After(newest) {
|
||||
newest = ended
|
||||
}
|
||||
if f, err = a.RunsFill(); err != nil {
|
||||
return err
|
||||
}
|
||||
if f.Bytes*10 < f.Cap*runsFillUnderTenths {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if deleted == 0 {
|
||||
a.logf("aged: the state test-runs holds %d of its %d bytes, nine tenths or more, and no ended test run is left to delete in the step log", held, f.Cap)
|
||||
return nil
|
||||
}
|
||||
a.logf("aged: the state test-runs held %d of its %d bytes, nine tenths or more, so %d ended test runs and their outputs were deleted, ended %s to %s ago; it holds %d bytes now",
|
||||
held, f.Cap, deleted, now.Sub(oldest).Round(time.Second), now.Sub(newest).Round(time.Second), f.Bytes)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *Ager) ageAt(r Retention) error {
|
||||
now := time.Now().UTC()
|
||||
if a.Now != nil {
|
||||
@@ -120,14 +209,21 @@ func (a *Ager) ageAt(r Retention) error {
|
||||
const RetentionTestRuns = "test-runs"
|
||||
|
||||
// ageRun deletes the test run the ended step of e read, and its output object, once its kept time has passed since the
|
||||
// step's end, in the step log's order (§725, A-470a): the run's key is read from e's pipeline, its step's Shared run.
|
||||
// step's end, in the step log's order (§725, A-470a), said in a line.
|
||||
func (a *Ager) ageRun(r Retention, e seat.LogEntry) {
|
||||
if e.What != seat.LogEntryWhatEnded {
|
||||
return
|
||||
if run, _, ok := a.deleteRun(e); ok {
|
||||
a.logf("aged: deleted the test run %s and its output (%s after its end)", run, r.Age)
|
||||
}
|
||||
p, _, err := a.Pipelines.Get(e.Pipeline)
|
||||
}
|
||||
|
||||
// runOfEntry is the run the ended step of e read: its step's Shared run in e's pipeline, empty when it reads none.
|
||||
func runOfEntry(pipelines Updater, e seat.LogEntry) string {
|
||||
if e.What != seat.LogEntryWhatEnded {
|
||||
return ""
|
||||
}
|
||||
p, _, err := pipelines.Get(e.Pipeline)
|
||||
if err != nil {
|
||||
return
|
||||
return ""
|
||||
}
|
||||
run := ""
|
||||
for _, s := range p.Steps {
|
||||
@@ -135,20 +231,27 @@ func (a *Ager) ageRun(r Retention, e seat.LogEntry) {
|
||||
run = sharedRun(s)
|
||||
}
|
||||
}
|
||||
return run
|
||||
}
|
||||
|
||||
// deleteRun deletes the ended test run the ended step of e read, and its output object, and answers its end: the run's key
|
||||
// is read from e's pipeline, its step's Shared run. A run not ended is kept, and so is one whose output is not deleted.
|
||||
func (a *Ager) deleteRun(e seat.LogEntry) (string, time.Time, bool) {
|
||||
run := runOfEntry(a.Pipelines, e)
|
||||
if run == "" {
|
||||
return
|
||||
return run, time.Time{}, false
|
||||
}
|
||||
for {
|
||||
t, rev, err := a.Runs.Get(run)
|
||||
// The entry is past the retention (ageAt), and a run ends no later than the reader's end it was read at: a run not
|
||||
// ended yet is aged at a later reader's end.
|
||||
if err != nil || t.Ended == nil {
|
||||
return
|
||||
return run, time.Time{}, false
|
||||
}
|
||||
if t.Output != "" && a.RunOutputs != nil {
|
||||
if err := a.RunOutputs(t.Output); err != nil {
|
||||
a.logf("aged: the output %s of the test run %s is not deleted, so the run is kept: %v", t.Output, run, err)
|
||||
return
|
||||
return run, time.Time{}, false
|
||||
}
|
||||
}
|
||||
// Deleted at the revision read: a rerun that wrote the key again since is read again, and a run it started is kept.
|
||||
@@ -156,10 +259,10 @@ func (a *Ager) ageRun(r Retention, e seat.LogEntry) {
|
||||
continue
|
||||
} else if err != nil {
|
||||
a.logf("aged: the test run %s is not deleted: %v", run, err)
|
||||
return
|
||||
return run, time.Time{}, false
|
||||
}
|
||||
a.logf("aged: deleted the test run %s and its output (%s after its end)", run, r.Age)
|
||||
return
|
||||
unmarkAsks(a.Clock, run, a.logf)
|
||||
return run, *t.Ended, true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -53,10 +53,19 @@ func TestAnAsksBoundCountsFromThePullAndEndsItsStep(t *testing.T) {
|
||||
}
|
||||
p.Steps[stepIndex(p, "lint", "app:program")].Outcome = seat.StepResultOutcomeFailed
|
||||
store.Update(pkey, p, rev)
|
||||
old := p.Steps[stepIndex(p, "lint", "app:program")].Ask
|
||||
_ = v.Hearer.Clock.MarkAsk(old, AskMark{Pipeline: pkey, Module: "app", Step: "lint"})
|
||||
r, err := v.Rerun("operator", seat.RerunInput{Pipeline: pkey, Step: "lint", Artifact: "app:program", Why: "retry"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// The step asked again keeps one ask key, its new ask's: the earlier one is deleted (H-A-506 addendum).
|
||||
if _, had, _ := v.Hearer.Clock.AskOf(old); had {
|
||||
t.Errorf("the ask key of the earlier ask %s outlives the rerun", old)
|
||||
}
|
||||
if m, ok, _ := v.Hearer.Clock.AskOf(r.Result.Ask); !ok || m.Pipeline != pkey || m.Step != "lint" {
|
||||
t.Errorf("the rerun's ask key = %+v, %v; want it naming %s's lint step", m, ok, pkey)
|
||||
}
|
||||
ask, key := r.Result.Ask, AskBoundKey(nodebuildgo.Seat, r.Result.Ask)
|
||||
if want := []string{key + " 10m0s"}; !slices.Equal(armed, want) || len(asks.ids) != 1 {
|
||||
t.Fatalf("armed %v asking %v, want %v before one ask", armed, asks.ids, want)
|
||||
@@ -110,15 +119,17 @@ func TestAnAsksBoundCountsFromThePullAndEndsItsStep(t *testing.T) {
|
||||
if !slices.Equal(raised, []string{nodebuildgo.Seat + " " + ask}) || !slices.Contains(*said, "pipeline-ended.main.5") {
|
||||
t.Errorf("raised %v, said %v", raised, *said)
|
||||
}
|
||||
// A bound whose step ended asks nothing; the step's end deletes the bound; a late ask-taken clears the finding.
|
||||
// A bound whose step ended asks nothing; the step's end deletes the bound; a late ask-taken after the pipeline's
|
||||
// end clears nothing: the end deleted the ask's key, so the finding stands as what happened (H-A-506 second
|
||||
// addendum; H-A-238 (2) holds while the pipeline runs).
|
||||
if err := v.AskUnanswered(nodebuildgo.Seat, ask); err != nil || len(asks.ids) != 1 || len(dropped) != 1 {
|
||||
t.Errorf("a bound of an ended step asked %v, dropped %v (%v)", asks.ids, dropped, err)
|
||||
}
|
||||
if err := c.Ended(nodebuildgo.Seat, ask); err != nil || !slices.Equal(unbound, []string{key}) {
|
||||
t.Errorf("the step's end deleted %v (%v)", unbound, err)
|
||||
}
|
||||
if _, err := v.Hearer.Taken(ask, "n2", now); err != nil || !slices.Equal(cleared, []string{nodebuildgo.Seat + " " + ask}) {
|
||||
t.Errorf("a late ask-taken cleared %v (%v)", cleared, err)
|
||||
if _, err := v.Hearer.Taken(ask, "n2", now); err != nil || len(cleared) != 0 {
|
||||
t.Errorf("a late ask-taken after the pipeline's end cleared %v (%v), want nothing", cleared, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -99,6 +99,7 @@ func (h *Hearer) putDeclined(key, old string, s seat.StepResult, a Asked, ev Ste
|
||||
break
|
||||
}
|
||||
}
|
||||
unmarkAsk(h.Clock, old, h.logf) // one key per ask, gone once the ask is no longer open (H-A-506 addendum, corrected)
|
||||
h.logf("%s: the %s step of %s was declined on %s (%s): asked again as %s, not on %s (H-A-445)", key, s.Step,
|
||||
strings.TrimSpace(s.Module+" "+s.Artifact), ev.Node, ev.Said, a.ID, strings.Join(s.NotOn, ", "))
|
||||
return h.PutAgain(key, a)
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
package pipeline
|
||||
|
||||
import (
|
||||
"slices"
|
||||
|
||||
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner"
|
||||
wants "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||
)
|
||||
|
||||
// dropSeat says whether the holder of a seat serves the seat's drop of an ask the runner put on it: every seat whose
|
||||
// holder says ask-taken, the three build seats, mesh-builds and mesh-wants (AskTakenSeats).
|
||||
func dropSeat(name string) bool {
|
||||
for _, s := range AskTakenSeats {
|
||||
if s.Seat == name {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// openAtEnd are copies of the steps of steps that an end of their pipeline takes while still asked (design 47 H2
|
||||
// H-A-506): an open step with an ask of its own, and a step reading a test run, open or waiting, which leaves it. Read
|
||||
// before the end is written, since the end rewrites the steps.
|
||||
func openAtEnd(steps []seat.StepResult) []seat.StepResult {
|
||||
var out []seat.StepResult
|
||||
for _, s := range steps {
|
||||
asked := open(s) && s.Ask != ""
|
||||
reads := sharedRun(s) != "" && s.Seat != wants.Seat && (open(s) || s.Outcome == seat.StepResultOutcomeWaiting)
|
||||
if asked || reads {
|
||||
out = append(out, s)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// DropOpen takes the steps of pipeline key that its end took while asked (openAtEnd) off the seats (design 47 H2
|
||||
// H-A-506 as corrected): a step reading a test run leaves it (leaveRun), the run's ask dropped only by its last reader's
|
||||
// leave; every other own ask still open, a mesh-wants step's included, is dropped through its seat's drop, so its holder
|
||||
// refuses it unrun and no build capacity goes to an ended pipeline. Each drop and each refusal is said in one journal line
|
||||
// per ask; a drop that is not answered fails nothing. The leaves are written before it answers; the drops are asked beside
|
||||
// the path that ended the pipeline (Aside), since a seat with no holder answers a kept call only at its bound, so a cancel
|
||||
// is answered at once whatever its seats.
|
||||
func (h *Hearer) DropOpen(key string, steps []seat.StepResult, why string) {
|
||||
done := map[string]bool{}
|
||||
var drops []seat.StepResult
|
||||
for _, st := range steps {
|
||||
if sharedRun(st) != "" && st.Seat != wants.Seat {
|
||||
// A shared test run's ask is dropped only by its last reader's leave, never while another pipeline reads it
|
||||
// (H-A-506 corrected).
|
||||
h.leaveRun(key, st, why)
|
||||
continue
|
||||
}
|
||||
if !open(st) || st.Ask == "" || done[st.Ask] || !dropSeat(st.Seat) {
|
||||
continue
|
||||
}
|
||||
done[st.Ask] = true
|
||||
if h.DropRun == nil {
|
||||
h.logf("%s: the ask %s of %s's %s on %s is not dropped: the runner has no drop (H-A-506)", key, st.Ask, st.Module, st.Step, st.Seat)
|
||||
continue
|
||||
}
|
||||
drops = append(drops, st)
|
||||
}
|
||||
for _, st := range drops {
|
||||
h.aside(func() {
|
||||
if err := h.DropRun(st.Seat, st.Node, st.Ask, why); err != nil {
|
||||
h.logf("%s: the drop of the ask %s of %s's %s is refused or not answered by %s: %v (H-A-506)", key, st.Ask, st.Module, st.Step, st.Seat, err)
|
||||
return
|
||||
}
|
||||
h.logf("%s: the ask %s of %s's %s on %s is dropped (H-A-506)", key, st.Ask, st.Module, st.Step, st.Seat)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// aside runs do through Aside, in place when there is none.
|
||||
func (h *Hearer) aside(do func()) {
|
||||
if h.Aside == nil {
|
||||
do()
|
||||
return
|
||||
}
|
||||
h.Aside(do)
|
||||
}
|
||||
|
||||
// endedOpen are the steps of prior, a pipeline's steps read before a placing that ended it, which the end took while asked
|
||||
// (openAtEnd): those no longer open in steps, the steps as written, the same index naming the same step since a placing only
|
||||
// appends. An ask in unput, placed but never put, is no ask of a seat and is left out.
|
||||
func endedOpen(prior, steps []seat.StepResult, unput []Asked) []seat.StepResult {
|
||||
var out []seat.StepResult
|
||||
for i, s := range prior {
|
||||
if i >= len(steps) || open(steps[i]) || len(openAtEnd([]seat.StepResult{s})) == 0 {
|
||||
continue
|
||||
}
|
||||
if s.Ask != "" && slices.ContainsFunc(unput, func(a Asked) bool { return a.ID == s.Ask }) {
|
||||
continue
|
||||
}
|
||||
out = append(out, s)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// dropEnded drops, through Drop, the asks the placing end of pipeline p took while open (H-A-506); a pipeline not ended
|
||||
// drops nothing.
|
||||
func (s *Starter) dropEnded(p seat.Pipeline, prior []seat.StepResult, unput []Asked) {
|
||||
if p.Ended == nil {
|
||||
return
|
||||
}
|
||||
steps := endedOpen(prior, p.Steps, unput)
|
||||
if s.Drop != nil && len(steps) > 0 {
|
||||
s.Drop(p.Pipeline, steps, "the pipeline "+p.Pipeline+" ended "+p.Outcome+": "+p.Why)
|
||||
}
|
||||
// The end cleared these steps' asks, so their ask keys go here, not with the end's own (H-A-506 addendum); a shared
|
||||
// test run's key goes with the run's end (H-A-506 corrected).
|
||||
for _, st := range steps {
|
||||
if sharedRun(st) == "" || st.Seat == wants.Seat { // only a test run's key waits for the run's end
|
||||
unmarkAsk(s.Clock, st.Ask, s.logf)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -223,11 +223,11 @@ func TestAReleasedVersionIsTheMoversVersion(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Design 47 H2 §785: a pipeline of two movers ends with its taken, placed and ended times and each step kind's span, the
|
||||
// Design 47 H2 §785: a pipeline of two movers ends with its sequence (H-A-504 addendum) and its taken, placed and ended times and each step kind's span, the
|
||||
// earliest start and the latest end across its movers; a kind none of whose steps started has none.
|
||||
func TestPipelineEndedCarriesEachStepKindsSpan(t *testing.T) {
|
||||
at := func(m int) *time.Time { v := time.Date(2026, 11, 22, 1, m, 0, 0, time.UTC); return &v }
|
||||
p := seat.Pipeline{Pipeline: "main.7", Started: at(0), Ended: at(30), Outcome: seat.PipelineOutcomePassed,
|
||||
p := seat.Pipeline{Pipeline: "main.7", Seq: 270, Started: at(0), Ended: at(30), Outcome: seat.PipelineOutcomePassed,
|
||||
Movers: []seat.Mover{{Module: "lib", Tier: 1}, {Module: "app", Tier: 2}},
|
||||
Steps: []seat.StepResult{
|
||||
{Module: "lib", Step: seat.StepResultStepBuild, Started: at(2), Ended: at(6)},
|
||||
@@ -236,6 +236,9 @@ func TestPipelineEndedCarriesEachStepKindsSpan(t *testing.T) {
|
||||
{Module: "app", Step: seat.StepResultStepUnit, Started: at(10)},
|
||||
{Module: "app", Step: seat.StepResultStepComposition},
|
||||
}}
|
||||
if seq := pipelineEnded(p).Seq; seq != 270 {
|
||||
t.Errorf("pipeline-ended carries seq %d, want the record's 270 (H-A-504 addendum)", seq)
|
||||
}
|
||||
ph := pipelineEnded(p).Phases
|
||||
if ph == nil || !ph.Taken.Equal(*at(0)) || !ph.Placed.Equal(*at(1)) || !ph.Ended.Equal(*at(30)) {
|
||||
t.Fatalf("phases %+v, want taken 01:00, placed 01:01, ended 01:30", ph)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package pipeline
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
"strings"
|
||||
@@ -53,6 +54,37 @@ func TestAPipelineWithNothingOpenEndsAtOnce(t *testing.T) {
|
||||
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) {
|
||||
@@ -126,4 +158,25 @@ func TestAPipelineWithNothingOpenEndsAtOnce(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
// 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)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -508,6 +508,17 @@ func askAll(asker StepAsker, key string, asks []Asked, recovery func(commit stri
|
||||
return first
|
||||
}
|
||||
|
||||
// armAsk is what askAll does before each ask of pipeline key is put: its ask key is written, naming the pipeline, the step
|
||||
// and the run (H-A-506 addendum), then its bound armed (§778); an ask whose key or bound is not written is not put.
|
||||
func (s *Starter) armAsk(key string) func(Asked) error {
|
||||
return func(a Asked) error {
|
||||
if err := markAsk(s.Clock, key, a); err != nil {
|
||||
return err
|
||||
}
|
||||
return s.Asks.arm(a)
|
||||
}
|
||||
}
|
||||
|
||||
// askedStep is the mover and the step an ask names, read from its body; "-" where it names none (the validate ask names no
|
||||
// mover, H-A-51).
|
||||
func askedStep(a Asked) (mover, step string) {
|
||||
|
||||
@@ -686,6 +686,47 @@ func TestASeatWithNoHolderIsReadFromTheSeatHoldersView(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
// Design 47 H2 H-A-506: a placing that ends the pipeline (a later mover's seat with no holder) drops, through each
|
||||
// seat's drop, every ask an earlier placing put and still open, and never an ask it placed and did not put.
|
||||
{
|
||||
store, asks := memStore{}, &stepAsks{}
|
||||
holders := []string{"mesh-build-go"}
|
||||
var dropped []string
|
||||
s := &Starter{Pipelines: memCreated{store}, Say: func(string, any) error { return nil }, Steps: asks, Name: "the-runner",
|
||||
Registration: func(string) (catalog.Registration, bool) { return reg, true },
|
||||
Holders: func(string) ([]string, bool) { return holders, true },
|
||||
Ended: func(seat.Pipeline, []int) error { return nil },
|
||||
Drop: func(key string, steps []seat.StepResult, why string) {
|
||||
for _, st := range steps {
|
||||
dropped = append(dropped, st.Seat+" "+st.Ask)
|
||||
}
|
||||
}}
|
||||
if ok, err := s.Start(Begin{Branch: "main", Source: 4, Entries: entries, Movers: []seat.Mover{{Module: "app", Commit: "c1", Fingerprint: "src2:aa"}}}); !ok || err != nil {
|
||||
t.Fatalf("start = %v, %v", ok, err)
|
||||
}
|
||||
p, rev, _ := store.Get("main.4")
|
||||
var open []string
|
||||
for _, st := range p.Steps {
|
||||
if st.Ask != "" && st.Outcome == seat.StepResultOutcomeRunning {
|
||||
open = append(open, st.Seat+" "+st.Ask)
|
||||
}
|
||||
}
|
||||
p.Movers = append(p.Movers, seat.Mover{Module: "lib", Commit: "c2", Fingerprint: "src2:bb"})
|
||||
_, _ = store.Update("main.4", p, rev)
|
||||
withLib := map[string]catalog.CatalogEntry{"lib": {Module: "lib", Path: "modules/lib", Artifacts: []catalog.Artifact{{Ref: "lib:program", Language: "go"}}}}
|
||||
for k, e := range entries {
|
||||
withLib[k] = e
|
||||
}
|
||||
holders = nil
|
||||
got, _, _, _, _, err := s.placeOne(store, "main.4", func(seat.Pipeline) bool { return true },
|
||||
func(string) (catalog.Registration, bool) { return reg, true }, func(string) (Half, bool) { return Half{Entries: withLib}, true }, time.Unix(2, 0))
|
||||
if err != nil || got.Outcome != seat.PipelineOutcomeFailed {
|
||||
t.Fatalf("the placing of lib = %s (%s), %v; want the pipeline failed, node-build-go holderless", got.Outcome, got.Why, err)
|
||||
}
|
||||
if len(open) < 3 || !slices.Contains(open, "mesh-wants "+stepNamed(p, "", "composition").Ask) || fmt.Sprint(dropped) != fmt.Sprint(open) {
|
||||
t.Errorf("the placing's end dropped %v, want every ask still open %v, mesh-wants' among them, and none of lib's", dropped, open)
|
||||
}
|
||||
}
|
||||
// Design 47 H2 H-A-445: the nodes that can take a declined step hold every seat named, as the view keys a node seat.
|
||||
view := map[string]json.RawMessage{"node-build-go.ace": json.RawMessage(`{"holders":[{"module":"mesh-build-go"}]}`),
|
||||
"node-build-go.g14": json.RawMessage(`{"holders":[{"module":"mesh-build-go"}]}`), "node-build-node.g14": json.RawMessage(`{"holders":[{"module":"mesh-build-node"}]}`),
|
||||
|
||||
@@ -117,7 +117,7 @@ func (q *Queue) run(key string) (bool, error) {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// next is the sequence the next waiting pipeline gets: queue.next read and written one higher by compare-and-set, from 1.
|
||||
// next is the sequence the next pipeline gets, waiting or placed: queue.next read and written one higher by compare-and-set, from 1.
|
||||
func (q *Queue) next() (int64, error) {
|
||||
for {
|
||||
raw, rev, err := q.Store.Get(seat.QueueByQueueNextKey())
|
||||
@@ -180,23 +180,26 @@ func (s *Starter) sayQueueWait(event string, p seat.Pipeline, at time.Time, how
|
||||
}
|
||||
}
|
||||
|
||||
// queueStart judges a start against the bound (§748): under it, it answers true, the pipeline placed and its running key
|
||||
// written once the pipeline is (ran); over it p gets the next sequence and state waiting, with no step, and its waiting key
|
||||
// is written first, so a key whose pipeline was never written is dropped at its placing; it answers false and that key. A
|
||||
// start with no queue is placed.
|
||||
// queueStart gives p the next sequence of queue.next, whether it waits or is placed at once, so every pipeline's seq grows
|
||||
// across the pipelines of a branch and the assigner writes it as its wants' run (design 47 H2 §813 (1), H-A-504 addendum);
|
||||
// then it judges the start against the bound (§748): under it, it answers true, the pipeline placed and its running key
|
||||
// written once the pipeline is (ran); over it p gets state waiting, with no step, and its waiting key is written first, so a
|
||||
// key whose pipeline was never written is dropped at its placing; it answers false and that key. A start with no queue is
|
||||
// placed.
|
||||
func (s *Starter) queueStart(p *seat.Pipeline) (bool, string, error) {
|
||||
if s.Queue == nil {
|
||||
return true, "", nil
|
||||
}
|
||||
full, err := s.Queue.full()
|
||||
if err != nil || !full {
|
||||
return err == nil, "", err
|
||||
}
|
||||
seq, err := s.Queue.next()
|
||||
if err != nil {
|
||||
return false, "", err
|
||||
}
|
||||
p.Seq, p.Outcome = seq, seat.PipelineOutcomeWaiting
|
||||
p.Seq = seq
|
||||
full, err := s.Queue.full()
|
||||
if err != nil || !full {
|
||||
return err == nil, "", err
|
||||
}
|
||||
p.Outcome = seat.PipelineOutcomeWaiting
|
||||
return false, sequenceKey(seq), s.Queue.wait(seq, p.Pipeline)
|
||||
}
|
||||
|
||||
|
||||
@@ -116,8 +116,9 @@ func TestThePipelinesWaitTheirTurn(t *testing.T) {
|
||||
take := takeIn(t, s, view)
|
||||
take(4, "app")
|
||||
first := len(asks.ids)
|
||||
if p, _, _ := mem.Get("main.4"); p.Outcome != seat.PipelineOutcomeRunning || p.Seq != 0 || first == 0 {
|
||||
t.Fatalf("the first pipeline = %s seq %d with %d asks, want running and asked", p.Outcome, p.Seq, first)
|
||||
if p, _, _ := mem.Get("main.4"); p.Outcome != seat.PipelineOutcomeRunning || p.Seq != 1 || first == 0 {
|
||||
// H-A-504 addendum: a pipeline placed at once has its sequence too
|
||||
t.Fatalf("the first pipeline = %s seq %d with %d asks, want running at 1 and asked", p.Outcome, p.Seq, first)
|
||||
}
|
||||
if _, ok := q["running.main.4"]; !ok {
|
||||
t.Fatalf("the queue = %v, want running.main.4", q)
|
||||
@@ -127,15 +128,15 @@ func TestThePipelinesWaitTheirTurn(t *testing.T) {
|
||||
take(6, "tool")
|
||||
for i, key := range []string{"main.5", "main.6"} {
|
||||
p, _, _ := mem.Get(key)
|
||||
if p.Outcome != seat.PipelineOutcomeWaiting || p.Seq != int64(i+1) || len(p.Steps) != 0 {
|
||||
t.Errorf("%s = %s seq %d with %d steps, want waiting at %d with none", key, p.Outcome, p.Seq, len(p.Steps), i+1)
|
||||
if p.Outcome != seat.PipelineOutcomeWaiting || p.Seq != int64(i+2) || len(p.Steps) != 0 {
|
||||
t.Errorf("%s = %s seq %d with %d steps, want waiting at %d with none", key, p.Outcome, p.Seq, len(p.Steps), i+2)
|
||||
}
|
||||
}
|
||||
if len(asks.ids) != first {
|
||||
t.Errorf("a waiting pipeline asked %d steps", len(asks.ids)-first)
|
||||
}
|
||||
if _, ok := q["waiting.00000000000000000001"]; !ok || string(q["queue.next"].v) != "3" {
|
||||
t.Errorf("the queue = %v, want waiting.<1 in 20 digits> and queue.next 3", q)
|
||||
if _, ok := q["waiting.00000000000000000002"]; !ok || string(q["queue.next"].v) != "4" {
|
||||
t.Errorf("the queue = %v, want waiting.<2 in 20 digits> and queue.next 4", q)
|
||||
}
|
||||
if !slices.Contains(*said, "pipeline-started.main.5") || !slices.Contains(*said, "wait-held.main.5") || len(*waits) != 2 ||
|
||||
(*waits)[0].Step != seat.WaitStepPipeline || (*waits)[0].On != seat.WaitOnPipelinesAtOnce || (*waits)[0].Pipeline != "main.5" {
|
||||
|
||||
@@ -111,6 +111,7 @@ func (s *Starter) keepIn(key string, half Half, movers []seat.Mover) []seat.Move
|
||||
return left
|
||||
}
|
||||
var holderEnded []int
|
||||
prior, unput := slices.Clone(p.Steps), asks
|
||||
if len(asks) > 0 {
|
||||
asks, holderEnded = s.holderless(&p, asks, now)
|
||||
}
|
||||
@@ -126,12 +127,18 @@ func (s *Starter) keepIn(key string, half Half, movers []seat.Mover) []seat.Move
|
||||
s.logf("%s is not written, so the movers revision %d re-pinned stay its own at their old fingerprints: %v", key, half.Revision, err)
|
||||
return left
|
||||
}
|
||||
s.dropEnded(p, prior, unput) // a holderless end drops the asks still open, never one placed and not put (H-A-506)
|
||||
if !keeps {
|
||||
s.logf("%s keeps no kept-revisions, so the pin check of its re-pinned movers reads the pipeline's revision (H-A-285)", key)
|
||||
}
|
||||
s.logf("%s keeps the movers revision %d of its own source %d re-pinned, %s: %d steps ended superseded, %d asked again (H-A-283, H-A-284)",
|
||||
key, half.Revision, half.Source, strings.Join(moved, ", "), len(ended), len(asks))
|
||||
s.sayRePinned(p, kept, revisions, half.Revision)
|
||||
// The re-pin says pipeline-started again with every revision its movers are kept at, so the indexer pins them (design
|
||||
// 47 H2 H-A-496 and its addendum).
|
||||
if keeps {
|
||||
s.sayStartedPipeline(p, now)
|
||||
}
|
||||
for _, st := range ended {
|
||||
if s.Say == nil {
|
||||
break
|
||||
|
||||
@@ -66,7 +66,7 @@ func TestASameSourceRepinKeepsTheMoverInItsPipeline(t *testing.T) {
|
||||
store := &MoverStore{Raw: newMemRaw()}
|
||||
asks := &stepAsks{}
|
||||
var said []seat.StepEvent
|
||||
var repinned []string
|
||||
var repinned, starts []string
|
||||
var left [][]seat.StepResult
|
||||
s := &Starter{Pipelines: store, Store: store, Steps: asks, Name: "the-runner", Now: ticking(), Revision: read,
|
||||
Registration: func(m string) (catalog.Registration, bool) { return reg, m == "app" },
|
||||
@@ -77,6 +77,9 @@ func TestASameSourceRepinKeepsTheMoverInItsPipeline(t *testing.T) {
|
||||
if ev, ok := body.(seat.RePinnedEvent); ok {
|
||||
repinned = append(repinned, fmt.Sprintf("%s %s %s %d", subject, ev.Pipeline, ev.Mover, ev.Revision))
|
||||
}
|
||||
if ev, ok := body.(seat.PipelineStarted); ok {
|
||||
starts = append(starts, fmt.Sprintf("%s %v", ev.Pipeline, ev.Kept))
|
||||
}
|
||||
return nil
|
||||
},
|
||||
Left: func(_ string, leave, drop []seat.StepResult, _ string) { left = append(left, append(leave, drop...)) }}
|
||||
@@ -133,6 +136,11 @@ func TestASameSourceRepinKeepsTheMoverInItsPipeline(t *testing.T) {
|
||||
if kept, err := store.KeptRevisions(key); err != nil || kept["app"] != 11 {
|
||||
t.Errorf("kept-revisions = %v (%v), want app at 11", kept, err)
|
||||
}
|
||||
// design 47 H2 H-A-496 and its addendum: the start names no kept revision, the re-pin says pipeline-started again with
|
||||
// every revision its movers are kept at.
|
||||
if want := []string{key + " []", key + " [11]"}; !slices.Equal(starts, want) {
|
||||
t.Errorf("pipeline-started said %q, want %q", starts, want)
|
||||
}
|
||||
// The pin check reads the kept mover's entry at the revision it was kept at, never the pipeline's.
|
||||
if n, err := s.AskPinHeld(store, key, "app", map[string]string{"git.novox.be/novox/mesh-sdk/go": "v0.1.26", "git.novox.be/novox/x/go": "v0.1.1"}, read); n == 0 || err != nil {
|
||||
after, _, _ := store.Get(key)
|
||||
@@ -149,6 +157,49 @@ func TestASameSourceRepinKeepsTheMoverInItsPipeline(t *testing.T) {
|
||||
if p, _, _ := store.Get(key); !slices.Contains(p.Superseded, "app") {
|
||||
t.Errorf("the new source's revision left app in %s: %v", key, p.Superseded)
|
||||
}
|
||||
t.Run("a holderless end drops the open asks of the movers it keeps", testARepinsHolderlessEndDropsTheOpenAsks)
|
||||
}
|
||||
|
||||
// design 47 H2 H-A-506: a re-pin whose placing ends the pipeline holderless drops, through each seat's drop, every ask still
|
||||
// open of the movers it did not re-pin, and none of the re-pinned mover's new asks, never put.
|
||||
func testARepinsHolderlessEndDropsTheOpenAsks(t *testing.T) {
|
||||
reg, entries, repinned, read := repinFixture()
|
||||
lib := catalog.CatalogEntry{Module: "lib", Path: "modules/lib", Fp: "src2:l1", Artifacts: []catalog.Artifact{{Ref: "lib:program", Language: "go"}}}
|
||||
entries["lib"], repinned["lib"] = lib, lib
|
||||
store := &MoverStore{Raw: newMemRaw()}
|
||||
holders := []string{"mesh-build-go"}
|
||||
var dropped []string
|
||||
s := &Starter{Pipelines: store, Store: store, Steps: &stepAsks{}, Name: "the-runner", Now: ticking(), Revision: read,
|
||||
Registration: func(m string) (catalog.Registration, bool) { return reg, m == "app" || m == "lib" },
|
||||
Say: func(string, any) error { return nil },
|
||||
Holders: func(string) ([]string, bool) { return holders, true },
|
||||
Ended: func(seat.Pipeline, []int) error { return nil },
|
||||
Drop: func(_ string, steps []seat.StepResult, _ string) {
|
||||
for _, st := range steps {
|
||||
dropped = append(dropped, st.Seat+" "+st.Ask)
|
||||
}
|
||||
}}
|
||||
key := Key("main", 10)
|
||||
if ok, err := s.Start(Begin{Branch: "main", Source: 41, Revision: 10, Entries: entries, Movers: []seat.Mover{
|
||||
{Module: "app", Commit: "c1", Fingerprint: "src2:aa", Repository: "o/app"},
|
||||
{Module: "lib", Commit: "c1", Fingerprint: "src2:l1", Repository: "o/lib"}}}); !ok || err != nil {
|
||||
t.Fatalf("start = %v, %v", ok, err)
|
||||
}
|
||||
before, _, _ := store.Get(key)
|
||||
var want []string
|
||||
for _, st := range before.Steps {
|
||||
if st.Module == "lib" && st.Ask != "" && open(st) {
|
||||
want = append(want, st.Seat+" "+st.Ask)
|
||||
}
|
||||
}
|
||||
holders = nil
|
||||
if _, err := s.Revised(revisionEvent(11), read); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
p, _, _ := store.Get(key)
|
||||
if p.Outcome != seat.PipelineOutcomeFailed || len(want) == 0 || fmt.Sprint(dropped) != fmt.Sprint(want) {
|
||||
t.Errorf("the re-pin's holderless end = %s (%s), dropped %v; want failed and lib's open asks %v dropped", p.Outcome, p.Why, dropped, want)
|
||||
}
|
||||
}
|
||||
|
||||
// H-A-286: a kept mover not placed at its keep (its registration arrived later) is placed from the revision it is kept at
|
||||
@@ -255,6 +306,60 @@ func TestAKeptMoverWaitingOnItsRevisionSaysSo(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// design 47 H2 H-A-496: a kept mover whose kept revision the catalog answers "no such object" for waits no longer: the
|
||||
// pipeline ends failed "kept revision 11 gone" at the placing, is said ended, frees its turn, and leaves its mover
|
||||
// unfinished, so it rejoins the next pipeline.
|
||||
func TestAKeptRevisionGoneEndsThePipeline(t *testing.T) {
|
||||
reg, entries, _, read := repinFixture()
|
||||
revision := func(branch string, rev int64) (Half, error) {
|
||||
if rev == 11 {
|
||||
return Half{}, fmt.Errorf("revision main.11: no such object: %w", ErrRevisionGone)
|
||||
}
|
||||
return read(branch, rev)
|
||||
}
|
||||
store := &MoverStore{Raw: newMemRaw()}
|
||||
var turned, ended []string
|
||||
u := memUnfinished{}
|
||||
h := &Hearer{Store: store, Name: "the-runner", Unfinished: &Unfinished{Store: u},
|
||||
Say: func(subject string, body any) error {
|
||||
if ev, ok := body.(seat.PipelineEnded); ok {
|
||||
ended = append(ended, ev.Pipeline+" "+ev.Outcome)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
Turn: func(key string) { turned = append(turned, key) }}
|
||||
registered := false
|
||||
s := &Starter{Pipelines: store, Store: store, Steps: &stepAsks{}, Name: "the-runner", Now: ticking(), Revision: revision,
|
||||
Say: func(string, any) error { return nil }, Ended: h.EndedAtPlacing,
|
||||
Registration: func(m string) (catalog.Registration, bool) { return reg, registered && m == "app" }}
|
||||
key := Key("main", 10)
|
||||
if ok, err := s.Start(Begin{Branch: "main", Source: 41, Revision: 10, Entries: entries,
|
||||
Movers: []seat.Mover{{Module: "app", Commit: "c1", Fingerprint: "src2:aa", Repository: "o/app"}}}); !ok || err != nil {
|
||||
t.Fatalf("start = %v, %v", ok, err)
|
||||
}
|
||||
if n, err := s.Revised(revisionEvent(11), read); n != 0 || err != nil {
|
||||
t.Fatalf("the re-pin started %d (%v)", n, err)
|
||||
}
|
||||
registered = true
|
||||
lagging := func(string) (Half, bool) { return Half{Revision: 10, Source: 41, Entries: entries}, true }
|
||||
if _, err := s.Registered(store, reg, lagging); err != nil {
|
||||
t.Fatalf("the placing: %v", err)
|
||||
}
|
||||
p, _, err := store.Get(key)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if p.Outcome != seat.PipelineOutcomeFailed || p.Ended == nil || !strings.HasPrefix(p.Why, "kept revision 11 gone") {
|
||||
t.Fatalf("the pipeline = %s, %q, ended %v: want failed with kept revision 11 gone", p.Outcome, p.Why, p.Ended)
|
||||
}
|
||||
if !slices.Equal(ended, []string{key + " failed"}) || !slices.Equal(turned, []string{key}) {
|
||||
t.Fatalf("said ended %v, turns freed %v: want %s's end said and its turn freed", ended, turned, key)
|
||||
}
|
||||
if _, held := u[UnfinishedKey("main", "app")]; !held {
|
||||
t.Fatalf("app is not left unfinished, so it rejoins no pipeline: %v", u)
|
||||
}
|
||||
}
|
||||
|
||||
// rawKept reads a memRaw as the reads do.
|
||||
type rawKept struct{ r *memRaw }
|
||||
|
||||
|
||||
@@ -4,23 +4,23 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner"
|
||||
)
|
||||
|
||||
// RunSettings are the runner's settings of its test runs (design 47 G §725; A-469d, A-469w, A-469x): the cap of test-runs
|
||||
// the process judges a write by, how long an ended run is kept, the bound of a taken run's owed progress and the bound of
|
||||
// an ask never taken.
|
||||
// RunSettings are the runner's settings of its test runs (design 47 G §725; A-469d, A-469w, A-469x): how long an ended run
|
||||
// is kept, the bound of a taken run's owed progress and the bound of an ask never taken. test-runs' cap is no setting: it
|
||||
// is its bucket's max bytes, read from the bus (H-A-510 addendum).
|
||||
type RunSettings struct {
|
||||
CapBytes int64
|
||||
Kept time.Duration
|
||||
StepBound time.Duration
|
||||
Untaken time.Duration
|
||||
}
|
||||
|
||||
// The settings' defaults (§725; A-466n, A-466s): 16 MiB, 7 days, 30 minutes, 24 hours.
|
||||
var DefaultRunSettings = RunSettings{CapBytes: 16 << 20, Kept: 7 * 24 * time.Hour, StepBound: 30 * time.Minute, Untaken: 24 * time.Hour}
|
||||
// The settings' defaults (§725; A-466n, A-466s, H-A-510): 48 hours, 30 minutes, 24 hours.
|
||||
var DefaultRunSettings = RunSettings{Kept: 48 * time.Hour, StepBound: 30 * time.Minute, Untaken: 24 * time.Hour}
|
||||
|
||||
// The two bound keys of a test run in test-runs, each with its own time to live (§725; A-468b, A-470): `bound.<run key>`,
|
||||
// written at the build seat's ask-taken of the run's ask and again at each step-progress of it, and `untaken.<run key>`,
|
||||
@@ -54,6 +54,123 @@ type RunClock interface {
|
||||
Has(key string) (bool, error)
|
||||
// Keys are test-runs' keys.
|
||||
Keys() ([]string, error)
|
||||
// MarkAsk writes the ask key of ask (AskKey) holding mark, create-only: one written already is kept (H-A-500 addendum
|
||||
// (1), H-A-506 addendum).
|
||||
MarkAsk(ask string, mark AskMark) error
|
||||
// AskOf reads the ask key of ask: the mark it holds; ok false when it is not written.
|
||||
AskOf(ask string) (mark AskMark, ok bool, err error)
|
||||
}
|
||||
|
||||
// AskPrefix begins the ask key of an ask the runner put, `ask.<ask>` in test-runs, holding its AskMark: written at the put
|
||||
// of every ask, a test run's and every other's, and deleted with its pipeline's end or its run's, so an ask-taken or a
|
||||
// step-progress finds its pipeline, step and run in one read and never lists the pipelines (design 47 H2 H-A-500 addendum
|
||||
// (1), H-A-506 addendum: one key per ask, the test run's ask key of H-A-500 and the ask key of every other ask in one form).
|
||||
const AskPrefix = "ask."
|
||||
|
||||
// AskKey is the ask key of ask.
|
||||
func AskKey(ask string) string { return AskPrefix + ask }
|
||||
|
||||
// IsRunAsk says whether a key of test-runs is an ask key rather than a run.
|
||||
func IsRunAsk(key string) bool { return strings.HasPrefix(key, AskPrefix) }
|
||||
|
||||
// AskMark is what an ask key holds (H-A-506 addendum): the pipeline that put the ask, the mover and the step it asks, and
|
||||
// the test run it asks, empty for an ask of no test run. An ask key written before the addendum holds its run alone.
|
||||
type AskMark struct {
|
||||
Pipeline string `json:"pipeline,omitempty"`
|
||||
Module string `json:"module,omitempty"`
|
||||
Step string `json:"step,omitempty"`
|
||||
Run string `json:"run,omitempty"`
|
||||
}
|
||||
|
||||
// markOf is the mark of ask a, put by the pipeline key.
|
||||
func markOf(key string, a Asked) AskMark {
|
||||
mover, step := askedStep(a)
|
||||
if mover == "-" {
|
||||
mover = ""
|
||||
}
|
||||
return AskMark{Pipeline: key, Module: mover, Step: step, Run: a.Run}
|
||||
}
|
||||
|
||||
// markAsk writes the ask key of ask a of pipeline key before it is put (H-A-506 addendum); a nil clock writes none.
|
||||
func markAsk(clock RunClock, key string, a Asked) error {
|
||||
if clock == nil || a.ID == "" {
|
||||
return nil
|
||||
}
|
||||
if err := clock.MarkAsk(a.ID, markOf(key, a)); err != nil {
|
||||
return fmt.Errorf("the ask key of ask %s of %s is not written: %w", a.ID, key, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// unmarkAsk deletes the ask key of ask, at its pipeline's end or its run's (H-A-506 addendum); one not deleted is said.
|
||||
func unmarkAsk(clock RunClock, ask string, logf func(string, ...any)) {
|
||||
if clock == nil || ask == "" {
|
||||
return
|
||||
}
|
||||
if err := clock.Unbound(AskKey(ask)); err != nil {
|
||||
logf("the ask key of ask %s is not deleted: %v", ask, err)
|
||||
}
|
||||
}
|
||||
|
||||
// unmarkAsks deletes, with the run under run, every ask key holding it (H-A-500 addendum (1)): the ask it names now and each
|
||||
// it was given before (a rerun, a declined step asked again). A key not read or not deleted is said. The Hearer calls it
|
||||
// when a run's last reader leaves, the Ager when a run is aged, so no ask key outlives its run.
|
||||
func unmarkAsks(clock RunClock, run string, logf func(string, ...any)) {
|
||||
if clock == nil {
|
||||
return
|
||||
}
|
||||
all, err := clock.Keys()
|
||||
if err != nil {
|
||||
logf("the ask keys of the deleted test run %s are not listed, so they are kept: %v", run, err)
|
||||
return
|
||||
}
|
||||
for _, k := range all {
|
||||
if !IsRunAsk(k) {
|
||||
continue
|
||||
}
|
||||
if held, ok, err := clock.AskOf(strings.TrimPrefix(k, AskPrefix)); err != nil || !ok || held.Run != run {
|
||||
continue
|
||||
}
|
||||
if err := clock.Unbound(k); err != nil {
|
||||
logf("the ask key %s of the deleted test run %s is not deleted: %v", k, run, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// LateEveryLine is how many late events of ended runs' asks one journal line says (H-A-500 (a)).
|
||||
const LateEveryLine = 100
|
||||
|
||||
// LateRunAsk says whether an event of ask is acknowledged at once, moving nothing (design 47 H2 H-A-500 (a) and its addenda,
|
||||
// H-A-506 addendum): an ask with no ask key, put before the ask keys or of a pipeline or a run already ended, reads nothing
|
||||
// else; an ask of a test run that has ended, or whose run was asked again under another ask since, is read from its ask
|
||||
// key and its run. Both are said in one journal line every LateEveryLine of them. This replaces
|
||||
// H-A-311 (2)'s placing and H-A-238 (2)'s clearing for it. With no clock nothing is judged here.
|
||||
func (h *Hearer) LateRunAsk(event, ask string) bool {
|
||||
if h.Clock == nil || ask == "" {
|
||||
return false
|
||||
}
|
||||
m, ok, err := h.Clock.AskOf(ask)
|
||||
if err != nil {
|
||||
h.logf("the %s of ask %s is acknowledged, moving nothing: its ask key is not read: %v (H-A-506)", event, ask, err)
|
||||
return true
|
||||
}
|
||||
if !ok {
|
||||
if n := atomic.AddInt64(&h.lateRuns, 1); n%LateEveryLine == 0 {
|
||||
h.logf("%d late events acknowledged at once, moving nothing; the last the %s of ask %s, which has no ask key (H-A-500, H-A-506)", n, event, ask)
|
||||
}
|
||||
return true
|
||||
}
|
||||
if m.Run == "" || h.TestRuns == nil {
|
||||
return false
|
||||
}
|
||||
r, _, err := h.TestRuns.Get(m.Run)
|
||||
if err != nil || (r.Ended == nil && r.Ask == ask) {
|
||||
return false
|
||||
}
|
||||
if n := atomic.AddInt64(&h.lateRuns, 1); n%LateEveryLine == 0 {
|
||||
h.logf("%d late events of ended test runs' asks acknowledged at once, moving nothing; the last the %s of ask %s of the test run %s (H-A-500)", n, event, ask, m.Run)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// ParseRunBound reads a key of test-runs as a run's bound: the run's key and whether it is the untaken bound.
|
||||
@@ -73,32 +190,38 @@ func IsRunBound(key string) bool {
|
||||
return ok
|
||||
}
|
||||
|
||||
// runOfAsk is the test run asked under ask: the run its asking step names in Shared, read from the state pipelines.
|
||||
// markOfAsk is the mark of ask, read from its ask key alone, never from the pipelines (H-A-506 addendum); ok false when the
|
||||
// ask has no key, or no clock is held.
|
||||
func (h *Hearer) markOfAsk(ask string) (AskMark, bool) {
|
||||
if h.Clock == nil || ask == "" {
|
||||
return AskMark{}, false
|
||||
}
|
||||
m, ok, err := h.Clock.AskOf(ask)
|
||||
if err != nil {
|
||||
h.logf("the ask key of ask %s is not read, so its event moves nothing: %v", ask, err)
|
||||
return AskMark{}, false
|
||||
}
|
||||
return m, ok
|
||||
}
|
||||
|
||||
// runOfAsk is the test run asked under ask, read from its ask key (H-A-500 addendum (1)).
|
||||
func (h *Hearer) runOfAsk(ask string) (string, bool) {
|
||||
run, _, ok := h.runAndPipelineOfAsk(ask)
|
||||
return run, ok
|
||||
}
|
||||
|
||||
// runAndPipelineOfAsk is runOfAsk with the key of the pipeline whose step asked it.
|
||||
// runAndPipelineOfAsk is runOfAsk with the key of the pipeline that put the ask, both read from its ask key alone (H-A-506
|
||||
// addendum); an ask key written before the addendum names no pipeline, the run's readers then naming every pipeline that
|
||||
// reads it, the asking one among them.
|
||||
func (h *Hearer) runAndPipelineOfAsk(ask string) (string, string, bool) {
|
||||
if h.TestRuns == nil || ask == "" {
|
||||
if h.TestRuns == nil {
|
||||
return "", "", false
|
||||
}
|
||||
pkeys, err := allKeys(h.Store)
|
||||
if err != nil {
|
||||
m, ok := h.markOfAsk(ask)
|
||||
if !ok || m.Run == "" {
|
||||
return "", "", false
|
||||
}
|
||||
for _, key := range pkeys {
|
||||
p, _, err := h.Store.Get(key)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if i := stepOfAsk(p, ask); i >= 0 {
|
||||
run := sharedRun(p.Steps[i])
|
||||
return run, key, run != ""
|
||||
}
|
||||
}
|
||||
return "", "", false
|
||||
return m.Run, m.Pipeline, true
|
||||
}
|
||||
|
||||
// releaseLate places what the end of a step heard late unlocks (H-A-311 (2)): a step-progress or step-end that arrives
|
||||
@@ -254,7 +377,7 @@ func (h *Hearer) TakeUp() (int, error) {
|
||||
ended := 0
|
||||
var first error
|
||||
for _, run := range all {
|
||||
if IsRunBound(run) {
|
||||
if IsRunBound(run) || IsRunAsk(run) {
|
||||
continue
|
||||
}
|
||||
r, _, err := h.TestRuns.Get(run)
|
||||
@@ -283,9 +406,6 @@ func (h *Hearer) TakeUp() (int, error) {
|
||||
func (h *Hearer) runSettings() RunSettings {
|
||||
s := h.Runs
|
||||
d := DefaultRunSettings
|
||||
if s.CapBytes <= 0 {
|
||||
s.CapBytes = d.CapBytes
|
||||
}
|
||||
if s.Kept <= 0 {
|
||||
s.Kept = d.Kept
|
||||
}
|
||||
@@ -337,6 +457,7 @@ func (h *Hearer) EndRun(run string, end seat.TestRun, skip *seat.TestRunReader)
|
||||
h.logf("the bound %s of the ended test run is not deleted: %v", k, err)
|
||||
}
|
||||
}
|
||||
unmarkAsk(h.Clock, r.Ask, h.logf) // the ask key goes with its run's end (H-A-506 addendum)
|
||||
}
|
||||
var first error
|
||||
for _, reader := range r.Readers {
|
||||
@@ -415,21 +536,21 @@ const NoReaderLeft = "no reader is left"
|
||||
// leaveRun takes the step of pipeline key that read or asked a test run out of the run's readers (§726): a step superseded
|
||||
// or cancelled. When no reader is left the run ends `could not run`, naming that (A-469z), and its ask is dropped (§119);
|
||||
// while one is left the ask stays, so a superseded pipeline never takes away another's run. A step of no test run leaves
|
||||
// nothing.
|
||||
func (h *Hearer) leaveRun(key string, s seat.StepResult, why string) {
|
||||
// nothing. It answers the ask whose drop it asked, empty when it asked none.
|
||||
func (h *Hearer) leaveRun(key string, s seat.StepResult, why string) string {
|
||||
run := sharedRun(s)
|
||||
if run == "" || h.TestRuns == nil {
|
||||
return
|
||||
return ""
|
||||
}
|
||||
reader := seat.TestRunReader{Pipeline: key, Artifact: s.Artifact}
|
||||
for {
|
||||
r, rev, err := h.TestRuns.Get(run)
|
||||
if errors.Is(err, ErrNoRun) {
|
||||
return
|
||||
return ""
|
||||
}
|
||||
if err != nil {
|
||||
h.logf("the test run %s is not read, so the step %s of %s does not leave it: %v", run, s.Step, key, err)
|
||||
return
|
||||
return ""
|
||||
}
|
||||
left := r.Readers[:0:0]
|
||||
for _, o := range r.Readers {
|
||||
@@ -438,7 +559,7 @@ func (h *Hearer) leaveRun(key string, s seat.StepResult, why string) {
|
||||
}
|
||||
}
|
||||
if len(left) == len(r.Readers) {
|
||||
return
|
||||
return ""
|
||||
}
|
||||
r.Readers = left
|
||||
// The last to leave ends the run in the same write, so a step joining it after that read finds it ended and asks
|
||||
@@ -452,10 +573,10 @@ func (h *Hearer) leaveRun(key string, s seat.StepResult, why string) {
|
||||
continue
|
||||
} else if err != nil {
|
||||
h.logf("the step %s of %s does not leave the test run %s: %v", s.Step, key, run, err)
|
||||
return
|
||||
return ""
|
||||
}
|
||||
if !last {
|
||||
return
|
||||
return ""
|
||||
}
|
||||
if h.Clock != nil {
|
||||
for _, k := range []string{BoundPrefix + run, UntakenPrefix + run} {
|
||||
@@ -463,13 +584,21 @@ func (h *Hearer) leaveRun(key string, s seat.StepResult, why string) {
|
||||
h.logf("the bound %s of the ended test run is not deleted: %v", k, err)
|
||||
}
|
||||
}
|
||||
unmarkAsk(h.Clock, r.Ask, h.logf) // the ask key goes with its run's end (H-A-506 addendum)
|
||||
}
|
||||
if h.DropRun != nil {
|
||||
if h.DropRun == nil {
|
||||
h.logf("%s: the ask %s of the test run %s, which no reader is left of, is not dropped: the runner has no drop", key, r.Ask, run)
|
||||
return ""
|
||||
}
|
||||
// Asked beside the leave, so a seat with no holder never holds it; one line says what happened (H-A-506).
|
||||
h.aside(func() {
|
||||
if err := h.DropRun(r.Seat, r.Node, r.Ask, why); err != nil {
|
||||
h.logf("the drop of ask %s of the test run %s, which no reader is left of, is not answered: %v", r.Ask, run, err)
|
||||
h.logf("%s: the drop of the ask %s of the test run %s, which no reader is left of, is refused or not answered by %s: %v (H-A-506)", key, r.Ask, run, r.Seat, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
h.logf("%s: the ask %s of the test run %s, which no reader is left of, is dropped on %s (H-A-506)", key, r.Ask, run, r.Seat)
|
||||
})
|
||||
return r.Ask
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -198,6 +198,9 @@ type Starter struct {
|
||||
// Ended says a pipeline that ended at its placing (holderless): the step-ended of each step of steps, then its end
|
||||
// (Hearer.EndedAtPlacing); nil says it in the journal alone.
|
||||
Ended func(p seat.Pipeline, steps []int) error
|
||||
// Drop takes the steps of pipeline key a placing's end took while asked off their seats, each own ask dropped through
|
||||
// its seat's drop and each test run read left (design 47 H2 H-A-506; Hearer.DropOpen); nil drops none.
|
||||
Drop func(key string, steps []seat.StepResult, why string)
|
||||
// Supersede takes out of every older running pipeline of newer's branch each mover whose fingerprint newer moved
|
||||
// (H-A-223; Hearer.SupersedeRunning); nil leaves running pipelines as they are.
|
||||
Supersede func(newer seat.Pipeline)
|
||||
@@ -347,6 +350,27 @@ func (s *Starter) holderless(p *seat.Pipeline, asks []Asked, now time.Time) ([]A
|
||||
return nil, ended
|
||||
}
|
||||
|
||||
// keptGone ends p failed at its placing, "kept revision <r> gone", when the catalog no longer holds revision r a mover of
|
||||
// it is kept at (design 47 H2 H-A-496): each step not ended ends not asked, so its movers, whose steps never ran, are left
|
||||
// unfinished and rejoin the next pipeline (§786), and its end frees its turn under pipelines-at-once. It answers the steps
|
||||
// it ended, none when it had none; the pipeline's Ended says it ended.
|
||||
func keptGone(p *seat.Pipeline, r int64, err error, now time.Time) []int {
|
||||
why := fmt.Sprintf("kept revision %d gone", r)
|
||||
ended := []int{}
|
||||
for i := range p.Steps {
|
||||
st := &p.Steps[i]
|
||||
if !open(*st) && st.Outcome != seat.StepResultOutcomeWaiting {
|
||||
continue
|
||||
}
|
||||
st.Outcome, st.Why, st.Ended, st.Ask, st.Shared = seat.StepResultOutcomeNotAsked, "the pipeline failed: "+why, &now, "", nil
|
||||
p.Unlogged = append(p.Unlogged, endEntry(p.Pipeline, *st, now))
|
||||
ended = append(ended, i)
|
||||
}
|
||||
p.Outcome, p.Why, p.Ended = seat.PipelineOutcomeFailed, fmt.Sprintf("%s (%v)", why, err), &now
|
||||
p.EndCount++
|
||||
return ended
|
||||
}
|
||||
|
||||
// endedAtPlacing says a pipeline holderless ended at placing (A-470h): each step it ended in its step-ended, then the
|
||||
// pipeline's end, through Ended; with none given it is said in the journal alone.
|
||||
func (s *Starter) endedAtPlacing(p seat.Pipeline, steps []int) error {
|
||||
@@ -365,7 +389,7 @@ func (s *Starter) askSteps(key string, asks []Asked) error {
|
||||
var err error
|
||||
if len(asks) > 0 {
|
||||
s.carry(key, asks)
|
||||
err = askAll(s.Steps, key, asks, func(commit string) bool { return s.recovered(key, commit) }, s.Asks.arm, s.logf)
|
||||
err = askAll(s.Steps, key, asks, func(commit string) bool { return s.recovered(key, commit) }, s.armAsk(key), s.logf)
|
||||
}
|
||||
s.sayStarted(key, placed)
|
||||
return err
|
||||
@@ -416,18 +440,36 @@ func (s *Starter) create(key string, p seat.Pipeline) error {
|
||||
return s.Pipelines.Create(key, raw)
|
||||
}
|
||||
|
||||
// started is a pipeline's pipeline-started (§746): its key, branch, source, call, revision and movers.
|
||||
func started(p seat.Pipeline, at time.Time) seat.PipelineStarted {
|
||||
// started is a pipeline's pipeline-started (§746): its key, branch, source, call, revision and movers, and kept, every
|
||||
// catalog revision its movers are kept at (design 47 H2 H-A-496), so the indexer pins each while the pipeline runs.
|
||||
func started(p seat.Pipeline, at time.Time, kept []int64) seat.PipelineStarted {
|
||||
return seat.PipelineStarted{V: 1, At: &at, Pipeline: p.Pipeline, Branch: p.Branch, Source: p.Source, Call: p.Call,
|
||||
Revision: p.Revision, Movers: p.Movers, Published: p.Published, Run: p.Run}
|
||||
Revision: p.Revision, Movers: p.Movers, Published: p.Published, Run: p.Run, Kept: kept}
|
||||
}
|
||||
|
||||
// sayStartedPipeline says p's pipeline-started on <branch>.<revision> (§746).
|
||||
// keptList is every distinct revision of kept-revisions, in order (H-A-496).
|
||||
func keptList(kept map[string]int64) []int64 {
|
||||
var out []int64
|
||||
for _, r := range kept {
|
||||
if r > 0 && !slices.Contains(out, r) {
|
||||
out = append(out, r)
|
||||
}
|
||||
}
|
||||
slices.Sort(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// sayStartedPipeline says p's pipeline-started on <branch>.<revision> (§746), with the revisions its movers are kept at as
|
||||
// its record's kept-revisions holds them (H-A-496): a re-pin says it again with the full list (H-A-496 addendum).
|
||||
func (s *Starter) sayStartedPipeline(p seat.Pipeline, at time.Time) {
|
||||
if s.Say == nil {
|
||||
return
|
||||
}
|
||||
if err := s.Say(runnerclient.RevisionSubject(seat.EventPipelineStarted, p.Branch, subjectRevision(p)), started(p, at)); err != nil {
|
||||
kept, err := keptOfStore(s.Store, p.Pipeline)
|
||||
if err != nil {
|
||||
s.logf("the kept-revisions of %s are not read, so its pipeline-started names no kept revision: %v", p.Pipeline, err)
|
||||
}
|
||||
if err := s.Say(runnerclient.RevisionSubject(seat.EventPipelineStarted, p.Branch, subjectRevision(p)), started(p, at, keptList(kept))); err != nil {
|
||||
s.logf("pipeline-started of %s is not said: %v", p.Pipeline, err)
|
||||
}
|
||||
}
|
||||
@@ -445,6 +487,8 @@ func (s *Starter) placeMovers(p *seat.Pipeline, reg func(module string) (catalog
|
||||
if err != nil {
|
||||
s.logf("the kept-revisions of %s are not read, so its movers are placed as movers not kept: %v", p.Pipeline, err)
|
||||
}
|
||||
var gone int64
|
||||
var goneWhy error
|
||||
all := entries
|
||||
for i, m := range p.Movers {
|
||||
// A mover that left for a newer pipeline is placed there, never here (H-A-223, H-A-361).
|
||||
@@ -460,7 +504,13 @@ func (s *Starter) placeMovers(p *seat.Pipeline, reg func(module string) (catalog
|
||||
entries := all
|
||||
if rev := kept[m.Module]; rev > 0 {
|
||||
var err error
|
||||
if entries, err = s.keptEntries(p.Branch, rev); err != nil {
|
||||
if entries, err = s.keptEntries(p.Branch, rev); errors.Is(err, ErrRevisionGone) {
|
||||
// A kept revision the catalog no longer holds is never read: the pipeline ends failed (H-A-496).
|
||||
if gone == 0 {
|
||||
gone, goneWhy = rev, err
|
||||
}
|
||||
continue
|
||||
} else if err != nil {
|
||||
// It waits for its kept revision to be read, said once and carried on the mover (design 47 H2 §787).
|
||||
if m.Unplaced != seat.MoverUnplacedKeptRevisionUnread || m.Revision != rev {
|
||||
s.logf("%s: %s waits for its kept revision %d to be read (%v)", p.Pipeline, m.Module, rev, err)
|
||||
@@ -520,6 +570,9 @@ func (s *Starter) placeMovers(p *seat.Pipeline, reg func(module string) (catalog
|
||||
}
|
||||
}
|
||||
}
|
||||
if gone > 0 {
|
||||
return nil, unregistered, keptGone(p, gone, goneWhy, now), notAsked
|
||||
}
|
||||
if steps, ended := cycled(p, waits, unregistered, reg, all, now, s.Name); ended {
|
||||
return nil, unregistered, steps, notAsked
|
||||
} else {
|
||||
@@ -628,7 +681,7 @@ func (s *Starter) PutAgain(key string, a Asked) error {
|
||||
return errors.New("the runner puts no ask")
|
||||
}
|
||||
s.carry(key, []Asked{a})
|
||||
return askAll(s.Steps, key, []Asked{a}, func(commit string) bool { return s.recovered(key, commit) }, s.Asks.arm, s.logf)
|
||||
return askAll(s.Steps, key, []Asked{a}, func(commit string) bool { return s.recovered(key, commit) }, s.armAsk(key), s.logf)
|
||||
}
|
||||
|
||||
// validateStep is the index of p's first validate step that names its ask, -1 when it has none.
|
||||
@@ -702,7 +755,7 @@ func (s *Starter) Start(b Begin) (bool, error) {
|
||||
}
|
||||
s.ran(key)
|
||||
s.sayNotAsked(p, notAsked)
|
||||
if len(ended) > 0 {
|
||||
if len(ended) > 0 || p.Ended != nil {
|
||||
return true, s.endedAtPlacing(p, ended)
|
||||
}
|
||||
if s.Steps != nil && len(asks) > 0 {
|
||||
@@ -878,16 +931,19 @@ func (s *Starter) placeWaiting(store Updater, due func(seat.Pipeline) bool, reg
|
||||
if err != nil {
|
||||
note(err)
|
||||
}
|
||||
if n == 0 {
|
||||
// A pipeline its placing ended (a kept revision gone, H-A-496) is said ended though it placed no step.
|
||||
if n == 0 && ended == nil {
|
||||
continue
|
||||
}
|
||||
count++
|
||||
s.logf("%s: %d steps placed from %s (A-327)", key, n, from)
|
||||
// A pipeline whose steps were never asked is started by this placing (A-446a); the pipeline-started of its start,
|
||||
// said already, is said again harmlessly.
|
||||
s.sayStartedPipeline(p, now)
|
||||
if n > 0 {
|
||||
s.logf("%s: %d steps placed from %s (A-327)", key, n, from)
|
||||
// A pipeline whose steps were never asked is started by this placing (A-446a); the pipeline-started of its start,
|
||||
// said already, is said again harmlessly.
|
||||
s.sayStartedPipeline(p, now)
|
||||
}
|
||||
s.sayNotAsked(p, notAsked)
|
||||
if len(ended) > 0 {
|
||||
if ended != nil {
|
||||
if err := s.endedAtPlacing(p, ended); err != nil {
|
||||
note(err)
|
||||
}
|
||||
@@ -926,6 +982,7 @@ func (s *Starter) placeOne(store Updater, key string, due func(seat.Pipeline) bo
|
||||
return p, nil, nil, nil, 0, nil
|
||||
}
|
||||
before, marks := len(p.Steps), unplacedMarks(p)
|
||||
prior := slices.Clone(p.Steps)
|
||||
asks, unregistered, ended, notAsked := s.placeMovers(&p, reg, half.Entries, now)
|
||||
// Until its registration arrives, the pipeline says it waits on it (A-327): a mover with no registration has no step,
|
||||
// and it holds the pipeline's end only while every placed mover's required steps passed (H-A-163, H-A-171).
|
||||
@@ -933,7 +990,7 @@ func (s *Starter) placeOne(store Updater, key string, due func(seat.Pipeline) bo
|
||||
s.logf("%s: %s has no registration yet: its steps wait on its registration, which places them (A-327)", key, m)
|
||||
s.registrationMissing(m, key)
|
||||
}
|
||||
if len(p.Steps) == before {
|
||||
if len(p.Steps) == before && p.Ended == nil {
|
||||
// A mover that now waits for its kept revision, or no longer does, is written so (design 47 H2 §787).
|
||||
if unplacedMarks(p) == marks {
|
||||
return p, nil, nil, nil, 0, nil
|
||||
@@ -951,6 +1008,7 @@ func (s *Starter) placeOne(store Updater, key string, due func(seat.Pipeline) bo
|
||||
} else if err != nil {
|
||||
return p, nil, nil, nil, 0, fmt.Errorf("the placing of %s is not written: %w", key, err)
|
||||
}
|
||||
s.dropEnded(p, prior, nil) // an end at this placing drops the asks its earlier placings put (H-A-506)
|
||||
return p, asks, ended, notAsked, len(p.Steps) - before, nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,6 +194,12 @@ type Hearer struct {
|
||||
// queue (Starter.PutAgain); with either nil a declined step ends could not run.
|
||||
AskDeclined func(p seat.Pipeline, s seat.StepResult, now time.Time) (*Asked, error)
|
||||
PutAgain func(key string, a Asked) error
|
||||
|
||||
// Aside runs do beside the caller's path: the drops of an ended pipeline's open asks, each asked side by side, so an end is
|
||||
// never held by a seat that answers a kept call only at its bound (H-A-506); nil runs it in place.
|
||||
Aside func(do func())
|
||||
// lateRuns counts the late events of ended runs' asks acknowledged at once (LateRunAsk, H-A-500 (a)).
|
||||
lateRuns int64
|
||||
}
|
||||
|
||||
// EndReaders ends each of readers' steps of run with r's result (§725, §726): a step that read an ended run, or the steps
|
||||
@@ -292,7 +298,7 @@ func (h *Hearer) OnStepEndedPinned(bs StepSeat, subject string, ev StepEnded, sh
|
||||
h.logf("the step-ended of ask %s is ignored: its test run %s ended before it (%s)", ev.ID, run, p.Steps[i].Why)
|
||||
}
|
||||
return p, nil
|
||||
case !endOutcome(ev.Outcome):
|
||||
case !endOutcome(ev.Outcome) && !supersededBuild(p.Steps[i], ev.Outcome):
|
||||
return p, fmt.Errorf("%w: ask %s ended %q, not an outcome of step-ended", ErrRefused, ev.ID, ev.Outcome)
|
||||
}
|
||||
now := h.now()
|
||||
@@ -338,6 +344,26 @@ func (h *Hearer) OnStepEndedPinned(bs StepSeat, subject string, ev StepEnded, sh
|
||||
readers = append(readers, endPinHeld(&p, *s, pins, now)...)
|
||||
askHeld = stepPassed(*s) && heldOn(p, s.Module)
|
||||
}
|
||||
// A build ended superseded moves its mover to the newer revision's pipeline, as a newer pipeline taking it does
|
||||
// (H-A-508, H-A-223): its other open steps end superseded, it is kept in the pipeline's superseded, and the pipeline
|
||||
// is judged by its other movers alone; never a failure.
|
||||
var leave, drop []seat.StepResult
|
||||
left := s.Step == seat.StepResultStepBuild && s.Outcome == seat.StepResultOutcomeSuperseded
|
||||
if left {
|
||||
why := "superseded: its build was superseded and its mover left for the newer revision's pipeline (H-A-508): " + s.Why
|
||||
for j := range p.Steps {
|
||||
st := &p.Steps[j]
|
||||
if j == i || st.Module != s.Module || (!open(*st) && st.Outcome != seat.StepResultOutcomeWaiting) {
|
||||
continue
|
||||
}
|
||||
l, d := supersedeStep(&p, st, why, now)
|
||||
leave, drop = append(leave, l...), append(drop, d...)
|
||||
readers = append(readers, j)
|
||||
}
|
||||
if !slices.Contains(p.Superseded, s.Module) {
|
||||
p.Superseded = append(p.Superseded, s.Module)
|
||||
}
|
||||
}
|
||||
if s.Step == seat.StepResultStepValidate {
|
||||
readers = append(readers, sameValidate(&p, i, now)...)
|
||||
var notAsked []int
|
||||
@@ -358,9 +384,14 @@ func (h *Hearer) OnStepEndedPinned(bs StepSeat, subject string, ev StepEnded, sh
|
||||
// A build that passes, a rerun's among them, places again the steps that ended not asked on it (H-A-406): its
|
||||
// dependents need no hand rerun.
|
||||
var again []string
|
||||
if s.Step == seat.StepResultStepBuild && stepPassed(*s) {
|
||||
if s.Step == seat.StepResultStepBuild && (stepPassed(*s) || left) {
|
||||
// A mover that left is no dependency of the movers that stay (H-A-361): theirs ended not asked on it are placed again.
|
||||
named := readerNames(p, readers)
|
||||
if again = takeOutNotAsked(&p, s.Module); len(again) > 0 {
|
||||
release = true
|
||||
// The steps taken out shift the indexes: the step and its readers are found again by their names.
|
||||
i = stepOfAsk(p, ev.ID)
|
||||
s, readers = &p.Steps[i], readerIndexes(p, named)
|
||||
}
|
||||
}
|
||||
ended := h.endPipeline(&p, now, wr)
|
||||
@@ -387,6 +418,11 @@ func (h *Hearer) OnStepEndedPinned(bs StepSeat, subject string, ev StepEnded, sh
|
||||
}
|
||||
}
|
||||
h.Failures.StepEnded(h.Store, p, *s)
|
||||
if left {
|
||||
h.logf("%s: %s's build ended superseded, so it leaves for the newer revision's pipeline, %d of its other steps ended superseded (H-A-508): %s",
|
||||
ev.Pipeline, s.Module, len(readers), s.Why)
|
||||
h.leaveSteps(ev.Pipeline, leave, drop, "the mover %s left "+ev.Pipeline+" for the newer revision's pipeline", "superseded: its build was superseded (H-A-508)")
|
||||
}
|
||||
if err := h.say(seat.EventStepEnded, p, s); err != nil {
|
||||
return p, fmt.Errorf("pipeline %s's %s is written but not said: %w", ev.Pipeline, seat.EventStepEnded, err)
|
||||
}
|
||||
@@ -514,6 +550,13 @@ func (h *Hearer) said(p seat.Pipeline, asked []int, ended bool) error {
|
||||
}
|
||||
h.Failures.Ended(p)
|
||||
h.Unfinished.Ended(p)
|
||||
// Every ask key of its steps goes with the pipeline's end (H-A-506 addendum), but a shared test run's: another
|
||||
// pipeline may still read the run, and its key goes with the run's end (H-A-500 addendum (1), H-A-506 corrected).
|
||||
for _, st := range p.Steps {
|
||||
if sharedRun(st) == "" || st.Seat == wants.Seat { // only a test run's key waits for the run's end
|
||||
unmarkAsk(h.Clock, st.Ask, h.logf)
|
||||
}
|
||||
}
|
||||
if h.RegistrationWaits != nil {
|
||||
h.RegistrationWaits()
|
||||
}
|
||||
@@ -690,7 +733,8 @@ func stepsOf(p seat.Pipeline, module string) []seat.StepResult {
|
||||
return out
|
||||
}
|
||||
|
||||
// pipelineEnded is p's pipeline-ended (design 47 H §746): its key, branch, source, call, revision and outcome, and per
|
||||
// pipelineEnded is p's pipeline-ended (design 47 H §746): its key, branch, source, call, revision, sequence (H2 §813 (1),
|
||||
// H-A-504 addendum) and outcome, and per
|
||||
// mover, in the delivery order of its tiers, its module, fingerprint, commit, widens (H-A-119), released version, step results
|
||||
// and tier; and the movers its end left unfinished (design 47 H2 §786).
|
||||
func pipelineEnded(p seat.Pipeline) seat.PipelineEnded {
|
||||
@@ -701,7 +745,7 @@ func pipelineEnded(p seat.Pipeline) seat.PipelineEnded {
|
||||
}
|
||||
sort.SliceStable(movers, func(i, j int) bool { return movers[i].Tier < movers[j].Tier })
|
||||
return seat.PipelineEnded{V: 1, Pipeline: p.Pipeline, Branch: p.Branch, Source: p.Source, Call: p.Call, Revision: p.Revision,
|
||||
Run: p.Run, Outcome: p.Outcome, Why: p.Why, Started: p.Started, Ended: p.Ended, EndCount: p.EndCount, Movers: movers,
|
||||
Seq: p.Seq, Run: p.Run, Outcome: p.Outcome, Why: p.Why, Started: p.Started, Ended: p.Ended, EndCount: p.EndCount, Movers: movers,
|
||||
Phases: phasesOf(p), Unfinished: unfinishedOf(p)}
|
||||
}
|
||||
|
||||
@@ -753,6 +797,32 @@ func phasesOf(p seat.Pipeline) *seat.PipelineEndedPhases {
|
||||
return ph
|
||||
}
|
||||
|
||||
// supersededBuild says whether o is the outcome superseded of a build step of the seat mesh-builds, the one seat whose end
|
||||
// names it (H-A-508): another seat's end naming it is refused as any outcome the runner does not know.
|
||||
func supersededBuild(st seat.StepResult, o string) bool {
|
||||
return o == builds.StepEndedOutcomeSuperseded && st.Seat == builds.Seat && st.Step == seat.StepResultStepBuild
|
||||
}
|
||||
|
||||
// readerNames are the steps of p at the indexes readers, by module, artifact and step.
|
||||
func readerNames(p seat.Pipeline, readers []int) []string {
|
||||
out := make([]string, 0, len(readers))
|
||||
for _, j := range readers {
|
||||
out = append(out, p.Steps[j].Module+"\x00"+p.Steps[j].Artifact+"\x00"+p.Steps[j].Step)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// readerIndexes are the indexes in p of the steps named, as readerNames names them.
|
||||
func readerIndexes(p seat.Pipeline, names []string) []int {
|
||||
var out []int
|
||||
for j, st := range p.Steps {
|
||||
if slices.Contains(names, st.Module+"\x00"+st.Artifact+"\x00"+st.Step) {
|
||||
out = append(out, j)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func endOutcome(o string) bool {
|
||||
switch o {
|
||||
case nodebuildgo.StepEndedOutcomePassed, nodebuildgo.StepEndedOutcomeFailed, nodebuildgo.StepEndedOutcomeNothingToRun,
|
||||
|
||||
@@ -213,6 +213,34 @@ func TestStepEndedEndsThePipeline(t *testing.T) {
|
||||
t.Errorf("after the second decline: the step %+v, %d puts; want could not run, %q", lint, len(put), want)
|
||||
}
|
||||
})
|
||||
// H-A-506 addendum, corrected: a declined test-run step asked again keeps one ask key, its new ask's; the earlier
|
||||
// ask's key is deleted as it is asked again, not at the run's end.
|
||||
t.Run("declined test run", func(t *testing.T) {
|
||||
h, store, _, _, _ := fixture()
|
||||
h.Asker = nil
|
||||
clock := &clockMem{runs: testRunsMem{}, bound: map[string]time.Duration{}}
|
||||
h.Clock = clock
|
||||
e := store[pkey]
|
||||
e.p.Steps[0].Shared = []seat.Shared{{Run: "main.5.lint.d", Ask: "a1"}}
|
||||
store[pkey] = e
|
||||
_ = clock.MarkAsk("a1", AskMark{Pipeline: pkey, Module: "app", Step: "lint", Run: "main.5.lint.d"})
|
||||
h.NeedNodes = func([]string) ([]string, bool) { return []string{"n1", "n2"}, true }
|
||||
h.AskDeclined = func(_ seat.Pipeline, s seat.StepResult, _ time.Time) (*Asked, error) {
|
||||
return &Asked{Seat: s.Seat, ID: s.Ask + "x", Ask: nodebuildgo.StepAsk{ID: s.Ask + "x"}}, nil
|
||||
}
|
||||
h.PutAgain = func(string, Asked) error { return nil }
|
||||
ev := ended("a1", "lint", nodebuildgo.StepEndedOutcomeDeclined)
|
||||
ev.Node, ev.Needs, ev.Lacks, ev.Said = "n1", []string{"node-build-node"}, []string{"node-build-node"}, "this node lacks node-build-node"
|
||||
if _, err := h.OnStepEnded(goSeat, goSeat.Prefix+"n1", ev); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if lint := store[pkey].p.Steps[0]; lint.Ask != "a1x" {
|
||||
t.Fatalf("the declined test-run step = %+v, want it asked again as a1x", lint)
|
||||
}
|
||||
if _, ok, _ := clock.AskOf("a1"); ok {
|
||||
t.Error("the earlier ask's key of a declined test-run step outlives its ask")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// The approval step is asked last, only when every other required step passed, and ended by its warrant (§26, §37).
|
||||
|
||||
@@ -25,43 +25,44 @@ func (h *Hearer) Taken(ask, node string, at time.Time) (*time.Time, error) {
|
||||
if ask == "" || node == "" {
|
||||
return nil, nil
|
||||
}
|
||||
pkeys, err := allKeys(h.Store)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("the pipelines are not listed: %w", err)
|
||||
// The ask key names the ask's pipeline: that one record is read, never the pipelines list (H-A-506 addendum).
|
||||
m, ok := h.markOfAsk(ask)
|
||||
if !ok || m.Pipeline == "" {
|
||||
return nil, nil
|
||||
}
|
||||
for _, key := range pkeys {
|
||||
for {
|
||||
p, rev, err := h.Store.Get(key)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
i := stepOfAsk(p, ask)
|
||||
if i >= 0 && !open(p.Steps[i]) {
|
||||
h.Asks.answeredLate(p.Steps[i], h.logf)
|
||||
}
|
||||
if i < 0 || !open(p.Steps[i]) {
|
||||
break
|
||||
}
|
||||
s := &p.Steps[i]
|
||||
if s.Node == node && s.TakenAt != nil {
|
||||
return s.TakenAt, nil
|
||||
}
|
||||
s.Node = node
|
||||
if s.TakenAt == nil {
|
||||
if at.IsZero() {
|
||||
at = h.now()
|
||||
}
|
||||
s.TakenAt = ptrTime(at.UTC())
|
||||
}
|
||||
if _, err := h.Store.Update(key, p, rev); errors.Is(err, ErrChanged) {
|
||||
continue
|
||||
} else if err != nil {
|
||||
return nil, fmt.Errorf("pipeline %s cannot be written: %w", key, err)
|
||||
}
|
||||
key := m.Pipeline
|
||||
for {
|
||||
p, rev, err := h.Store.Get(key)
|
||||
if err != nil {
|
||||
return nil, nil
|
||||
}
|
||||
i := stepOfAsk(p, ask)
|
||||
// A late ask-taken clears the finding only while the pipeline runs; after its end the finding stands (H-A-506 second
|
||||
// addendum).
|
||||
if i >= 0 && !open(p.Steps[i]) && p.Outcome == seat.PipelineOutcomeRunning {
|
||||
h.Asks.answeredLate(p.Steps[i], h.logf)
|
||||
}
|
||||
if i < 0 || !open(p.Steps[i]) {
|
||||
return nil, nil
|
||||
}
|
||||
s := &p.Steps[i]
|
||||
if s.Node == node && s.TakenAt != nil {
|
||||
return s.TakenAt, nil
|
||||
}
|
||||
s.Node = node
|
||||
if s.TakenAt == nil {
|
||||
if at.IsZero() {
|
||||
at = h.now()
|
||||
}
|
||||
s.TakenAt = ptrTime(at.UTC())
|
||||
}
|
||||
if _, err := h.Store.Update(key, p, rev); errors.Is(err, ErrChanged) {
|
||||
continue
|
||||
} else if err != nil {
|
||||
return nil, fmt.Errorf("pipeline %s cannot be written: %w", key, err)
|
||||
}
|
||||
return s.TakenAt, nil
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func ptrTime(t time.Time) *time.Time { return &t }
|
||||
|
||||
@@ -3,6 +3,9 @@ package pipeline
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner"
|
||||
|
||||
nodebuildgo "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildgo"
|
||||
)
|
||||
@@ -11,16 +14,46 @@ import (
|
||||
// supersedes it no more (design 47 H §748).
|
||||
func TestATakenAskNamesItsNode(t *testing.T) {
|
||||
h, store, _, _, _ := fixture()
|
||||
clock := &clockMem{runs: testRunsMem{}, bound: map[string]time.Duration{}}
|
||||
h.Clock = clock
|
||||
_ = clock.MarkAsk("a1", AskMark{Pipeline: pkey, Module: "app", Step: "lint"})
|
||||
// The ask key names the pipeline: the ask-taken reads that one record and never lists the pipelines; an ask with no
|
||||
// key reads none (H-A-506 addendum).
|
||||
counted := &countedStore{memStore: store}
|
||||
h.Store = counted
|
||||
if _, err := h.Taken("a1", "n7", h.now()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if p, _, _ := store.Get(pkey); p.Steps[0].Node != "n7" || p.Steps[1].Node != "" {
|
||||
t.Fatalf("after ask-taken of a1 on n7 the steps name %q and %q", p.Steps[0].Node, p.Steps[1].Node)
|
||||
}
|
||||
if counted.gets != 1 || counted.lists != 0 {
|
||||
t.Errorf("the ask-taken of a1 read %d pipelines and listed %d times, want one read and no list", counted.gets, counted.lists)
|
||||
}
|
||||
counted.gets = 0
|
||||
if at, err := h.Taken("a2", "n7", h.now()); err != nil || at != nil || counted.gets != 0 || counted.lists != 0 {
|
||||
t.Errorf("the ask-taken of a2, which has no ask key, = %v, %v, read %d and listed %d; want nothing read", at, err, counted.gets, counted.lists)
|
||||
}
|
||||
}
|
||||
|
||||
// A-222, A-77: a drop is bounded by a key of its own armed before it is asked and deleted when it is answered; one never
|
||||
// answered leaves its key to expire.
|
||||
// countedStore is a memStore that counts its reads and its lists.
|
||||
type countedStore struct {
|
||||
memStore
|
||||
gets, lists int
|
||||
}
|
||||
|
||||
func (c *countedStore) Get(key string) (seat.Pipeline, uint64, error) {
|
||||
c.gets++
|
||||
return c.memStore.Get(key)
|
||||
}
|
||||
|
||||
func (c *countedStore) Keys(filter string) ([]string, error) {
|
||||
c.lists++
|
||||
return c.memStore.Keys(filter)
|
||||
}
|
||||
|
||||
func TestBoundDrop(t *testing.T) {
|
||||
var armed, answered []string
|
||||
arm := func(key string) error { armed = append(armed, key); return nil }
|
||||
|
||||
@@ -206,27 +206,20 @@ func (s *Starter) share(key string, asks []Asked) []Asked {
|
||||
type fullErr struct{ fill seat.Fill }
|
||||
|
||||
func (e *fullErr) Error() string {
|
||||
return fmt.Sprintf("the state %s holds %d of its %d bytes, so no test run is asked (test-runs-cap-mib)", e.fill.Store, e.fill.Bytes, e.fill.Cap)
|
||||
return fmt.Sprintf("the state %s holds %d of its %d bytes, so no test run is asked (its bucket's max-mib)", e.fill.Store, e.fill.Bytes, e.fill.Cap)
|
||||
}
|
||||
|
||||
// TestRunsFill is test-runs' fill against its cap setting test-runs-cap-mib, the cap that refuses a new run (A-469d, A-470i),
|
||||
// never the manifest's ceiling.
|
||||
// TestRunsFill is test-runs' fill against its cap, the bucket's max bytes as the bus says it, the max-mib of the manifest
|
||||
// the runner runs from and never a second number (A-469d, A-470i, H-A-510 and its addendum).
|
||||
func (s *Starter) TestRunsFill() (seat.Fill, error) {
|
||||
if s.RunsFill == nil {
|
||||
return seat.Fill{}, errors.New("the runner reads no fill of test-runs")
|
||||
}
|
||||
f, err := s.RunsFill()
|
||||
if err != nil {
|
||||
return seat.Fill{}, err
|
||||
}
|
||||
f.Cap = s.Runs.CapBytes
|
||||
if f.Cap <= 0 {
|
||||
f.Cap = DefaultRunSettings.CapBytes
|
||||
}
|
||||
return f, nil
|
||||
return s.RunsFill()
|
||||
}
|
||||
|
||||
// atCap is the error of test-runs at its cap setting, nil below it or when its fill is not read (said).
|
||||
// atCap is the error of test-runs full by its bucket's max bytes, nil below it, when its bucket has no cap or when its
|
||||
// fill is not read (said).
|
||||
func (s *Starter) atCap() error {
|
||||
if s.RunsFill == nil {
|
||||
return nil
|
||||
@@ -236,7 +229,7 @@ func (s *Starter) atCap() error {
|
||||
s.logf("the fill of test-runs is not read, so its cap is not judged: %v", err)
|
||||
return nil
|
||||
}
|
||||
if f.Bytes >= f.Cap {
|
||||
if f.Cap > 0 && f.Bytes >= f.Cap {
|
||||
return &fullErr{fill: f}
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -38,7 +38,7 @@ func (r RunsRead) TestRuns(in seat.TestRunsInput) (seat.TestRunsAnswer, error) {
|
||||
sort.Strings(all)
|
||||
a := seat.TestRunsAnswer{Runs: []seat.TestRun{}}
|
||||
for _, key := range all {
|
||||
if IsRunBound(key) || (in.Candidate != "" && !strings.HasPrefix(key, in.Candidate+".")) {
|
||||
if IsRunBound(key) || IsRunAsk(key) || (in.Candidate != "" && !strings.HasPrefix(key, in.Candidate+".")) {
|
||||
continue
|
||||
}
|
||||
raw, err := r.Runs.Value(key)
|
||||
@@ -165,6 +165,7 @@ func (v Verbs) TestRunsDrop(caller string, in seat.TestRunsDropInput) (seat.Test
|
||||
for _, k := range []string{BoundPrefix + in.Key, UntakenPrefix + in.Key} {
|
||||
_ = h.Clock.Unbound(k)
|
||||
}
|
||||
unmarkAsks(h.Clock, in.Key, h.logf)
|
||||
}
|
||||
gone := r.Answer()
|
||||
gone.Key = in.Key
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -20,6 +21,8 @@ type clockMem struct {
|
||||
asks map[string]string
|
||||
revs map[string]uint64
|
||||
rev uint64
|
||||
// askRuns are the ask keys, each holding its mark (H-A-500 addendum (1), H-A-506 addendum).
|
||||
askRuns map[string]AskMark
|
||||
// before is called once at the next Bound, a write that comes between its caller's read and its write.
|
||||
before func()
|
||||
}
|
||||
@@ -40,7 +43,11 @@ func (c *clockMem) Bounded(key string) (string, uint64, bool, error) {
|
||||
_, ok := c.bound[key]
|
||||
return c.asks[key], c.revs[key], ok, nil
|
||||
}
|
||||
func (c *clockMem) Unbound(key string) error { delete(c.bound, key); return nil }
|
||||
func (c *clockMem) Unbound(key string) error {
|
||||
delete(c.bound, key)
|
||||
delete(c.askRuns, key)
|
||||
return nil
|
||||
}
|
||||
func (c *clockMem) UnboundAt(key string, rev uint64) error {
|
||||
if c.revs[key] == rev {
|
||||
delete(c.bound, key)
|
||||
@@ -48,6 +55,26 @@ func (c *clockMem) UnboundAt(key string, rev uint64) error {
|
||||
return nil
|
||||
}
|
||||
func (c *clockMem) Has(key string) (bool, error) { _, ok := c.bound[key]; return ok, nil }
|
||||
func (c *clockMem) MarkAsk(ask string, m AskMark) error {
|
||||
if _, ok := c.askRuns[AskKey(ask)]; ok {
|
||||
return nil
|
||||
}
|
||||
if c.askRuns == nil {
|
||||
c.askRuns = map[string]AskMark{}
|
||||
}
|
||||
c.askRuns[AskKey(ask)] = m
|
||||
return nil
|
||||
}
|
||||
func (c *clockMem) AskOf(ask string) (AskMark, bool, error) {
|
||||
m, ok := c.askRuns[AskKey(ask)]
|
||||
return m, ok, nil
|
||||
}
|
||||
|
||||
// RunOfAsk is the run the ask key of ask names.
|
||||
func (c *clockMem) RunOfAsk(ask string) (string, bool, error) {
|
||||
m, ok := c.askRuns[AskKey(ask)]
|
||||
return m.Run, ok, nil
|
||||
}
|
||||
func (c *clockMem) Keys() ([]string, error) {
|
||||
var out []string
|
||||
for k := range c.runs {
|
||||
@@ -56,6 +83,9 @@ func (c *clockMem) Keys() ([]string, error) {
|
||||
for k := range c.bound {
|
||||
out = append(out, k)
|
||||
}
|
||||
for k := range c.askRuns {
|
||||
out = append(out, k)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
@@ -82,8 +112,11 @@ type runFixture struct {
|
||||
said []seat.StepEvent
|
||||
logged []string
|
||||
fill int64
|
||||
cap int64
|
||||
s *Starter
|
||||
h *Hearer
|
||||
// mu guards drops and logged, written also by the drops DropOpen asks side by side (H-A-506).
|
||||
mu sync.Mutex
|
||||
}
|
||||
|
||||
func newRunFixture() *runFixture {
|
||||
@@ -97,14 +130,20 @@ func newRunFixture() *runFixture {
|
||||
return nil
|
||||
}
|
||||
f.h = &Hearer{Store: f.store, Say: say, TestRuns: f.runs, Clock: f.clock, RunOutputs: f.objects,
|
||||
Logf: func(format string, a ...any) { f.logged = append(f.logged, fmt.Sprintf(format, a...)) },
|
||||
Logf: func(format string, a ...any) {
|
||||
f.mu.Lock()
|
||||
defer f.mu.Unlock()
|
||||
f.logged = append(f.logged, fmt.Sprintf(format, a...))
|
||||
},
|
||||
DropRun: func(seatName, node, ask, why string) error {
|
||||
f.mu.Lock()
|
||||
defer f.mu.Unlock()
|
||||
f.drops = append(f.drops, seatName+" "+node+" "+ask)
|
||||
return nil
|
||||
}}
|
||||
f.s = &Starter{Pipelines: memCreated{f.store}, Store: f.store, TestRuns: f.runs, Clock: f.clock, Say: say, Steps: f.asks,
|
||||
Name: "the-runner", Registration: func(string) (catalog.Registration, bool) { return reg, true }, EndReaders: f.h.EndReaders,
|
||||
RunsFill: func() (seat.Fill, error) { return seat.Fill{Store: "test-runs", Bytes: f.fill}, nil }, Logf: f.h.Logf}
|
||||
RunsFill: func() (seat.Fill, error) { return seat.Fill{Store: "test-runs", Bytes: f.fill, Cap: f.cap}, nil }, Logf: f.h.Logf}
|
||||
return f
|
||||
}
|
||||
|
||||
@@ -222,7 +261,7 @@ func TestATestRunHasOneClockACapAndAnAge(t *testing.T) {
|
||||
})
|
||||
t.Run("cap", func(t *testing.T) {
|
||||
f := newRunFixture()
|
||||
f.s.Runs.CapBytes, f.fill = 1<<20, 1<<20
|
||||
f.cap, f.fill = 1<<20, 1<<20
|
||||
p := f.start(t, 4, 9)
|
||||
for _, a := range f.asks.ids {
|
||||
if a == stepNamed(p, "app:program", "unit").Ask {
|
||||
@@ -244,24 +283,102 @@ func TestATestRunHasOneClockACapAndAnAge(t *testing.T) {
|
||||
_ = f.h.EndRun(run, seat.TestRun{Outcome: seat.StepResultOutcomePassed, Output: "out-1"}, nil)
|
||||
f.objects["out-1"] = []byte("ok")
|
||||
now := agedNow
|
||||
a := &Ager{Runs: f.runs, RunOutputs: f.objects.Delete, RunsKept: 7 * 24 * time.Hour, Pipelines: agedDeleter{f.store},
|
||||
Aged: agedState{}, Now: func() time.Time { return now },
|
||||
// test-runs-kept unset is its default, 48h (H-A-510).
|
||||
a := &Ager{Runs: f.runs, RunOutputs: f.objects.Delete, Pipelines: agedDeleter{f.store},
|
||||
Clock: f.clock, Aged: agedState{}, Now: func() time.Time { return now },
|
||||
Log: func(from uint64, limit int) ([]LoggedEntry, error) {
|
||||
if from > 1 {
|
||||
return nil, nil
|
||||
}
|
||||
return []LoggedEntry{{Sequence: 1, Entry: seat.LogEntry{Pipeline: p.Pipeline, Step: "unit", Artifact: "app:tools",
|
||||
What: seat.LogEntryWhatEnded, At: agedNow.Add(-6 * 24 * time.Hour)}}}, nil
|
||||
What: seat.LogEntryWhatEnded, At: agedNow.Add(-46 * time.Hour)}}}, nil
|
||||
}}
|
||||
a.Age()
|
||||
if _, _, err := f.runs.Get(run); err != nil {
|
||||
t.Fatal("a run is aged before test-runs-kept passed")
|
||||
}
|
||||
now = now.Add(2 * 24 * time.Hour)
|
||||
// The ask key goes with the run's end, not its aging (H-A-506 addendum).
|
||||
if held, ok, _ := f.clock.RunOfAsk(unit.Ask); ok {
|
||||
t.Fatalf("the ask key of %s holds %q after its run ended, want it deleted with the end", unit.Ask, held)
|
||||
}
|
||||
_ = f.clock.MarkAsk(unit.Ask, AskMark{Run: run}) // a key written before the addendum, holding its run alone
|
||||
now = now.Add(3 * time.Hour)
|
||||
a.Age()
|
||||
if _, _, err := f.runs.Get(run); err != ErrNoRun || len(f.objects) != 0 {
|
||||
t.Errorf("the run past test-runs-kept is %v, objects %v; want both deleted", err, f.objects)
|
||||
}
|
||||
// The ask key is deleted with the aged run (H-A-500 addendum (1)), as it is when the run's last reader leaves.
|
||||
if _, ok, _ := f.clock.RunOfAsk(unit.Ask); ok {
|
||||
t.Errorf("the ask key of %s outlives its aged run", unit.Ask)
|
||||
}
|
||||
})
|
||||
t.Run("age by fill", func(t *testing.T) {
|
||||
// H-A-510: at nine tenths of the bucket's max bytes the oldest ended runs go with their outputs, in the step log's
|
||||
// order, until the fill is under eight tenths, said in one line; a run not ended is never aged by fill.
|
||||
store, runs, objects := memStore{}, testRunsMem{}, objectsMem{}
|
||||
var steps []seat.StepResult
|
||||
var log []LoggedEntry
|
||||
for i := range 5 {
|
||||
run, step := sprintf("r%d", i), sprintf("unit%d", i)
|
||||
steps = append(steps, seat.StepResult{Artifact: "app:program", Step: step, Shared: []seat.Shared{{Run: run}}})
|
||||
r := Run{TestRun: seat.TestRun{Output: "o" + run}}
|
||||
if i > 0 { // r0 has not ended
|
||||
ended := agedNow.Add(-time.Duration(6-i) * time.Hour)
|
||||
r.Ended = &ended
|
||||
}
|
||||
_ = runs.Create(run, r)
|
||||
objects["o"+run] = []byte("out")
|
||||
log = append(log, LoggedEntry{Sequence: uint64(i + 1), Entry: seat.LogEntry{Pipeline: "main.1", Step: step,
|
||||
Artifact: "app:program", What: seat.LogEntryWhatEnded, At: agedNow.Add(-time.Hour)}})
|
||||
}
|
||||
store["main.1"] = struct {
|
||||
p seat.Pipeline
|
||||
rev uint64
|
||||
}{seat.Pipeline{Pipeline: "main.1", Branch: "main", Outcome: seat.PipelineOutcomePassed, Steps: steps}, 1}
|
||||
var logged []string
|
||||
cap := int64(60)
|
||||
aged := agedState{}
|
||||
a := &Ager{Runs: runs, RunOutputs: objects.Delete, Pipelines: agedDeleter{store}, Aged: aged,
|
||||
Now: func() time.Time { return agedNow },
|
||||
Logf: func(format string, v ...any) { logged = append(logged, sprintf(format, v...)) },
|
||||
RunsFill: func() (seat.Fill, error) {
|
||||
return seat.Fill{Store: "test-runs", Bytes: int64(10 * len(runs)), Cap: cap}, nil
|
||||
},
|
||||
Log: func(from uint64, limit int) ([]LoggedEntry, error) {
|
||||
var out []LoggedEntry
|
||||
for _, e := range log {
|
||||
if e.Sequence >= from && len(out) < limit {
|
||||
out = append(out, e)
|
||||
}
|
||||
}
|
||||
return out, nil
|
||||
}}
|
||||
kept := func() []string {
|
||||
var out []string
|
||||
for k := range runs {
|
||||
out = append(out, k)
|
||||
}
|
||||
slices.Sort(out)
|
||||
return out
|
||||
}
|
||||
a.Age() // 50 of 60 bytes, under nine tenths; and no run is past test-runs-kept's 48h
|
||||
if got := kept(); len(got) != 5 || len(logged) != 0 {
|
||||
t.Fatalf("under nine tenths the runs are %v, said %q; want all five kept, nothing said", got, logged)
|
||||
}
|
||||
cap = 50
|
||||
a.Age()
|
||||
if got := kept(); !slices.Equal(got, []string{"r0", "r3", "r4"}) || objects["or1"] != nil || objects["or2"] != nil || objects["or0"] == nil {
|
||||
t.Fatalf("at the cap the runs are %v, objects %v; want r1 and r2 deleted with their outputs, the unended r0 kept", got, objects)
|
||||
}
|
||||
if len(logged) != 1 || !strings.Contains(logged[0], "50 of its 50 bytes") || !strings.Contains(logged[0], "2 ended test runs") ||
|
||||
!strings.Contains(logged[0], "ended 5h0m0s to 4h0m0s ago") || !strings.Contains(logged[0], "holds 30 bytes now") || aged[RetentionTestRuns] != 3 {
|
||||
t.Fatalf("the fill's ageing said %q, retention at %d; want one line of how many and how old, at the log's third entry", logged, aged[RetentionTestRuns])
|
||||
}
|
||||
cap, logged = 10, nil
|
||||
a.Age() // past the cap: every ended run left goes, the log runs out, and the unended r0 stays
|
||||
if got := kept(); !slices.Equal(got, []string{"r0"}) || len(logged) != 1 || !strings.Contains(logged[0], "2 ended test runs") {
|
||||
t.Fatalf("the runs are %v, said %q; want only the unended r0 kept, said in one line", got, logged)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -322,20 +439,39 @@ func TestATestRunsEndMovesEveryReaderAndIsCountedOnce(t *testing.T) {
|
||||
t.Errorf("%s's unit ends journaled %d times in %q, want once per artifact", key, n, f.logged)
|
||||
}
|
||||
}
|
||||
// a, cancelled, leaves the lint run to b's readers; b, cancelled after, leaves none: the ask is dropped and the run ends.
|
||||
// Two pipelines read one lint run: a, cancelled, leaves it to b's readers and its ask is not dropped, while a's own
|
||||
// asks of no shared run are; b, cancelled after, is the last reader: the run ends, no reader left, and its ask is
|
||||
// dropped once (H-A-506 corrected).
|
||||
lint := stepNamed(a, "app:program", "lint")
|
||||
v := Verbs{Hearer: f.h, Acts: &actLog{}}
|
||||
if _, err := v.Cancel("operator", seat.CancelInput{Pipeline: a.Pipeline, Why: "not needed"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if r, _, _ := f.runs.Get(lint.Shared[0].Run); r.Ended != nil || len(r.Readers) != 2 || len(f.drops) != 0 {
|
||||
t.Fatalf("after a left the lint run = %+v, drops %v; want it running for b's two readers", r, f.drops)
|
||||
if r, _, _ := f.runs.Get(lint.Shared[0].Run); r.Ended != nil || len(r.Readers) != 2 || slices.Contains(f.drops, "node-build-go "+lint.Ask) || len(f.drops) == 0 {
|
||||
t.Fatalf("after a left the lint run = %+v, drops %v; want it running for b's two readers, its ask kept, a's own asks dropped", r, f.drops)
|
||||
}
|
||||
// a's end keeps the run's ask key, which b still reads: b's holder's progress re-arms the run's clock (H-A-500
|
||||
// addendum (1), H-A-506 corrected).
|
||||
run := lint.Shared[0].Run
|
||||
if m, ok, _ := f.clock.AskOf(lint.Ask); !ok || m.Run != run {
|
||||
t.Fatalf("after a's end the lint run's ask key = %+v, %v; want it kept for b", m, ok)
|
||||
}
|
||||
if err := f.h.RunTaken(lint.Ask, "ace"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
delete(f.clock.bound, BoundPrefix+run)
|
||||
if err := f.h.RunProgress(lint.Ask); err != nil || f.clock.bound[BoundPrefix+run] == 0 {
|
||||
t.Fatalf("b's progress after a's end re-armed %v (%v), want the run's clock armed", f.clock.bound, err)
|
||||
}
|
||||
n := len(f.drops)
|
||||
if _, err := v.Cancel("operator", seat.CancelInput{Pipeline: b.Pipeline, Why: "not needed"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if r, _, _ := f.runs.Get(lint.Shared[0].Run); r.Outcome != seat.StepResultOutcomeCouldNotRun || r.Said != NoReaderLeft || len(f.drops) != 2 || f.drops[0] != "node-build-go "+lint.Ask {
|
||||
t.Errorf("after the last reader left the lint run = %+v, drops %v; want it ended, no reader left, its ask and the integration run's dropped", r, f.drops)
|
||||
if r, _, _ := f.runs.Get(lint.Shared[0].Run); r.Outcome != seat.StepResultOutcomeCouldNotRun || r.Said != NoReaderLeft {
|
||||
t.Errorf("after the last reader left the lint run = %+v; want it ended, no reader left", r)
|
||||
}
|
||||
if got := countLines(f.drops[n:], lint.Ask); got != 1 {
|
||||
t.Errorf("b's cancel dropped %v, want the lint run's ask %s once", f.drops[n:], lint.Ask)
|
||||
}
|
||||
// A composition step's end keeps the runs mesh-wants names, as they came (A-468d).
|
||||
c := newRunFixture()
|
||||
@@ -354,6 +490,15 @@ func TestATestRunsEndMovesEveryReaderAndIsCountedOnce(t *testing.T) {
|
||||
if s := stepNamed(c.pipeline(p), "", "composition"); len(s.Shared) != 1 || s.Shared[0] != (seat.Shared{Machine: "ace", Run: "main.9.ace", Ask: "r1"}) {
|
||||
t.Errorf("the composition step's shared = %+v, want mesh-wants' as it came", s.Shared)
|
||||
}
|
||||
// Its own ask key goes with the pipeline's end: a mesh-wants step's shared runs are no test run whose end deletes it
|
||||
// (H-A-506 addendum, corrected).
|
||||
_ = c.clock.MarkAsk(comp.Ask, AskMark{Pipeline: p.Pipeline, Step: "composition"})
|
||||
if err := c.h.said(c.pipeline(p), nil, true); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, ok, _ := c.clock.AskOf(comp.Ask); ok {
|
||||
t.Errorf("the composition's ask key %s outlives its pipeline's end", comp.Ask)
|
||||
}
|
||||
}
|
||||
|
||||
// Asking a test run again moves every reader (design 47 G §727; A-469l, A-470d, A-470e): a rerun of one artifact's failed
|
||||
@@ -472,15 +617,13 @@ func TestTheTestRunsAreReadAndDroppedByTheirVerbs(t *testing.T) {
|
||||
for k, e := range f.runs {
|
||||
put(t, pipes, k, e.r)
|
||||
}
|
||||
// The fill is said against the cap setting that refuses, never the bucket's 64 MiB ceiling (A-470g, A-470i).
|
||||
f.s.Runs.CapBytes, f.fill = 1<<20, 9
|
||||
bucket := f.s.RunsFill
|
||||
f.s.RunsFill = func() (seat.Fill, error) { fl, err := bucket(); fl.Cap = 64 << 20; return fl, err }
|
||||
// The fill is said against the bucket's max bytes, the cap that refuses, never a second number (A-470i, H-A-510).
|
||||
f.cap, f.fill = 1<<20, 9
|
||||
read := RunsRead{Runs: pipes, Object: f.objects.Get, Fill: f.s.TestRunsFill}
|
||||
a, err := read.TestRuns(seat.TestRunsInput{Level: "unit", Module: "app"})
|
||||
if err != nil || len(a.Runs) != 1 || len(a.Runs[0].Packages) != 1 || a.Runs[0].Packages[0] != (seat.TestRunPackage{Package: "app/x", Digest: "d1"}) ||
|
||||
a.Runs[0].Key != unit.Shared[0].Run || len(a.Runs[0].Readers) != 2 || a.Fill.Cap != 1<<20 || a.Fill.Bytes != 9 {
|
||||
t.Fatalf("test-runs = %+v, %v; want the unit run with its package and readers, and the fill against the cap setting", a, err)
|
||||
t.Fatalf("test-runs = %+v, %v; want the unit run with its package and readers, and the fill against the bucket's max bytes", a, err)
|
||||
}
|
||||
delete(f.objects, unit.Shared[0].Run) // gone, whatever step-outputs' age: the run answers without its packages
|
||||
if a, _ := read.TestRuns(seat.TestRunsInput{Level: "unit"}); len(a.Runs) != 1 || a.Runs[0].Gone != Gone || len(a.Runs[0].Packages) != 0 {
|
||||
@@ -631,6 +774,45 @@ func TestNoWriteOfATestRunActsOnAReadBeforeItsLatestChange(t *testing.T) {
|
||||
t.Errorf("the late step-progress placed in %v, want %s's waiting movers placed", released, p.Pipeline)
|
||||
}
|
||||
})
|
||||
// H-A-500 (a) and its addenda: a late ask-taken or step-progress of an ended run's ask is judged from its ask key and
|
||||
// its run alone, never the pipelines, one journal line per hundred; the ask key is deleted with the run.
|
||||
t.Run("a late event of an ended run's ask reads no pipeline", func(t *testing.T) {
|
||||
f := newRunFixture()
|
||||
p := f.start(t, 4, 9)
|
||||
unit := stepNamed(p, "app:program", "unit")
|
||||
run := unit.Shared[0].Run
|
||||
// The ask key of the run's ask names its pipeline, its step and its run (H-A-506 addendum).
|
||||
if got, ok, _ := f.clock.AskOf(unit.Ask); !ok || got != (AskMark{Pipeline: p.Pipeline, Module: "app", Step: "unit", Run: run}) {
|
||||
t.Fatalf("the ask key of %s holds %+v, %v; want %s's unit step of the run %s", unit.Ask, got, ok, p.Pipeline, run)
|
||||
}
|
||||
if f.h.LateRunAsk("step-progress", unit.Ask) {
|
||||
t.Fatal("the ask of a running run is judged late")
|
||||
}
|
||||
if err := f.h.EndRun(run, seat.TestRun{Ask: unit.Ask, Outcome: seat.StepResultOutcomePassed}, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
store := f.h.Store
|
||||
f.h.Store, f.logged = nil, nil // a read of the pipelines would panic
|
||||
for i := 0; i < 2*LateEveryLine; i++ {
|
||||
if !f.h.LateRunAsk("ask-taken", unit.Ask) {
|
||||
t.Fatalf("event %d of the ended run's ask is not judged late", i)
|
||||
}
|
||||
}
|
||||
if !f.h.LateRunAsk("ask-taken", "anaskofnorun") {
|
||||
t.Error("an ask with no ask key is not acknowledged at once (H-A-506 addendum)")
|
||||
}
|
||||
if len(f.logged) != 2 || !strings.Contains(f.logged[1], "200 late events") {
|
||||
t.Errorf("journal %q; want one line per hundred late events", f.logged)
|
||||
}
|
||||
f.h.Store = store
|
||||
v := Verbs{Hearer: f.h, Starter: f.s, Acts: &actLog{}}
|
||||
if _, err := v.TestRunsDrop("op@shanks", seat.TestRunsDropInput{Key: run, Why: "gone"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, ok, _ := f.clock.RunOfAsk(unit.Ask); ok {
|
||||
t.Error("the ask key is kept after its run is deleted")
|
||||
}
|
||||
})
|
||||
// A run's end is written as its step-ended is heard, before the finding the step says (A-470o).
|
||||
t.Run("the run ends before the step's finding is written", func(t *testing.T) {
|
||||
f := newRunFixture()
|
||||
|
||||
@@ -208,8 +208,9 @@ func (v Verbs) Accept(caller string, in seat.AcceptInput) (seat.AcceptAnswer, er
|
||||
return seat.AcceptAnswer{Result: p.Steps[i]}, nil
|
||||
}
|
||||
|
||||
// Cancel ends a running pipeline `cancelled`, each step not ended cancelled and each step of a test run leaving it, recorded
|
||||
// in the hand-act log first (§394, §726); it says pipeline-ended.
|
||||
// Cancel ends a running pipeline `cancelled`, each step not ended cancelled, each step of a test run leaving it and every
|
||||
// ask still open dropped through its seat's drop, recorded in the hand-act log first (§394, §726, H-A-506); it says
|
||||
// pipeline-ended.
|
||||
func (v Verbs) Cancel(caller string, in seat.CancelInput) (seat.CancelAnswer, error) {
|
||||
h := v.Hearer
|
||||
recorded := false
|
||||
@@ -228,16 +229,14 @@ func (v Verbs) Cancel(caller string, in seat.CancelInput) (seat.CancelAnswer, er
|
||||
recorded = true
|
||||
}
|
||||
now := h.now()
|
||||
var leave []seat.StepResult
|
||||
// Every ask still open is dropped and every test run read is left once the cancel is written (H-A-506).
|
||||
asked := openAtEnd(p.Steps)
|
||||
var cancelled []int
|
||||
for i := range p.Steps {
|
||||
s := &p.Steps[i]
|
||||
if !open(*s) && s.Outcome != seat.StepResultOutcomeWaiting {
|
||||
continue
|
||||
}
|
||||
if sharedRun(*s) != "" && s.Seat != wants.Seat {
|
||||
leave = append(leave, *s) // it leaves its test run, dropped only with the last reader (§726)
|
||||
}
|
||||
s.Outcome, s.By, s.Why, s.Ended = seat.StepResultOutcomeCancelled, caller, in.Why, &now
|
||||
cancelled = append(cancelled, i)
|
||||
}
|
||||
@@ -248,9 +247,7 @@ func (v Verbs) Cancel(caller string, in seat.CancelInput) (seat.CancelAnswer, er
|
||||
} else if err != nil {
|
||||
return seat.CancelAnswer{}, fmt.Errorf("pipeline %s cannot be written: %w", in.Pipeline, err)
|
||||
}
|
||||
for _, s := range leave {
|
||||
h.leaveRun(in.Pipeline, s, "the pipeline "+in.Pipeline+" is cancelled: "+in.Why)
|
||||
}
|
||||
h.DropOpen(in.Pipeline, asked, "the pipeline "+in.Pipeline+" is cancelled: "+in.Why)
|
||||
// Each step the cancel ended is said, with its line (design 47 H2 §784).
|
||||
for _, i := range cancelled {
|
||||
if err := h.say(seat.EventStepEnded, p, &p.Steps[i]); err != nil {
|
||||
@@ -369,10 +366,11 @@ func (v Verbs) rerun(caller string, in seat.RerunInput, reopens bool) (seat.Reru
|
||||
}
|
||||
}
|
||||
var ask *Asked
|
||||
var replaced string
|
||||
p, _, err := v.change(in.Pipeline, seat.EventStepStarted, func() error {
|
||||
return v.record(seat.VerbRerun, fmt.Sprintf("asked the %s step of %s again", in.Step, in.Pipeline), in.Why)
|
||||
}, func(p *seat.Pipeline, now time.Time) (int, error) {
|
||||
ask = nil
|
||||
ask, replaced = nil, ""
|
||||
switch p.Outcome {
|
||||
case seat.PipelineOutcomeCancelled, seat.PipelineOutcomeSuperseded:
|
||||
return -1, fmt.Errorf("the pipeline %s is %s: a step of it is not asked again", p.Pipeline, p.Outcome)
|
||||
@@ -391,6 +389,7 @@ func (v Verbs) rerun(caller string, in seat.RerunInput, reopens bool) (seat.Reru
|
||||
}
|
||||
}
|
||||
oldAsk := s.Ask
|
||||
replaced = oldAsk
|
||||
*s = seat.StepResult{Step: s.Step, Module: s.Module, Artifact: s.Artifact, Status: s.Status, Fingerprint: s.Fingerprint, Seat: s.Seat,
|
||||
Outcome: seat.StepResultOutcomeWaiting, By: caller, Rerun: true}
|
||||
if ask != nil {
|
||||
@@ -417,9 +416,12 @@ func (v Verbs) rerun(caller string, in seat.RerunInput, reopens bool) (seat.Reru
|
||||
return seat.RerunAnswer{}, err
|
||||
}
|
||||
v.sayReopened(p, reopens)
|
||||
if ask == nil || replaced != ask.ID {
|
||||
unmarkAsk(v.Hearer.Clock, replaced, v.Hearer.logf) // one key per ask, gone once the ask is no longer open (H-A-506 addendum)
|
||||
}
|
||||
if ask != nil {
|
||||
v.Starter.carry(in.Pipeline, []Asked{*ask})
|
||||
if err := askAll(v.Starter.Steps, in.Pipeline, []Asked{*ask}, func(commit string) bool { return v.Starter.recovered(in.Pipeline, commit) }, v.Starter.Asks.arm, v.Starter.logf); err != nil {
|
||||
if err := askAll(v.Starter.Steps, in.Pipeline, []Asked{*ask}, func(commit string) bool { return v.Starter.recovered(in.Pipeline, commit) }, v.Starter.armAsk(in.Pipeline), v.Starter.logf); err != nil {
|
||||
return seat.RerunAnswer{}, fmt.Errorf("the step is written running but not asked, it is asked again at the next start: %w", err)
|
||||
}
|
||||
}
|
||||
@@ -567,7 +569,7 @@ func (v Verbs) rerunTest(caller string, in seat.RerunInput, st seat.StepResult,
|
||||
break
|
||||
}
|
||||
v.Starter.carry(in.Pipeline, []Asked{*ask})
|
||||
if err := askAll(v.Starter.Steps, in.Pipeline, []Asked{*ask}, func(commit string) bool { return v.Starter.recovered(in.Pipeline, commit) }, v.Starter.Asks.arm, v.Starter.logf); err != nil {
|
||||
if err := askAll(v.Starter.Steps, in.Pipeline, []Asked{*ask}, func(commit string) bool { return v.Starter.recovered(in.Pipeline, commit) }, v.Starter.armAsk(in.Pipeline), v.Starter.logf); err != nil {
|
||||
return seat.RerunAnswer{}, fmt.Errorf("the step is written running but not asked, it is asked again at the next start: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,9 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -36,9 +38,22 @@ func verbsFixture() (Verbs, memStore, *[]string, *stepAsks, *actLog, *[]string)
|
||||
rev uint64
|
||||
}{p, 1}
|
||||
asks, acts, dropped := &stepAsks{}, &actLog{}, &[]string{}
|
||||
clock := &clockMem{runs: testRunsMem{}, bound: map[string]time.Duration{}}
|
||||
h.Clock = clock
|
||||
s := &Starter{Steps: asks, Name: "the-runner", Registration: func(string) (catalog.Registration, bool) { return reg, true },
|
||||
Now: h.Now}
|
||||
h.DropRun = func(_, _, ask, _ string) error { *dropped = append(*dropped, ask); return nil }
|
||||
Now: h.Now, Clock: clock}
|
||||
var mu sync.Mutex // the drops DropOpen asks side by side write here too (H-A-506)
|
||||
h.DropRun = func(onSeat, _, ask, _ string) error {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
*dropped = append(*dropped, onSeat+" "+ask)
|
||||
return nil
|
||||
}
|
||||
h.Logf = func(format string, args ...any) {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
*dropped = append(*dropped, "log: "+fmt.Sprintf(format, args...))
|
||||
}
|
||||
return Verbs{Hearer: h, Starter: s, View: func(string) (Half, bool) { return Half{Entries: entries}, true }, Acts: acts},
|
||||
store, said, asks, acts, dropped
|
||||
}
|
||||
@@ -137,10 +152,41 @@ func TestAcceptRerunAndCancelWriteByCompareAndSetAndRecordTheirHandAct(t *testin
|
||||
if _, err := v.Rerun("operator", seat.RerunInput{Pipeline: pkey, Step: "approval", Why: "again"}); err == nil {
|
||||
t.Error("an approval was asked again by rerun")
|
||||
}
|
||||
// A cancel ends the pipeline cancelled and drops the bounds of the asks still held.
|
||||
// A cancel ends the pipeline cancelled and drops, through each seat's drop, every ask still open: the build on
|
||||
// mesh-builds, the build steps on node-build-go and the composition on mesh-wants; an ended step's ask is not dropped
|
||||
// (H-A-506).
|
||||
before, _, _ := store.Get(pkey)
|
||||
var open []string
|
||||
for _, s := range before.Steps {
|
||||
if s.Ask != "" && (s.Outcome == seat.StepResultOutcomeRunning || s.Outcome == seat.StepResultOutcomeWaitingForABuildNode) {
|
||||
open = append(open, s.Seat+" "+s.Ask)
|
||||
}
|
||||
}
|
||||
c, err := v.Cancel("operator", seat.CancelInput{Pipeline: pkey, Why: "wrong branch"})
|
||||
if err != nil || c.Pipeline.Outcome != "cancelled" || c.Pipeline.EndCount != 1 || len(*dropped) != 0 {
|
||||
t.Fatalf("cancel = %+v, %v, dropped %v", c.Pipeline, err, *dropped)
|
||||
if err != nil || c.Pipeline.Outcome != "cancelled" || c.Pipeline.EndCount != 1 {
|
||||
t.Fatalf("cancel = %+v, %v", c.Pipeline, err)
|
||||
}
|
||||
seats := map[string]bool{}
|
||||
for _, o := range open {
|
||||
seats[strings.Fields(o)[0]] = true
|
||||
}
|
||||
var drops, lines []string
|
||||
for _, d := range *dropped {
|
||||
if l, ok := strings.CutPrefix(d, "log: "); ok {
|
||||
lines = append(lines, l)
|
||||
} else {
|
||||
drops = append(drops, d)
|
||||
}
|
||||
}
|
||||
slices.Sort(drops)
|
||||
slices.Sort(open)
|
||||
if len(open) < 4 || !seats["mesh-builds"] || !seats["mesh-wants"] || !seats["node-build-go"] || fmt.Sprint(drops) != fmt.Sprint(open) {
|
||||
t.Fatalf("cancel dropped %v, want every open ask %v, on mesh-builds, node-build-go and mesh-wants", drops, open)
|
||||
}
|
||||
for _, o := range open {
|
||||
if ask := strings.Fields(o)[1]; countLines(lines, "the ask "+ask+" of ") != 1 {
|
||||
t.Errorf("the drop of %s is not said in one journal line: %q", ask, lines)
|
||||
}
|
||||
}
|
||||
if s := stepNamed(c.Pipeline, "app:program", "lint"); s.Outcome != "cancelled" || s.By != "operator" {
|
||||
t.Errorf("the lint step = %+v", s)
|
||||
|
||||
@@ -208,8 +208,9 @@ func equalSets(a, b []string) bool {
|
||||
return slices.Equal(x, y)
|
||||
}
|
||||
|
||||
// runSettingsOf says whether the manifest holds the test runs' four settings (design 47 G §725; A-469w, A-469x): the cap a
|
||||
// whole number of at most 64, the three times Go durations, each written into the file its environment names.
|
||||
// runSettingsOf says whether the manifest holds the test runs' three settings (design 47 G §725; A-469w, A-469x), Go
|
||||
// durations, test-runs-kept 48h by default, each written into the file its environment names, and no cap setting: the cap is
|
||||
// the state's max-mib (H-A-510 and its addendum).
|
||||
func runSettingsOf(raw []byte) bool {
|
||||
var m struct {
|
||||
Config map[string]map[string]any `json:"config"`
|
||||
@@ -223,7 +224,7 @@ func runSettingsOf(raw []byte) bool {
|
||||
if json.Unmarshal(raw, &m) != nil {
|
||||
return false
|
||||
}
|
||||
want := map[string]string{"test-runs-cap-mib": "number", "test-runs-kept": "string", "test-step-bound": "string", "run-untaken-bound": "string", "ask-unanswered-bound": "string", "widens-read-bound": "string", "revisions-kept": "number",
|
||||
want := map[string]string{"test-runs-kept": "string", "test-step-bound": "string", "run-untaken-bound": "string", "ask-unanswered-bound": "string", "widens-read-bound": "string", "revisions-kept": "number",
|
||||
"pipelines-at-once": "number", "pipelines-waiting-cap": "number"}
|
||||
// design 47 H2 §790, §781: stalled-bound is read through mesh-sdk's settings reader, by the process and the tools
|
||||
// program alike, from the words the node-engine composes: no file of its own.
|
||||
@@ -235,7 +236,7 @@ func runSettingsOf(raw []byte) bool {
|
||||
return false
|
||||
}
|
||||
}
|
||||
if len(m.Config) != len(want)+len(words) || m.Config["test-runs-cap-mib"]["maximum"] != float64(64) || m.Config["test-runs-cap-mib"]["default"] != float64(16) ||
|
||||
if len(m.Config) != len(want)+len(words) || m.Config["test-runs-kept"]["default"] != "48h" ||
|
||||
m.Config["pipelines-at-once"]["minimum"] != float64(1) || m.Config["pipelines-at-once"]["maximum"] != float64(8) ||
|
||||
m.Config["pipelines-at-once"]["default"] != float64(1) || m.Config["pipelines-waiting-cap"]["default"] != float64(64) ||
|
||||
m.Config["widens-read-bound"]["default"] != "30s" {
|
||||
@@ -247,6 +248,11 @@ func runSettingsOf(raw []byte) bool {
|
||||
env[v] = true
|
||||
}
|
||||
}
|
||||
for _, r := range m.Resources {
|
||||
if strings.Contains(r.Path, "test-runs-cap") {
|
||||
return false
|
||||
}
|
||||
}
|
||||
for key, kind := range want {
|
||||
if m.Config[key]["type"] != kind {
|
||||
return false
|
||||
|
||||
@@ -116,19 +116,11 @@
|
||||
"operator-channel"
|
||||
],
|
||||
"config": {
|
||||
"test-runs-cap-mib": {
|
||||
"type": "number",
|
||||
"description": "MiB of the state test-runs at which the runner asks no new test run and ends the step could not run, naming the fill (design 47 G section 725, A-469d); the manifest's max-mib is the ceiling.",
|
||||
"minimum": 1,
|
||||
"maximum": 64,
|
||||
"trusted": false,
|
||||
"default": 16
|
||||
},
|
||||
"test-runs-kept": {
|
||||
"type": "string",
|
||||
"description": "how long an ended test run and its output object are kept after its end, a Go duration such as 168h (design 47 G section 725, A-469x, A-470a); at most 168h, so the pipeline naming its key is still kept.",
|
||||
"description": "how long an ended test run and its output object are kept after its end, a Go duration such as 48h (design 47 G section 725, A-469x, A-470a, H-A-510); at most 168h, so the pipeline naming its key is still kept. Past nine tenths of the state's max-mib the oldest ended runs go sooner, until it is under eight tenths.",
|
||||
"trusted": false,
|
||||
"default": "168h"
|
||||
"default": "48h"
|
||||
},
|
||||
"test-step-bound": {
|
||||
"type": "string",
|
||||
@@ -301,14 +293,6 @@
|
||||
"place": ".",
|
||||
"unknown": "program"
|
||||
},
|
||||
{
|
||||
"id": "test-runs-cap",
|
||||
"type": "file",
|
||||
"path": "${dir:state}/test-runs-cap-mib",
|
||||
"owner": "mesh-delivery-pipeline",
|
||||
"mode": "0600",
|
||||
"content": "${config:test-runs-cap-mib}"
|
||||
},
|
||||
{
|
||||
"id": "test-runs-kept",
|
||||
"type": "file",
|
||||
@@ -383,7 +367,6 @@
|
||||
],
|
||||
"env": {
|
||||
"MESH_BROKER_FILE": "${dir:state}/broker",
|
||||
"MESH_RUNNER_TEST_RUNS_CAP_FILE": "${dir:state}/test-runs-cap-mib",
|
||||
"MESH_RUNNER_TEST_RUNS_KEPT_FILE": "${dir:state}/test-runs-kept",
|
||||
"MESH_RUNNER_TEST_STEP_BOUND_FILE": "${dir:state}/test-step-bound",
|
||||
"MESH_RUNNER_WIDENS_READ_BOUND_FILE": "${dir:state}/widens-read-bound",
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
"time"
|
||||
|
||||
"github.com/nats-io/nats.go/jetstream"
|
||||
|
||||
@@ -107,6 +108,30 @@ func (c creating) RaiseMaxBytes(stream string, to int64) (int64, bool, error) {
|
||||
return from, true, nil
|
||||
}
|
||||
|
||||
// AllowMsgTTL turns on a held stream's per-message time to live, its delete markers living markerTTL, when it is off, and
|
||||
// changes nothing else (design 47 H2 H-A-501, corrected): it reads the stream's configuration and updates with the rest as
|
||||
// it was. A stream with it on already is left as it is.
|
||||
func (c creating) AllowMsgTTL(stream string, markerTTL time.Duration) (bool, error) {
|
||||
ctx, cancel := context.WithTimeout(c.ctx, requestWithin)
|
||||
defer cancel()
|
||||
s, err := c.js.Stream(ctx, stream)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
cfg := s.CachedInfo().Config
|
||||
if cfg.AllowMsgTTL {
|
||||
return false, nil
|
||||
}
|
||||
cfg.AllowMsgTTL = true
|
||||
if cfg.SubjectDeleteMarkerTTL == 0 {
|
||||
cfg.SubjectDeleteMarkerTTL = markerTTL
|
||||
}
|
||||
if _, err := c.js.UpdateStream(ctx, cfg); err != nil {
|
||||
return false, err
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// SourceFilter brings the filter subject of a held stream's source from `source` to `filter` and changes nothing else
|
||||
// (design 47 H H-A-145): it reads the stream's configuration and updates with the rest as it was, so its messages stay. A
|
||||
// stream with no source from `source`, or one already at `filter`, is left as it is.
|
||||
|
||||
@@ -202,6 +202,19 @@ func (b *fakeBus) AddSubjects(stream string, add []string) error {
|
||||
// SourceFilter is the bus's update of a held stream's source filter: the fake holds no sources, so nothing changes.
|
||||
func (b *fakeBus) SourceFilter(string, string, string) (string, bool, error) { return "", false, nil }
|
||||
|
||||
// AllowMsgTTL is the bus's turning on of a held stream's per-message time to live, every other setting kept.
|
||||
func (b *fakeBus) AllowMsgTTL(stream string, _ time.Duration) (bool, error) {
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
for _, s := range b.streams {
|
||||
if s["name"] == stream && s["allow_msg_ttl"] != true {
|
||||
s["allow_msg_ttl"] = true
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// RaiseMaxBytes is the bus's raise of a held stream's size cap: only to a larger cap, an unbounded stream and every other
|
||||
// setting kept.
|
||||
func (b *fakeBus) RaiseMaxBytes(stream string, to int64) (int64, bool, error) {
|
||||
@@ -719,10 +732,11 @@ func TestGrants(t *testing.T) {
|
||||
if n := strings.Count(string(src), "CreateStream"); (path == createOnly && n != 1) || (path != createOnly && n != 0) {
|
||||
t.Errorf("%s holds CreateStream %d times: only create.go creates, once", path, n)
|
||||
}
|
||||
// The three updates of a stream: adding subjects to a held one (the operator, 2026-11-05), raising its size cap
|
||||
// (2026-11-09) and bringing a kept stream's source filter to its definition's (design 47 H H-A-145), all in create.go.
|
||||
if n := strings.Count(string(src), "UpdateStream("); (path == createOnly && n != 3) || (path != createOnly && n != 0) {
|
||||
t.Errorf("%s holds UpdateStream %d times: only create.go updates a stream, three times, to add subjects, to raise a size cap and to bring a kept stream's source filter", path, n)
|
||||
// The four updates of a stream: adding subjects to a held one (the operator, 2026-11-05), raising its size cap
|
||||
// (2026-11-09), bringing a kept stream's source filter to its definition's (design 47 H H-A-145) and turning on a
|
||||
// key-ttl state's per-message time to live (design 47 H2 H-A-501, corrected), all in create.go.
|
||||
if n := strings.Count(string(src), "UpdateStream("); (path == createOnly && n != 4) || (path != createOnly && n != 0) {
|
||||
t.Errorf("%s holds UpdateStream %d times: only create.go updates a stream, four times, to add subjects, to raise a size cap, to bring a kept stream's source filter and to turn on per-message time to live", path, n)
|
||||
}
|
||||
// The one object bucket: the part's own, of the user list sealed to the bus node, in sealed.go (ADR 0547 clause 7).
|
||||
if path == sealedOnly {
|
||||
|
||||
@@ -1546,7 +1546,9 @@ func theToolRunnerHearsEveryEvent(t *testing.T) {
|
||||
}
|
||||
}
|
||||
for _, s := range p.Publish {
|
||||
if strings.Contains(s, "LEDGER") || strings.HasPrefix(s, "$JS.ACK.") {
|
||||
// A module's own takeins durable on the shared events stream is no restricted stream (H-A-500 (b)).
|
||||
takeIns := strings.HasPrefix(s, "$JS.ACK."+EventsStream+".") && strings.HasSuffix(s, TakeInsSuffix+".>")
|
||||
if strings.Contains(s, "LEDGER") || (strings.HasPrefix(s, "$JS.ACK.") && !takeIns) {
|
||||
t.Errorf("the tool runner's runtime may %s on the restricted stream", s)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -254,6 +254,19 @@ func heardConsumer(p Principal, h Heard) Consumer {
|
||||
// under a name of its own, since only a work queue shares one (lead answer A-397; mesh-tools bus.ToolsConsumerOf).
|
||||
const ToolsSuffix = "_tools"
|
||||
|
||||
// TakeInsSuffix ends the name of a module's own second durable on the shared events stream, `<node>_<module>_takeins`,
|
||||
// which the module makes itself and hears take-in.taken on alone, so a take-in never waits behind its other events (design
|
||||
// 47 H2 H-A-500 (b) and its addenda): every module principal is granted it, none special-cased.
|
||||
const TakeInsSuffix = "_takeins"
|
||||
|
||||
// takeInsGrants are what a module publishes to make, ask about, pull from and acknowledge its takeins durable on the shared
|
||||
// events stream (TakeInsSuffix): the create by its name alone, every filter in FilterSubjects.
|
||||
func takeInsGrants(durable string) []string {
|
||||
d := durable + TakeInsSuffix
|
||||
return []string{"$JS.API.CONSUMER.CREATE." + EventsStream + "." + d, "$JS.API.CONSUMER.INFO." + EventsStream + "." + d,
|
||||
"$JS.API.CONSUMER.MSG.NEXT." + EventsStream + "." + d, "$JS.ACK." + EventsStream + "." + d + ".>"}
|
||||
}
|
||||
|
||||
// readerGrants are what a reader publishes to ask about, pull from and acknowledge a durable consumer on a stream: for the
|
||||
// module's program's name and for its tool runner's twin (A-397); and the create and delete of the twin by its name alone,
|
||||
// which the tool runner makes from the membership's spec and removes when the module leaves the node (design 47 H2, H-A-472
|
||||
|
||||
@@ -1159,6 +1159,8 @@ func permissionsFor(p Principal) (Permissions, error) {
|
||||
// which asks for these permissions to build the consumer and would ask forever. A
|
||||
// subject for a consumer that turns out not to exist grants nothing anybody can use.
|
||||
pub = append(pub, readerGrants(consumerStream(p), consumerDurable(p))...)
|
||||
// 2d. Its own takeins durable on the shared events stream, made and heard by the module (H-A-500 (b)).
|
||||
pub = append(pub, takeInsGrants(consumerDurable(p))...)
|
||||
|
||||
// 3. Seats it holds: full participation. But mesh-broker's acting verbs, which nobody serves on the bus (busstate.go).
|
||||
for _, s := range p.Holds {
|
||||
@@ -1326,6 +1328,8 @@ func permissionsFor(p Principal) (Permissions, error) {
|
||||
// And the module streams it hears, each through its own consumer there (novox/hq ADR 0363 §8) — never
|
||||
// a restricted one, which only a module on an account of its own hears (ADR 0376 §1).
|
||||
pub = append(pub, heardGrants(own, own.Hears)...)
|
||||
// Its takeins durable on the shared events stream, as a module on an account of its own has (H-A-500 (b)).
|
||||
pub = append(pub, takeInsGrants(consumerDurable(own))...)
|
||||
if _, consumes := ConsumerFor(own); !consumes {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ accounts {
|
||||
allow_responses: { max: 1, ttl: "1m" }
|
||||
} }
|
||||
{ user: "one.mesh-delivery-watchman", password: "$2a$11$wwwwwwwwwwwwwwwwwwwwww", permissions: {
|
||||
publish: { allow: ["$JS.ACK.DEAD_LETTER_NOTICES.mesh-delivery-watchman.>", "$JS.ACK.EVENTS.one_mesh-delivery-watchman.>", "$JS.ACK.EVENTS.one_mesh-delivery-watchman_tools.>", "$JS.API.CONSUMER.CREATE.DEAD_LETTER_NOTICES.mesh-delivery-watchman", "$JS.API.CONSUMER.CREATE.EVENTS.one_mesh-delivery-watchman_tools", "$JS.API.CONSUMER.CREATE.KV_mesh-grants_memberships.*.$KV.mesh-grants_memberships.one.mesh-delivery-watchman", "$JS.API.CONSUMER.DELETE.EVENTS.one_mesh-delivery-watchman_tools", "$JS.API.CONSUMER.DELETE.KV_mesh-grants_memberships.>", "$JS.API.CONSUMER.INFO.DEAD_LETTER_NOTICES.controller", "$JS.API.CONSUMER.INFO.DEAD_LETTER_NOTICES.mesh-delivery-watchman", "$JS.API.CONSUMER.INFO.EVENTS.one_mesh-delivery-watchman", "$JS.API.CONSUMER.INFO.EVENTS.one_mesh-delivery-watchman_tools", "$JS.API.CONSUMER.MSG.NEXT.DEAD_LETTER_NOTICES.mesh-delivery-watchman", "$JS.API.CONSUMER.MSG.NEXT.EVENTS.one_mesh-delivery-watchman", "$JS.API.CONSUMER.MSG.NEXT.EVENTS.one_mesh-delivery-watchman_tools", "$JS.API.DIRECT.GET.KV_mesh-grants_memberships.$KV.mesh-grants_memberships.one.mesh-delivery-watchman", "$JS.API.DIRECT.GET.PROV_APPLIED.>", "$JS.API.STREAM.INFO.DEAD_LETTERS", "$JS.API.STREAM.INFO.DEAD_LETTER_NOTICES", "$JS.API.STREAM.INFO.KV_mesh-grants_memberships", "$JS.API.STREAM.INFO.PROV_APPLIED", "$JS.API.STREAM.MSG.GET.DEAD_LETTERS", "$JS.API.STREAM.MSG.GET.PROV_APPLIED", "$JS.API.STREAM.NAMES", "$JS.FC.KV_mesh-grants_memberships.>", "mesh.bus.connz", "mesh.events.dead.>", "mesh.seat.*.accept.>", "mesh.seat.*.call.*.*.one~mesh-delivery-watchman", "mesh.seat.*.call.*.one~mesh-delivery-watchman", "mesh.seat.*.tool.>"], deny: ["mesh.seat.node-launcher.tool.secret", "mesh.seat.node-launcher.tool.secret.*", "mesh.seat.node-launcher.call.secret.>", "mesh.seat.mesh-broker.call.apply.>", "mesh.seat.mesh-broker.call.create.>", "mesh.seat.mesh-broker.call.drop.>", "mesh.seat.mesh-broker.call.recreate.>", "mesh.seat.mesh-broker.tool.apply", "mesh.seat.mesh-broker.tool.create", "mesh.seat.mesh-broker.tool.drop", "mesh.seat.mesh-broker.tool.recreate"] }
|
||||
publish: { allow: ["$JS.ACK.DEAD_LETTER_NOTICES.mesh-delivery-watchman.>", "$JS.ACK.EVENTS.one_mesh-delivery-watchman.>", "$JS.ACK.EVENTS.one_mesh-delivery-watchman_takeins.>", "$JS.ACK.EVENTS.one_mesh-delivery-watchman_tools.>", "$JS.API.CONSUMER.CREATE.DEAD_LETTER_NOTICES.mesh-delivery-watchman", "$JS.API.CONSUMER.CREATE.EVENTS.one_mesh-delivery-watchman_takeins", "$JS.API.CONSUMER.CREATE.EVENTS.one_mesh-delivery-watchman_tools", "$JS.API.CONSUMER.CREATE.KV_mesh-grants_memberships.*.$KV.mesh-grants_memberships.one.mesh-delivery-watchman", "$JS.API.CONSUMER.DELETE.EVENTS.one_mesh-delivery-watchman_tools", "$JS.API.CONSUMER.DELETE.KV_mesh-grants_memberships.>", "$JS.API.CONSUMER.INFO.DEAD_LETTER_NOTICES.controller", "$JS.API.CONSUMER.INFO.DEAD_LETTER_NOTICES.mesh-delivery-watchman", "$JS.API.CONSUMER.INFO.EVENTS.one_mesh-delivery-watchman", "$JS.API.CONSUMER.INFO.EVENTS.one_mesh-delivery-watchman_takeins", "$JS.API.CONSUMER.INFO.EVENTS.one_mesh-delivery-watchman_tools", "$JS.API.CONSUMER.MSG.NEXT.DEAD_LETTER_NOTICES.mesh-delivery-watchman", "$JS.API.CONSUMER.MSG.NEXT.EVENTS.one_mesh-delivery-watchman", "$JS.API.CONSUMER.MSG.NEXT.EVENTS.one_mesh-delivery-watchman_takeins", "$JS.API.CONSUMER.MSG.NEXT.EVENTS.one_mesh-delivery-watchman_tools", "$JS.API.DIRECT.GET.KV_mesh-grants_memberships.$KV.mesh-grants_memberships.one.mesh-delivery-watchman", "$JS.API.DIRECT.GET.PROV_APPLIED.>", "$JS.API.STREAM.INFO.DEAD_LETTERS", "$JS.API.STREAM.INFO.DEAD_LETTER_NOTICES", "$JS.API.STREAM.INFO.KV_mesh-grants_memberships", "$JS.API.STREAM.INFO.PROV_APPLIED", "$JS.API.STREAM.MSG.GET.DEAD_LETTERS", "$JS.API.STREAM.MSG.GET.PROV_APPLIED", "$JS.API.STREAM.NAMES", "$JS.FC.KV_mesh-grants_memberships.>", "mesh.bus.connz", "mesh.events.dead.>", "mesh.seat.*.accept.>", "mesh.seat.*.call.*.*.one~mesh-delivery-watchman", "mesh.seat.*.call.*.one~mesh-delivery-watchman", "mesh.seat.*.tool.>"], deny: ["mesh.seat.node-launcher.tool.secret", "mesh.seat.node-launcher.tool.secret.*", "mesh.seat.node-launcher.call.secret.>", "mesh.seat.mesh-broker.call.apply.>", "mesh.seat.mesh-broker.call.create.>", "mesh.seat.mesh-broker.call.drop.>", "mesh.seat.mesh-broker.call.recreate.>", "mesh.seat.mesh-broker.tool.apply", "mesh.seat.mesh-broker.tool.create", "mesh.seat.mesh-broker.tool.drop", "mesh.seat.mesh-broker.tool.recreate"] }
|
||||
subscribe: { allow: ["$JS.EVENT.ADVISORY.CONSUMER.DELETED.>", "$SRV.INFO", "$SRV.INFO.mesh-delivery-watchman", "$SRV.INFO.mesh-delivery-watchman.>", "$SRV.PING", "$SRV.PING.mesh-delivery-watchman", "$SRV.PING.mesh-delivery-watchman.>", "$SRV.STATS", "$SRV.STATS.mesh-delivery-watchman", "$SRV.STATS.mesh-delivery-watchman.>", "_INBOX.one.mesh-delivery-watchman.>", "mesh.bus.connect", "mesh.bus.disconnect", "mesh.control.*.tools-alive", "mesh.events.dead.>", "mesh.mod.*.event.provisioner.failing", "mesh.mod.*.event.provisioner.recovered", "mesh.mod.mesh-delivery-watchman.call.>", "mesh.mod.mesh-delivery-watchman.tool.>", "mesh.mod.nats.event.bus.connection-closed", "mesh.mod.nats.event.bus.slow-consumer", "mesh.mod.power.event.*", "mesh.seat.mesh-self-check.event.checked", "prov.applied.>"] }
|
||||
allow_responses: { max: 1, ttl: "1m" }
|
||||
} }
|
||||
@@ -47,17 +47,17 @@ accounts {
|
||||
subscribe: { allow: ["_INBOX.one.nats.>"] }
|
||||
} }
|
||||
{ user: "one.telegram", password: "$2a$11$tttttttttttttttttttttt", permissions: {
|
||||
publish: { allow: ["$JS.ACK.EVENTS.one_telegram.>", "$JS.ACK.EVENTS.one_telegram_tools.>", "$JS.ACK.SEAT_TELEGRAM_SENDER.SEAT_TELEGRAM_SENDER_worker.>", "$JS.API.CONSUMER.CREATE.EVENTS.one_telegram_tools", "$JS.API.CONSUMER.CREATE.KV_mesh-grants_memberships.*.$KV.mesh-grants_memberships.one.telegram", "$JS.API.CONSUMER.DELETE.EVENTS.one_telegram_tools", "$JS.API.CONSUMER.DELETE.KV_mesh-grants_memberships.>", "$JS.API.CONSUMER.INFO.EVENTS.one_telegram", "$JS.API.CONSUMER.INFO.EVENTS.one_telegram_tools", "$JS.API.CONSUMER.INFO.SEAT_TELEGRAM_SENDER.SEAT_TELEGRAM_SENDER_worker", "$JS.API.CONSUMER.MSG.NEXT.EVENTS.one_telegram", "$JS.API.CONSUMER.MSG.NEXT.EVENTS.one_telegram_tools", "$JS.API.CONSUMER.MSG.NEXT.SEAT_TELEGRAM_SENDER.SEAT_TELEGRAM_SENDER_worker", "$JS.API.DIRECT.GET.KV_mesh-grants_memberships.$KV.mesh-grants_memberships.one.telegram", "$JS.API.STREAM.INFO.KV_mesh-grants_memberships", "$JS.API.STREAM.NAMES", "$JS.FC.KV_mesh-grants_memberships.>", "mesh.seat.*.accept.>", "mesh.seat.*.call.*.*.one~telegram", "mesh.seat.*.call.*.one~telegram", "mesh.seat.*.tool.>", "mesh.seat.telegram-sender.event.delivered", "mesh.seat.telegram-sender.event.failed"], deny: ["mesh.seat.node-launcher.tool.secret", "mesh.seat.node-launcher.tool.secret.*", "mesh.seat.node-launcher.call.secret.>", "mesh.seat.mesh-broker.call.apply.>", "mesh.seat.mesh-broker.call.create.>", "mesh.seat.mesh-broker.call.drop.>", "mesh.seat.mesh-broker.call.recreate.>", "mesh.seat.mesh-broker.tool.apply", "mesh.seat.mesh-broker.tool.create", "mesh.seat.mesh-broker.tool.drop", "mesh.seat.mesh-broker.tool.recreate"] }
|
||||
publish: { allow: ["$JS.ACK.EVENTS.one_telegram.>", "$JS.ACK.EVENTS.one_telegram_takeins.>", "$JS.ACK.EVENTS.one_telegram_tools.>", "$JS.ACK.SEAT_TELEGRAM_SENDER.SEAT_TELEGRAM_SENDER_worker.>", "$JS.API.CONSUMER.CREATE.EVENTS.one_telegram_takeins", "$JS.API.CONSUMER.CREATE.EVENTS.one_telegram_tools", "$JS.API.CONSUMER.CREATE.KV_mesh-grants_memberships.*.$KV.mesh-grants_memberships.one.telegram", "$JS.API.CONSUMER.DELETE.EVENTS.one_telegram_tools", "$JS.API.CONSUMER.DELETE.KV_mesh-grants_memberships.>", "$JS.API.CONSUMER.INFO.EVENTS.one_telegram", "$JS.API.CONSUMER.INFO.EVENTS.one_telegram_takeins", "$JS.API.CONSUMER.INFO.EVENTS.one_telegram_tools", "$JS.API.CONSUMER.INFO.SEAT_TELEGRAM_SENDER.SEAT_TELEGRAM_SENDER_worker", "$JS.API.CONSUMER.MSG.NEXT.EVENTS.one_telegram", "$JS.API.CONSUMER.MSG.NEXT.EVENTS.one_telegram_takeins", "$JS.API.CONSUMER.MSG.NEXT.EVENTS.one_telegram_tools", "$JS.API.CONSUMER.MSG.NEXT.SEAT_TELEGRAM_SENDER.SEAT_TELEGRAM_SENDER_worker", "$JS.API.DIRECT.GET.KV_mesh-grants_memberships.$KV.mesh-grants_memberships.one.telegram", "$JS.API.STREAM.INFO.KV_mesh-grants_memberships", "$JS.API.STREAM.NAMES", "$JS.FC.KV_mesh-grants_memberships.>", "mesh.seat.*.accept.>", "mesh.seat.*.call.*.*.one~telegram", "mesh.seat.*.call.*.one~telegram", "mesh.seat.*.tool.>", "mesh.seat.telegram-sender.event.delivered", "mesh.seat.telegram-sender.event.failed"], deny: ["mesh.seat.node-launcher.tool.secret", "mesh.seat.node-launcher.tool.secret.*", "mesh.seat.node-launcher.call.secret.>", "mesh.seat.mesh-broker.call.apply.>", "mesh.seat.mesh-broker.call.create.>", "mesh.seat.mesh-broker.call.drop.>", "mesh.seat.mesh-broker.call.recreate.>", "mesh.seat.mesh-broker.tool.apply", "mesh.seat.mesh-broker.tool.create", "mesh.seat.mesh-broker.tool.drop", "mesh.seat.mesh-broker.tool.recreate"] }
|
||||
subscribe: { allow: ["$JS.EVENT.ADVISORY.CONSUMER.CREATED.SEAT_TELEGRAM_SENDER.SEAT_TELEGRAM_SENDER_worker", "$JS.EVENT.ADVISORY.CONSUMER.DELETED.SEAT_TELEGRAM_SENDER.SEAT_TELEGRAM_SENDER_worker", "$SRV.INFO", "$SRV.INFO.telegram", "$SRV.INFO.telegram.>", "$SRV.PING", "$SRV.PING.telegram", "$SRV.PING.telegram.>", "$SRV.STATS", "$SRV.STATS.telegram", "$SRV.STATS.telegram.>", "_INBOX.one.telegram.>", "mesh.mod.telegram.call.>", "mesh.mod.telegram.tool.>", "mesh.seat.telegram-sender.accept.send"] }
|
||||
allow_responses: { max: 1, ttl: "1m" }
|
||||
} }
|
||||
{ user: "two.audit", password: "$2a$11$aaaaaaaaaaaaaaaaaaaaaa", permissions: {
|
||||
publish: { allow: ["$JS.ACK.EVENTS.two_audit.>", "$JS.ACK.EVENTS.two_audit_tools.>", "$JS.API.CONSUMER.CREATE.EVENTS.two_audit_tools", "$JS.API.CONSUMER.CREATE.KV_mesh-grants_memberships.*.$KV.mesh-grants_memberships.two.audit", "$JS.API.CONSUMER.DELETE.EVENTS.two_audit_tools", "$JS.API.CONSUMER.DELETE.KV_mesh-grants_memberships.>", "$JS.API.CONSUMER.INFO.EVENTS.two_audit", "$JS.API.CONSUMER.INFO.EVENTS.two_audit_tools", "$JS.API.CONSUMER.MSG.NEXT.EVENTS.two_audit", "$JS.API.CONSUMER.MSG.NEXT.EVENTS.two_audit_tools", "$JS.API.DIRECT.GET.KV_mesh-grants_memberships.$KV.mesh-grants_memberships.two.audit", "$JS.API.STREAM.INFO.KV_mesh-grants_memberships", "$JS.API.STREAM.NAMES", "$JS.FC.KV_mesh-grants_memberships.>", "mesh.seat.*.accept.>", "mesh.seat.*.call.*.*.two~audit", "mesh.seat.*.call.*.two~audit", "mesh.seat.*.tool.>"], deny: ["mesh.seat.node-launcher.tool.secret", "mesh.seat.node-launcher.tool.secret.*", "mesh.seat.node-launcher.call.secret.>", "mesh.seat.mesh-broker.call.apply.>", "mesh.seat.mesh-broker.call.create.>", "mesh.seat.mesh-broker.call.drop.>", "mesh.seat.mesh-broker.call.recreate.>", "mesh.seat.mesh-broker.tool.apply", "mesh.seat.mesh-broker.tool.create", "mesh.seat.mesh-broker.tool.drop", "mesh.seat.mesh-broker.tool.recreate"] }
|
||||
publish: { allow: ["$JS.ACK.EVENTS.two_audit.>", "$JS.ACK.EVENTS.two_audit_takeins.>", "$JS.ACK.EVENTS.two_audit_tools.>", "$JS.API.CONSUMER.CREATE.EVENTS.two_audit_takeins", "$JS.API.CONSUMER.CREATE.EVENTS.two_audit_tools", "$JS.API.CONSUMER.CREATE.KV_mesh-grants_memberships.*.$KV.mesh-grants_memberships.two.audit", "$JS.API.CONSUMER.DELETE.EVENTS.two_audit_tools", "$JS.API.CONSUMER.DELETE.KV_mesh-grants_memberships.>", "$JS.API.CONSUMER.INFO.EVENTS.two_audit", "$JS.API.CONSUMER.INFO.EVENTS.two_audit_takeins", "$JS.API.CONSUMER.INFO.EVENTS.two_audit_tools", "$JS.API.CONSUMER.MSG.NEXT.EVENTS.two_audit", "$JS.API.CONSUMER.MSG.NEXT.EVENTS.two_audit_takeins", "$JS.API.CONSUMER.MSG.NEXT.EVENTS.two_audit_tools", "$JS.API.DIRECT.GET.KV_mesh-grants_memberships.$KV.mesh-grants_memberships.two.audit", "$JS.API.STREAM.INFO.KV_mesh-grants_memberships", "$JS.API.STREAM.NAMES", "$JS.FC.KV_mesh-grants_memberships.>", "mesh.seat.*.accept.>", "mesh.seat.*.call.*.*.two~audit", "mesh.seat.*.call.*.two~audit", "mesh.seat.*.tool.>"], deny: ["mesh.seat.node-launcher.tool.secret", "mesh.seat.node-launcher.tool.secret.*", "mesh.seat.node-launcher.call.secret.>", "mesh.seat.mesh-broker.call.apply.>", "mesh.seat.mesh-broker.call.create.>", "mesh.seat.mesh-broker.call.drop.>", "mesh.seat.mesh-broker.call.recreate.>", "mesh.seat.mesh-broker.tool.apply", "mesh.seat.mesh-broker.tool.create", "mesh.seat.mesh-broker.tool.drop", "mesh.seat.mesh-broker.tool.recreate"] }
|
||||
subscribe: { allow: ["$SRV.INFO", "$SRV.INFO.audit", "$SRV.INFO.audit.>", "$SRV.PING", "$SRV.PING.audit", "$SRV.PING.audit.>", "$SRV.STATS", "$SRV.STATS.audit", "$SRV.STATS.audit.>", "_INBOX.two.audit.>", "mesh.mod.audit.call.>", "mesh.mod.audit.tool.>", "mesh.mod.shop.event.order.placed"] }
|
||||
allow_responses: { max: 1, ttl: "1m" }
|
||||
} }
|
||||
{ user: "two.shop", password: "$2a$11$ssssssssssssssssssssss", permissions: {
|
||||
publish: { allow: ["$JS.ACK.EVENTS.two_shop.>", "$JS.ACK.EVENTS.two_shop_tools.>", "$JS.API.CONSUMER.CREATE.EVENTS.two_shop_tools", "$JS.API.CONSUMER.CREATE.KV_mesh-grants_memberships.*.$KV.mesh-grants_memberships.two.shop", "$JS.API.CONSUMER.DELETE.EVENTS.two_shop_tools", "$JS.API.CONSUMER.DELETE.KV_mesh-grants_memberships.>", "$JS.API.CONSUMER.INFO.EVENTS.two_shop", "$JS.API.CONSUMER.INFO.EVENTS.two_shop_tools", "$JS.API.CONSUMER.MSG.NEXT.EVENTS.two_shop", "$JS.API.CONSUMER.MSG.NEXT.EVENTS.two_shop_tools", "$JS.API.DIRECT.GET.KV_mesh-grants_memberships.$KV.mesh-grants_memberships.two.shop", "$JS.API.STREAM.INFO.KV_mesh-grants_memberships", "$JS.API.STREAM.NAMES", "$JS.FC.KV_mesh-grants_memberships.>", "mesh.mod.shop.event.order.placed", "mesh.seat.*.accept.>", "mesh.seat.*.call.*.*.two~shop", "mesh.seat.*.call.*.two~shop", "mesh.seat.*.tool.>", "mesh.seat.telegram-sender.accept.send"], deny: ["mesh.seat.node-launcher.tool.secret", "mesh.seat.node-launcher.tool.secret.*", "mesh.seat.node-launcher.call.secret.>", "mesh.seat.mesh-broker.call.apply.>", "mesh.seat.mesh-broker.call.create.>", "mesh.seat.mesh-broker.call.drop.>", "mesh.seat.mesh-broker.call.recreate.>", "mesh.seat.mesh-broker.tool.apply", "mesh.seat.mesh-broker.tool.create", "mesh.seat.mesh-broker.tool.drop", "mesh.seat.mesh-broker.tool.recreate"] }
|
||||
publish: { allow: ["$JS.ACK.EVENTS.two_shop.>", "$JS.ACK.EVENTS.two_shop_takeins.>", "$JS.ACK.EVENTS.two_shop_tools.>", "$JS.API.CONSUMER.CREATE.EVENTS.two_shop_takeins", "$JS.API.CONSUMER.CREATE.EVENTS.two_shop_tools", "$JS.API.CONSUMER.CREATE.KV_mesh-grants_memberships.*.$KV.mesh-grants_memberships.two.shop", "$JS.API.CONSUMER.DELETE.EVENTS.two_shop_tools", "$JS.API.CONSUMER.DELETE.KV_mesh-grants_memberships.>", "$JS.API.CONSUMER.INFO.EVENTS.two_shop", "$JS.API.CONSUMER.INFO.EVENTS.two_shop_takeins", "$JS.API.CONSUMER.INFO.EVENTS.two_shop_tools", "$JS.API.CONSUMER.MSG.NEXT.EVENTS.two_shop", "$JS.API.CONSUMER.MSG.NEXT.EVENTS.two_shop_takeins", "$JS.API.CONSUMER.MSG.NEXT.EVENTS.two_shop_tools", "$JS.API.DIRECT.GET.KV_mesh-grants_memberships.$KV.mesh-grants_memberships.two.shop", "$JS.API.STREAM.INFO.KV_mesh-grants_memberships", "$JS.API.STREAM.NAMES", "$JS.FC.KV_mesh-grants_memberships.>", "mesh.mod.shop.event.order.placed", "mesh.seat.*.accept.>", "mesh.seat.*.call.*.*.two~shop", "mesh.seat.*.call.*.two~shop", "mesh.seat.*.tool.>", "mesh.seat.telegram-sender.accept.send"], deny: ["mesh.seat.node-launcher.tool.secret", "mesh.seat.node-launcher.tool.secret.*", "mesh.seat.node-launcher.call.secret.>", "mesh.seat.mesh-broker.call.apply.>", "mesh.seat.mesh-broker.call.create.>", "mesh.seat.mesh-broker.call.drop.>", "mesh.seat.mesh-broker.call.recreate.>", "mesh.seat.mesh-broker.tool.apply", "mesh.seat.mesh-broker.tool.create", "mesh.seat.mesh-broker.tool.drop", "mesh.seat.mesh-broker.tool.recreate"] }
|
||||
subscribe: { allow: ["$SRV.INFO", "$SRV.INFO.shop", "$SRV.INFO.shop.>", "$SRV.PING", "$SRV.PING.shop", "$SRV.PING.shop.>", "$SRV.STATS", "$SRV.STATS.shop", "$SRV.STATS.shop.>", "_INBOX.two.shop.>", "mesh.mod.shop.call.>", "mesh.mod.shop.tool.>"] }
|
||||
allow_responses: { max: 1, ttl: "1m" }
|
||||
} }
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -75,3 +75,31 @@ func TestTheRunnersTwinIsTheMembershipsSpec(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Design 47 H2, H-A-500 (b) and its addenda: every module principal, on an account of its own or carried by a tool runner,
|
||||
// is granted the create, information, pull and acknowledgement of its own takeins durable on the shared events stream.
|
||||
func TestEveryModuleIsGrantedItsTakeInsDurable(t *testing.T) {
|
||||
takeIns := func(node, module string) []string {
|
||||
d := node + "_" + module + TakeInsSuffix
|
||||
return []string{"$JS.API.CONSUMER.CREATE.EVENTS." + d, "$JS.API.CONSUMER.INFO.EVENTS." + d,
|
||||
"$JS.API.CONSUMER.MSG.NEXT.EVENTS." + d, "$JS.ACK.EVENTS." + d + ".>"}
|
||||
}
|
||||
for _, c := range []struct {
|
||||
name string
|
||||
p Principal
|
||||
module string
|
||||
}{
|
||||
{"a module's own account", Principal{Kind: KindModule, Node: "a", Module: "shop"}, "shop"},
|
||||
{"a module a tool runner carries", Principal{Kind: KindNodeTools, Node: "a", Module: "node-tools", Carries: []Declared{{Module: "shop"}}}, "shop"},
|
||||
} {
|
||||
perms, err := PermissionsFor(c.p)
|
||||
if err != nil {
|
||||
t.Fatalf("%s: %v", c.name, err)
|
||||
}
|
||||
for _, g := range takeIns("a", c.module) {
|
||||
if !slices.Contains(perms.Publish, g) {
|
||||
t.Errorf("%s is not granted %s", c.name, g)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ func (c *askCreator) RaiseMaxBytes(string, int64) (int64, bool, error) {
|
||||
func (c *askCreator) SourceFilter(string, string, string) (string, bool, error) {
|
||||
return "", false, nil
|
||||
}
|
||||
func (c *askCreator) AllowMsgTTL(string, time.Duration) (bool, error) { return false, nil }
|
||||
|
||||
// A seat whose queues came with G (mesh-builds) gets its work-queue ask stream from the seat list, as the controller made one for
|
||||
// every seat before G; a seat that accepts nothing gets none, and a stream the bus holds is never made again (lead-47, 2026-11-15).
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/nats-io/nats.go/jetstream"
|
||||
|
||||
@@ -74,6 +75,10 @@ type Creator interface {
|
||||
// messages and every other setting, the stream not made again (design 47 H H-A-145). It answers the filter it held and
|
||||
// whether it changed; a stream with no source from `source` is left as it is.
|
||||
SourceFilter(stream, source, filter string) (from string, changed bool, err error)
|
||||
// AllowMsgTTL turns on per-message time to live on a stream the bus holds, its delete markers living markerTTL, when it
|
||||
// is off, and changes nothing else (design 47 H2 H-A-501, corrected): a state declared key-ttl whose bucket was made
|
||||
// before the declaration. It answers whether it turned it on; one on already is left as it is. It never turns it off.
|
||||
AllowMsgTTL(stream string, markerTTL time.Duration) (turned bool, err error)
|
||||
}
|
||||
|
||||
// Raise is one held stream's size cap raised to the manifest's, said in the event and the journal.
|
||||
@@ -126,6 +131,24 @@ type creations struct {
|
||||
// refused is, by stream, the refusal of the last addition of subjects (an overlap with another stream, say), so a
|
||||
// refusal that stands is said once and not at every pass; a success or a different refusal says again.
|
||||
refused map[string]string
|
||||
// ttl is, by stream, the manifest digest at which its per-message time to live was last compared with the manifest's
|
||||
// key-ttl, so the bus is asked once per manifest (a hand assert asks again).
|
||||
ttl map[string]string
|
||||
}
|
||||
|
||||
func (c *creations) ttlAt(stream string) string {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
return c.ttl[stream]
|
||||
}
|
||||
|
||||
func (c *creations) keepTTL(stream, digest string) {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
if c.ttl == nil {
|
||||
c.ttl = map[string]string{}
|
||||
}
|
||||
c.ttl[stream] = digest
|
||||
}
|
||||
|
||||
// refusedAgain says whether this refusal of an addition to the stream was the last one said, and keeps it.
|
||||
@@ -265,6 +288,26 @@ func createMissing(c Creator, done *creations, a *Assertion, m catalogue.Manifes
|
||||
made = append(made, fmt.Sprintf("%s %s size cap raised from %d to %d bytes", it.Kind, it.Stream, from, it.Composed.MaxBytes))
|
||||
}
|
||||
}
|
||||
// A held bucket of a state declared key-ttl gets per-message time to live when it lacks it, add-only like the cap: a
|
||||
// bucket made before its state was declared key-ttl refuses every key written with a time to live (design 47 H2
|
||||
// H-A-501, corrected). Compared once per manifest.
|
||||
for i := range a.Items {
|
||||
it := &a.Items[i]
|
||||
cfg, ok := cfgs[it.Stream]
|
||||
if it.Held == nil || it.Kind != "bucket" || !ok || !cfg.AllowMsgTTL || (!force && done.ttlAt(it.Stream) == a.Manifest) {
|
||||
continue
|
||||
}
|
||||
turned, err := c.AllowMsgTTL(it.Stream, cfg.SubjectDeleteMarkerTTL)
|
||||
if err != nil {
|
||||
it.Created = ItemNotCreated + "per-message time to live not turned on: " + err.Error() + " (tried again at the next event)"
|
||||
continue
|
||||
}
|
||||
done.keepTTL(it.Stream, a.Manifest)
|
||||
if turned {
|
||||
it.Created = "per-message time to live turned on (its state is declared key-ttl)"
|
||||
made = append(made, it.Kind+" "+it.Stream+" per-message time to live turned on, its state declared key-ttl")
|
||||
}
|
||||
}
|
||||
if len(made) > 0 {
|
||||
a.Asserted = true
|
||||
}
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
package grants
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||
|
||||
"mesh-grants/internal/buscompose"
|
||||
)
|
||||
|
||||
// raiser is a Creator that holds one stream at a cap and records the cap it is raised to.
|
||||
@@ -41,6 +45,40 @@ func TestAStatesDeclaredCapReachesItsBucket(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// ttlTurner is a Creator that records each held stream whose per-message time to live it turns on.
|
||||
type ttlTurner struct {
|
||||
Creator
|
||||
turned []string
|
||||
}
|
||||
|
||||
func (r *ttlTurner) AllowMsgTTL(stream string, marker time.Duration) (bool, error) {
|
||||
r.turned = append(r.turned, fmt.Sprintf("%s %s", stream, marker))
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (r *ttlTurner) RaiseMaxBytes(string, int64) (int64, bool, error) { return 0, false, nil }
|
||||
|
||||
// A held bucket of a state declared key-ttl gets per-message time to live, once per manifest, and is said (design 47 H2
|
||||
// H-A-501, corrected); a bucket of a state with no key-ttl is not touched.
|
||||
func TestAHeldKeyTTLStateGetsPerMessageTTL(t *testing.T) {
|
||||
m := catalogue.Manifest{Module: "mesh-delivery-indexer", State: []catalogue.StateDeclaration{{Name: "heard", KeyTTL: true}, {Name: "plain"}}}
|
||||
a := Assertion{Manifest: "d", Items: Composed(m, nil)}
|
||||
for i := range a.Items {
|
||||
a.Items[i].Held = &Limits{}
|
||||
}
|
||||
r, done := &ttlTurner{}, &creations{}
|
||||
made, _ := createMissing(r, done, &a, m, nil, false)
|
||||
if want := []string{"KV_mesh-delivery-indexer_heard " + buscompose.KeyTTLMarkerTTL.String()}; !slices.Equal(r.turned, want) {
|
||||
t.Fatalf("turned on %v, want %v", r.turned, want)
|
||||
}
|
||||
if !a.Asserted || !slices.ContainsFunc(made, func(s string) bool { return strings.Contains(s, "per-message time to live turned on") }) {
|
||||
t.Errorf("asserted %v, said %v; want the turning on said", a.Asserted, made)
|
||||
}
|
||||
if createMissing(r, done, &a, m, nil, false); len(r.turned) != 1 {
|
||||
t.Errorf("asked again at the same manifest: %v", r.turned)
|
||||
}
|
||||
}
|
||||
|
||||
// adder is a Creator that records the subjects it is asked to add to a held stream.
|
||||
type adder struct {
|
||||
Creator
|
||||
|
||||
Reference in New Issue
Block a user