A13 event-unsaid-and-owed-tools: the assigner answers the verbs owed, owed-say and owed-drop of mesh-wants, an event owed past event-unsaid-after is the finding event-unsaid, the three tools call the verbs
Builds: design 47 H2b §832 6.
This commit is contained in:
@@ -614,6 +614,9 @@ func follow(ctx context.Context, js jetstream.JetStream, nc process.Subscriber,
|
||||
if p.owed.first, p.owed.last, err = owedSetting(getenv); err != nil {
|
||||
return err
|
||||
}
|
||||
if p.owed.unsaid, err = durationFile(getenv("MESH_ASSIGNER_EVENT_UNSAID_AFTER_FILE")); err != nil { // design 47 H2b §832 6.
|
||||
return err
|
||||
}
|
||||
// The setting pass-stall-seconds: a pass still running after it says which phase it is in (design 47 H2 H-A-635).
|
||||
if p.passStall, err = passStallSetting(getenv); err != nil {
|
||||
return err
|
||||
@@ -740,7 +743,8 @@ func follow(ctx context.Context, js jetstream.JetStream, nc process.Subscriber,
|
||||
return err
|
||||
}
|
||||
verbs := compositionVerbs(runs, steps, record, run)
|
||||
maps.Copy(verbs, dropVerb(steps)) // the seat's act drop (§778, H-A-404)
|
||||
maps.Copy(verbs, dropVerb(steps)) // the seat's act drop (§778, H-A-404)
|
||||
maps.Copy(verbs, owedVerbs(p, record)) // the owed events' read, say and drop (§832 6., H-A-847)
|
||||
if p.graph != nil {
|
||||
maps.Copy(verbs, keepNowVerb(ctx, p)) // the keeping by hand (§813 (2), H-A-417)
|
||||
}
|
||||
|
||||
@@ -3,8 +3,10 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -443,6 +445,101 @@ func TestTheWaitOnAnOutsideCause(t *testing.T) {
|
||||
t.Errorf("AC-832e: a record with ending said %v, want only its end", r.events)
|
||||
}
|
||||
})
|
||||
// Design 47 H2b §832 6. (1984/AC-832h, AC-832i, AC-832j, AC-832k, AC-832s): past event-unsaid-after an owed event is a finding, cleared
|
||||
// when said; assigner_owed_say says one now; assigner_owed_drop of a wait-ended does the rest of the wait's end; the tools call the
|
||||
// seat's verbs and say so when the program is stopped.
|
||||
t.Run("an owed event is the finding event-unsaid past event-unsaid-after, said by hand or dropped with what waited on it; the tools call the verbs (§832 6.)", func(t *testing.T) {
|
||||
r := newOutsideRig(t)
|
||||
r.p.wake = func() {}
|
||||
r.p.owed.unsaid = 5 * time.Minute
|
||||
r.p.findings.Keys = func() ([]string, error) {
|
||||
var ks []string
|
||||
for k := range r.found {
|
||||
ks = append(ks, k)
|
||||
}
|
||||
return ks, nil
|
||||
}
|
||||
r.notRunning = true
|
||||
r.cond("machine.hub.silent", "ace")
|
||||
r.refuse = 100
|
||||
r.review(false, nil)
|
||||
owed := r.p.owedAll()
|
||||
if len(owed) != 1 || len(r.found) != 1 {
|
||||
t.Fatalf("owed %+v findings %v", owed, r.found)
|
||||
}
|
||||
r.now = r.now.Add(6 * time.Minute)
|
||||
r.p.owedFindings()
|
||||
key := unsaidKey(owed[0].ID)
|
||||
if !r.found[strings.TrimPrefix(key, "")] || strings.Contains(key, "src2:") || strings.Contains(key, "T") {
|
||||
t.Fatalf("AC-832h: findings %v, want %s (the id with times as Unix nanoseconds)", r.found, key)
|
||||
}
|
||||
// AC-832k: a pass that would make the id owed already makes nothing
|
||||
r.review(false, nil)
|
||||
if got := r.p.owedAll(); len(got) != 1 {
|
||||
t.Errorf("AC-832k: owed %+v after another pass", got)
|
||||
}
|
||||
// AC-832i: said by hand at once; the finding is cleared with it (AC-832h)
|
||||
r.refuse = 0
|
||||
said, err := r.p.owedSay(owed[0].ID)
|
||||
if err != nil || said.ID != owed[0].ID || len(r.p.owedAll()) != 0 || r.found[key] || len(r.events) != 1 || r.events[0] != meshwants.EventWaitHeld {
|
||||
t.Fatalf("AC-832i: said %+v (%v), owed %d, events %v, findings %v", said, err, len(r.p.owedAll()), r.events, r.found)
|
||||
}
|
||||
// AC-832h: a restart no longer owes it, so the first pass clears what the bucket holds
|
||||
r.found[key] = true
|
||||
r.p.owedFindings()
|
||||
if r.found[key] {
|
||||
t.Error("AC-832h: a finding of an event no longer owed stands")
|
||||
}
|
||||
// AC-832j: the drop of the wait-held owed before a wait-ended drops both, and the wait is decided go-on, its ask and finding gone
|
||||
askKey, _ := asks.OutsideAskKey("ace", "nats", fpTest)
|
||||
r.now = r.now.Add(31 * time.Minute)
|
||||
r.p.outside.Heard("mesh.seat.mesh-conditions.event.condition-changed", []byte(`{"key":"machine.hub.silent","subject":{"id":"hub","scope":"machine","machine":"hub","also":["ace"]}}`))
|
||||
<-r.woke
|
||||
r.review(false, nil)
|
||||
_, ask, err := assign.DecodeAsk(askKey, r.p.w.value(buckets.Asks(), askKey))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r.refuse = 100
|
||||
w := r.wait()
|
||||
w.HeldSaid++ // a new wait-held the bus refuses, then the end
|
||||
r.p.keepWait(context.Background(), outside.Key("ace", "nats", strings.TrimPrefix(fpTest, "src2:")), w)
|
||||
r.p.wantsOwe(waitOrder(outside.Key("ace", "nats", strings.TrimPrefix(fpTest, "src2:")), w.ClockFrom), meshwants.EventWaitHeld, r.p.outsideBody(w),
|
||||
waitEventID("ace", "nats", strings.TrimPrefix(fpTest, "src2:"), "held."+strconv.Itoa(w.HeldSaid), w.ClockFrom), nil)
|
||||
v, _ := mdc.EncodeAnswer(mdc.Answer{Option: assign.OptionGoOn, Warrant: ask.ID + "@2026-11-11T10:32:00Z", Words: "the operator"})
|
||||
r.p.w.put(buckets.Answers, askKey, v)
|
||||
r.review(false, nil)
|
||||
owed = r.p.owedAll()
|
||||
if len(owed) != 2 || r.wait().Ending != outside.HowGoOn {
|
||||
t.Fatalf("AC-832j: owed %+v, wait %+v", owed, r.wait())
|
||||
}
|
||||
dropped, err := r.p.owedDrop(owed[0].ID)
|
||||
if err != nil || len(dropped) != 2 || r.wait().Decided != outside.HowGoOn || r.p.w.value(buckets.Asks(), askKey) != nil || len(r.p.owedAll()) != 0 {
|
||||
t.Errorf("AC-832j: the drop answered %+v (%v); wait %+v, ask %v", dropped, err, r.wait(), r.p.w.value(buckets.Asks(), askKey) != nil)
|
||||
}
|
||||
if _, err := r.p.owedDrop("no such id"); err == nil {
|
||||
t.Error("AC-832j: an id not owed was dropped")
|
||||
}
|
||||
// AC-832s: each tool answers through its verb; with the program stopped each says the verb is unanswered
|
||||
var verbs []string
|
||||
tools := owedTools(func(verb string, in any) (json.RawMessage, error) {
|
||||
verbs = append(verbs, verb)
|
||||
return json.RawMessage(`{"events":[]}`), nil
|
||||
})
|
||||
for _, tool := range tools {
|
||||
if _, err := tool.Run(map[string]any{"id": "x", "why": "y"}); err != nil {
|
||||
t.Errorf("AC-832s: %s: %v", tool.Name, err)
|
||||
}
|
||||
}
|
||||
if len(verbs) != 3 || !strings.HasSuffix(verbs[0], "."+meshwants.VerbOwed) || !strings.HasSuffix(verbs[1], "."+meshwants.VerbOwedSay) || !strings.HasSuffix(verbs[2], "."+meshwants.VerbOwedDrop) {
|
||||
t.Errorf("AC-832s: the tools called %v", verbs)
|
||||
}
|
||||
for _, tool := range owedTools(func(string, any) (json.RawMessage, error) { return nil, errors.New("no answer") }) {
|
||||
if _, err := tool.Run(map[string]any{"id": "x", "why": "y"}); err == nil || !strings.Contains(err.Error(), "does not answer the verb") {
|
||||
t.Errorf("AC-832s: %s with the program stopped answered %v", tool.Name, err)
|
||||
}
|
||||
}
|
||||
})
|
||||
t.Run("a newer want ends the wait replaced, and a restart judges it again", func(t *testing.T) {
|
||||
r := newOutsideRig(t)
|
||||
r.cond("machine.hub.unreachable", "ace")
|
||||
|
||||
@@ -34,6 +34,7 @@ type owedKept struct {
|
||||
mu sync.Mutex
|
||||
list []*owedEvent
|
||||
first, last time.Duration // the setting's pace; zero: the defaults
|
||||
unsaid time.Duration // the setting event-unsaid-after; zero: its default
|
||||
}
|
||||
|
||||
func (o *owedKept) pace() (first, max time.Duration) {
|
||||
|
||||
@@ -0,0 +1,301 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
mcc "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient"
|
||||
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient"
|
||||
mcseat "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions"
|
||||
meshwants "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
|
||||
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||
"git.novox.be/novox/mesh-sdk/go/process"
|
||||
"git.novox.be/novox/mesh-sdk/go/views"
|
||||
|
||||
"mesh-delivery-assigner/internal/assign"
|
||||
)
|
||||
|
||||
// The owed events' reading and steering (design 47 H2b §832 6., H-A-847, H-A-869): the seat mesh-wants' verbs `owed`, `owed-say` and
|
||||
// `owed-drop` are answered by the assigner's program, which keeps the owed events in its memory, and the tools assigner_owed,
|
||||
// assigner_owed_say and assigner_owed_drop call them. Past `event-unsaid-after` an owed event is the finding `event-unsaid`.
|
||||
|
||||
const (
|
||||
owedTool = "assigner_owed"
|
||||
owedSayTool = "assigner_owed_say"
|
||||
owedDropTool = "assigner_owed_drop"
|
||||
// kindEventUnsaid is the finding of an event owed for event-unsaid-after, scope delivery, id the message id made a key.
|
||||
kindEventUnsaid = "event-unsaid"
|
||||
// defaultEventUnsaidAfter is the setting event-unsaid-after's default.
|
||||
defaultEventUnsaidAfter = 5 * time.Minute
|
||||
)
|
||||
|
||||
func (o *owedKept) unsaidFor() time.Duration {
|
||||
if o.unsaid > 0 {
|
||||
return o.unsaid
|
||||
}
|
||||
return defaultEventUnsaidAfter
|
||||
}
|
||||
|
||||
// owedSeen is e as the seat's verbs answer it.
|
||||
func owedSeen(e *owedEvent) meshwants.OwedEvent {
|
||||
return meshwants.OwedEvent{ID: e.id, FirstOwed: e.firstOwed, Next: e.next, Tries: int64(e.tries)}
|
||||
}
|
||||
|
||||
// owedAll is every owed event, in the order they were made.
|
||||
func (p *passer) owedAll() []meshwants.OwedEvent {
|
||||
o := &p.owed
|
||||
o.mu.Lock()
|
||||
defer o.mu.Unlock()
|
||||
out := make([]meshwants.OwedEvent, 0, len(o.list))
|
||||
for _, e := range o.list {
|
||||
out = append(out, owedSeen(e))
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// owedSay says the first owed event of id's order now, its delay set back to say-again-pace-first; it answers the event said, or the
|
||||
// refusal of the bus (the event stays owed, said again from say-again-pace-first on).
|
||||
func (p *passer) owedSay(id string) (meshwants.OwedEvent, error) {
|
||||
if p.publishWants == nil {
|
||||
return meshwants.OwedEvent{}, errors.New("the assigner has no bus to say it on")
|
||||
}
|
||||
o := &p.owed
|
||||
o.mu.Lock()
|
||||
at := slicesIndex(o.list, id)
|
||||
if at < 0 {
|
||||
o.mu.Unlock()
|
||||
return meshwants.OwedEvent{}, fmt.Errorf("no event is owed under %q: assigner_owed lists them", id)
|
||||
}
|
||||
var e *owedEvent
|
||||
for _, c := range o.list {
|
||||
if c.order == o.list[at].order {
|
||||
e = c
|
||||
break
|
||||
}
|
||||
}
|
||||
first, _ := o.pace()
|
||||
now := p.clock().UTC()
|
||||
if err := p.publishWants(e.event, e.body, e.id); err != nil {
|
||||
e.tries, e.next = 0, now.Add(first)
|
||||
o.mu.Unlock()
|
||||
return owedSeen(e), fmt.Errorf("the bus did not take %s %s: %w; it stays owed, said again from %s", e.event, e.id, err, e.next.Format(time.RFC3339))
|
||||
}
|
||||
seen := owedSeen(e)
|
||||
o.list = slicesDelete(o.list, e)
|
||||
o.mu.Unlock()
|
||||
p.logf("%s %s is said by hand", e.event, e.id)
|
||||
if e.taken != nil {
|
||||
e.taken()
|
||||
}
|
||||
p.owedFindings()
|
||||
if p.wake != nil {
|
||||
p.wake()
|
||||
}
|
||||
return seen, nil
|
||||
}
|
||||
|
||||
// owedDrop drops the owed event id and every event owed behind it in its order, doing for each what the bus taking it would have
|
||||
// done (its taken), then clears their findings; it answers the events dropped, the named one first.
|
||||
func (p *passer) owedDrop(id string) ([]meshwants.OwedEvent, error) {
|
||||
o := &p.owed
|
||||
o.mu.Lock()
|
||||
at := slicesIndex(o.list, id)
|
||||
if at < 0 {
|
||||
o.mu.Unlock()
|
||||
return nil, fmt.Errorf("no event is owed under %q: assigner_owed lists them", id)
|
||||
}
|
||||
order := o.list[at].order
|
||||
var dropped []*owedEvent
|
||||
var kept []*owedEvent
|
||||
for i, e := range o.list {
|
||||
if e.order == order && i >= at {
|
||||
dropped = append(dropped, e)
|
||||
continue
|
||||
}
|
||||
kept = append(kept, e)
|
||||
}
|
||||
o.list = kept
|
||||
o.mu.Unlock()
|
||||
seen := make([]meshwants.OwedEvent, 0, len(dropped))
|
||||
for _, e := range dropped {
|
||||
seen = append(seen, owedSeen(e))
|
||||
p.logf("%s %s is dropped by hand, with what waited on it done", e.event, e.id)
|
||||
if e.taken != nil {
|
||||
e.taken()
|
||||
}
|
||||
}
|
||||
p.owedFindings()
|
||||
if p.wake != nil {
|
||||
p.wake()
|
||||
}
|
||||
return seen, nil
|
||||
}
|
||||
|
||||
func slicesIndex(list []*owedEvent, id string) int {
|
||||
for i, e := range list {
|
||||
if e.id == id {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
func slicesDelete(list []*owedEvent, e *owedEvent) []*owedEvent {
|
||||
out := list[:0:0]
|
||||
for _, c := range list {
|
||||
if c != e {
|
||||
out = append(out, c)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
var (
|
||||
unsaidFp = regexp.MustCompile(`src2:([0-9a-f]{64})`)
|
||||
unsaidTime = regexp.MustCompile(`\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:\.\d+)?Z`)
|
||||
)
|
||||
|
||||
// unsaidID is a message id as the finding's id: each fingerprint as its 64 hex digits without `src2:` and each time as Unix
|
||||
// nanoseconds (design 47 H2b §832 6.); assign.KeyID makes it a key.
|
||||
func unsaidID(id string) string {
|
||||
id = unsaidFp.ReplaceAllString(id, "$1")
|
||||
return unsaidTime.ReplaceAllStringFunc(id, func(s string) string {
|
||||
t, err := time.Parse(time.RFC3339Nano, s)
|
||||
if err != nil {
|
||||
return s
|
||||
}
|
||||
return strconv.FormatInt(t.UnixNano(), 10)
|
||||
})
|
||||
}
|
||||
|
||||
func unsaidKey(id string) string {
|
||||
return views.FindingKey(mcc.ScopeDelivery, assign.KeyID(unsaidID(id)), kindEventUnsaid)
|
||||
}
|
||||
|
||||
// owedFindings writes the finding `event-unsaid` of each event owed for event-unsaid-after, and clears, from the bucket's keys read
|
||||
// now, every one of an event no longer owed: said, dropped, or not owed again after a restart (H-A-722).
|
||||
func (p *passer) owedFindings() {
|
||||
have, ok := p.findingKeys("the finding event-unsaid")
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
o := &p.owed
|
||||
o.mu.Lock()
|
||||
now, after := p.clock().UTC(), o.unsaidFor()
|
||||
owed := map[string]bool{}
|
||||
var raise []*owedEvent
|
||||
for _, e := range o.list {
|
||||
if now.Sub(e.firstOwed) < after {
|
||||
continue
|
||||
}
|
||||
owed[unsaidKey(e.id)] = true
|
||||
raise = append(raise, e)
|
||||
}
|
||||
o.mu.Unlock()
|
||||
for _, e := range raise {
|
||||
key := unsaidKey(e.id)
|
||||
if have[key] {
|
||||
continue
|
||||
}
|
||||
summary := fmt.Sprintf("%s %s has been owed since %s and the bus does not take it", e.event, e.id, e.firstOwed.Format(time.RFC3339))
|
||||
f := assign.Observed{Scope: mcc.ScopeDelivery, ID: unsaidID(e.id), Kind: kindEventUnsaid, Severity: mcseat.FindingSeverityWarning,
|
||||
Summary: summary, Headline: "An event of the delivery is not said",
|
||||
Explanation: summary + ". The assigner says it again on its own pace; assigner_owed lists what is owed, assigner_owed_say says one now and assigner_owed_drop drops one the bus will never take.",
|
||||
Needs: "Nothing, unless the bus keeps refusing it.", Source: "assigner." + kindEventUnsaid}
|
||||
if err := p.findings.Put(f.Finding(now)); err != nil {
|
||||
p.logf("the finding %s is not written: %v", key, err)
|
||||
}
|
||||
}
|
||||
var gone []string
|
||||
for key := range have {
|
||||
if strings.HasPrefix(key, mcc.ScopeDelivery+".") && strings.HasSuffix(key, "."+kindEventUnsaid) && !owed[key] {
|
||||
gone = append(gone, key)
|
||||
}
|
||||
}
|
||||
sort.Strings(gone)
|
||||
for _, key := range gone {
|
||||
if err := p.findings.Delete(key); err != nil {
|
||||
p.logf("the finding %s is not cleared: %v", key, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// owedVerbs are the process's handlers of the seat mesh-wants' verbs owed, owed-say and owed-drop; record writes the hand act of a
|
||||
// drop in the log first.
|
||||
func owedVerbs(p *passer, record func(meshhandactsclient.Request) error) map[string]process.SeatHandler {
|
||||
return map[string]process.SeatHandler{
|
||||
meshwants.VerbOwed: func(string, json.RawMessage) (any, error) {
|
||||
return meshwants.OwedAnswer{Events: p.owedAll()}, nil
|
||||
},
|
||||
meshwants.VerbOwedSay: func(_ string, raw json.RawMessage) (any, error) {
|
||||
var in meshwants.OwedSayInput
|
||||
if err := json.Unmarshal(raw, &in); err != nil {
|
||||
return nil, fmt.Errorf("the arguments are not JSON: %w", err)
|
||||
}
|
||||
e, err := p.owedSay(in.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return meshwants.OwedSayAnswer{Event: e}, nil
|
||||
},
|
||||
meshwants.VerbOwedDrop: func(caller string, raw json.RawMessage) (any, error) {
|
||||
var in meshwants.OwedDropInput
|
||||
if err := json.Unmarshal(raw, &in); err != nil {
|
||||
return nil, fmt.Errorf("the arguments are not JSON: %w", err)
|
||||
}
|
||||
if in.ID == "" || strings.TrimSpace(in.Why) == "" {
|
||||
return nil, errors.New("name the owed event's id and why it is dropped")
|
||||
}
|
||||
if err := record(meshhandactsclient.Request{What: owedDropTool + " " + in.ID, Why: in.Why + " (" + caller + ")", Cause: "owed-event-drop"}); err != nil {
|
||||
return nil, fmt.Errorf("the hand act is not recorded, so nothing is dropped: %w", err)
|
||||
}
|
||||
dropped, err := p.owedDrop(in.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return meshwants.OwedDropAnswer{Dropped: dropped}, nil
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// owedTools are the module's tools of the owed events, each calling its verb of the seat mesh-wants; with the program stopped each
|
||||
// says the verb is unanswered.
|
||||
func owedTools(ask func(string, any) (json.RawMessage, error)) []stdio.Tool {
|
||||
call := func(verb string, in any) (any, error) {
|
||||
raw, err := ask("seat:"+meshwants.Seat+"."+verb, in)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("the assigner's program does not answer the verb %s of the seat %s (it is stopped or starting): %w", verb, meshwants.Seat, err)
|
||||
}
|
||||
var out any
|
||||
if err := json.Unmarshal(raw, &out); err != nil {
|
||||
return nil, fmt.Errorf("%s answered what is not JSON: %w", verb, err)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
return []stdio.Tool{
|
||||
{Name: owedTool, Description: "The events the assigner says on the seat mesh-wants that the bus refused or did not acknowledge, owed in order and said " +
|
||||
"again under the same id (design 47 H2b §832): each with its id, when it was first owed, how many times it was said again and when it is said next; past " +
|
||||
"event-unsaid-after each is the finding event-unsaid. Read-only.",
|
||||
Input: schema(map[string]string{}, nil),
|
||||
Run: func(map[string]any) (any, error) { return call(meshwants.VerbOwed, meshwants.OwedInput{}) }},
|
||||
{Name: owedSayTool, Description: "Say the first owed event of an id's order now (design 47 H2b §832 6.), its delay set back to say-again-pace-first; answers the event said, " +
|
||||
"or the bus's refusal, the event staying owed.",
|
||||
Input: schema(map[string]string{"id": "an owed event's message id, as assigner_owed lists it"}, []string{"id"}),
|
||||
Run: func(a map[string]any) (any, error) {
|
||||
return call(meshwants.VerbOwedSay, meshwants.OwedSayInput{ID: arg(a, "id")})
|
||||
}},
|
||||
{Name: owedDropTool, Description: "Drop an owed event the bus will never take, with every event owed behind it in its order (design 47 H2b §832 6.), doing for each what " +
|
||||
"the bus taking it would have done: a tier-late writes tier-late-said, a running deletes the progress key, a wait-ended does the rest of the wait's end, a removal " +
|
||||
"deletes its mark; then its finding is cleared. Written in the hand-act log first.",
|
||||
Input: schema(map[string]string{"id": "an owed event's message id", "why": "why it is dropped"}, []string{"id", "why"}),
|
||||
Run: func(a map[string]any) (any, error) {
|
||||
return call(meshwants.VerbOwedDrop, meshwants.OwedDropInput{ID: arg(a, "id"), Why: arg(a, "why")})
|
||||
}},
|
||||
}
|
||||
}
|
||||
@@ -173,6 +173,7 @@ func (p *passer) pass(ctx context.Context) {
|
||||
p.outside.beginPass(p.clock)
|
||||
}
|
||||
p.sayOwed()
|
||||
p.owedFindings() // an event owed for event-unsaid-after is raised, one no longer owed is cleared (§832 6.)
|
||||
watch.in(phaseAssignmentsSeat)
|
||||
p.assignmentsSeat(ctx)
|
||||
watch.in(phaseKeptGraph)
|
||||
|
||||
@@ -266,6 +266,35 @@ func TestAPipelinesWantsAreWrittenTierByTier(t *testing.T) {
|
||||
t.Fatalf("the end kept after the pass = %+v (%v)", end, ok)
|
||||
}
|
||||
})
|
||||
// Design 47 H2b §832 6. (1984/AC-832j): dropping an owed tier-late writes tier-late-said, and an owed running deletes the progress key.
|
||||
t.Run("assigner_owed_drop of an owed tier-late writes tier-late-said, and of an owed running deletes the progress key", func(t *testing.T) {
|
||||
db, web := meshcatalogclient.SourcePrefix2+strings.Repeat("d", 64), meshcatalogclient.SourcePrefix2+strings.Repeat("c", 64)
|
||||
pipeline := trunkBranch + ".5"
|
||||
r := newTierRig(t, db, web, pipeline)
|
||||
r.refuse = true
|
||||
r.pass(30 * time.Minute)
|
||||
owed := r.p.owedAll()
|
||||
if len(owed) != 1 || !strings.HasPrefix(owed[0].ID, "pipeline-wanted."+pipeline+".tier-late") {
|
||||
t.Fatalf("AC-832j: owed %+v", owed)
|
||||
}
|
||||
dropped, err := r.p.owedDrop(owed[0].ID)
|
||||
prog, _, _ := r.p.ends.tiersOf(pipeline)
|
||||
if err != nil || len(dropped) != 1 || prog.TierLateSaid.IsZero() || len(r.p.owedAll()) != 0 {
|
||||
t.Fatalf("AC-832j: the drop of tier-late answered %+v (%v), progress %+v", dropped, err, prog)
|
||||
}
|
||||
for i, m := range []struct{ module, fp string }{{"db", db}, {"web", web}} {
|
||||
raw, _ := json.Marshal(nodeengine.Running{Node: "g14", Module: m.module, Fingerprint: m.fp})
|
||||
_ = r.p.w.hearRunning("running.g14."+m.module, raw)
|
||||
r.pass(time.Duration(31+i) * time.Minute)
|
||||
}
|
||||
owed = r.p.owedAll()
|
||||
if len(owed) != 1 || !strings.HasSuffix(owed[0].ID, ".running") {
|
||||
t.Fatalf("AC-832j: owed %+v, want running", owed)
|
||||
}
|
||||
if _, err := r.p.owedDrop(owed[0].ID); err != nil || r.ends.vals[tierKey(pipeline)] != nil {
|
||||
t.Errorf("AC-832j: the drop of running left the progress key %v (%v)", r.ends.vals[tierKey(pipeline)] != nil, err)
|
||||
}
|
||||
})
|
||||
t.Run("a tier-late the bus refuses is said again after a restart, before running, and the key stands until running is taken", func(t *testing.T) {
|
||||
db, web := meshcatalogclient.SourcePrefix2+strings.Repeat("d", 64), meshcatalogclient.SourcePrefix2+strings.Repeat("c", 64)
|
||||
pipeline := trunkBranch + ".5"
|
||||
|
||||
@@ -395,6 +395,7 @@ func serveTools() error {
|
||||
keeper := &inputKeeper{vals: stateobjects.ForState(buckets.InputsState), now: time.Now, logf: func(string, ...any) {}}
|
||||
tools = append(tools, inputsRead(keeper), inputsDrop(keeper, stdio.Ask))
|
||||
tools = append(tools, validateTools(stdio.Ask)...) // judge a pipeline's candidate on request, through the seat mesh-wants' verb validate (H-A-727)
|
||||
tools = append(tools, owedTools(stdio.Ask)...) // the owed events, through the seat mesh-wants' verbs (§832 6.)
|
||||
tools = append(tools, compositionsTools(stdio.Ask)...) // the composition runs' read and drop, through their verbs (§728)
|
||||
tools = append(tools, viewTools(os.Getenv, keptSource, time.Now)...)
|
||||
// What each node's engine reads, as the assigner uses it: its own state engine-reads (design 47 H-A-104).
|
||||
|
||||
@@ -104,7 +104,7 @@ func TestManifest(t *testing.T) {
|
||||
// revision, entry and difference from its revisions kept as objects in the old section, form 1, capped at 512 MiB.
|
||||
if len(m.Claims) != 2 || m.Claims[0].Name != meshmoduleassigner.Seat || m.Claims[0].At() != catalogue.ScopeMesh ||
|
||||
!slices.Equal(m.Claims[0].Serves, []string{"assignments", "proposals", "propose", "withdraw", "again", "placement"}) ||
|
||||
m.Claims[1].Name != meshwants.Seat || m.Claims[1].At() != catalogue.ScopeMesh || !slices.Equal(m.Claims[1].Serves, []string{"upgrade", "bus", "revision", "entry", "difference", "input", "compositions", "compositions-drop", "validate", "keep-now", "drop"}) {
|
||||
m.Claims[1].Name != meshwants.Seat || m.Claims[1].At() != catalogue.ScopeMesh || !slices.Equal(m.Claims[1].Serves, []string{"upgrade", "bus", "revision", "entry", "difference", "input", "compositions", "compositions-drop", "validate", "keep-now", "drop", "owed", "owed-say", "owed-drop"}) {
|
||||
t.Errorf("the assigner claims %+v, want mesh-module-assigner with its five verbs and mesh-wants with its five", m.Claims)
|
||||
}
|
||||
if len(m.Objects) != 1 || m.Objects[0].Name != "assignment-revisions" || m.Objects[0].MaxMiB != 512 || m.Objects[0].Form != 1 {
|
||||
@@ -116,7 +116,7 @@ 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_progress_drop", "assigner_wait_drop", "assigner_why", "assigner_want_drop", "assigner_assignment_drop", "assigner_asks", "assigner_ask_drop", "assigner_keep_now", "assigner_validate_before", "assigner_validate"}) {
|
||||
"assigner_first_views", "assigner_first_view_again", "assigner_engine_reads", "assigner_seat_list", "assigner_seat_list_again", "assigner_ask_again", "assigner_written", "assigner_progress_drop", "assigner_wait_drop", "assigner_owed", "assigner_owed_say", "assigner_owed_drop", "assigner_why", "assigner_want_drop", "assigner_assignment_drop", "assigner_asks", "assigner_ask_drop", "assigner_keep_now", "assigner_validate_before", "assigner_validate"}) {
|
||||
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 {
|
||||
@@ -186,7 +186,7 @@ func TestManifest(t *testing.T) {
|
||||
}
|
||||
file, _ := os.ReadFile("module.json")
|
||||
if err := json.Unmarshal(file, &raw); err != nil || raw.Config["outside-wait-minutes"].Default != float64(30) || raw.Config["outside-settle-seconds"].Default != float64(90) ||
|
||||
raw.Config["ask-operator-for"].Default != "take-off,remove-node,stops" || len(raw.Config) != 20 || raw.Config["tier-bound"].Default != float64(30) || raw.Config["entry-asks"].Default != float64(5) || raw.Config["reads-bound"].Default != float64(8) ||
|
||||
raw.Config["ask-operator-for"].Default != "take-off,remove-node,stops" || len(raw.Config) != 21 || raw.Config["tier-bound"].Default != float64(30) || raw.Config["entry-asks"].Default != float64(5) || raw.Config["reads-bound"].Default != float64(8) ||
|
||||
raw.Config["composition-runs-cap-mib"].Default != float64(16) || raw.Config["composition-runs-kept"].Default != "24h" ||
|
||||
raw.Config["composition-step-bound"].Default != "30m" || raw.Config["run-untaken-bound"].Default != "24h" || raw.Config["blame-tries"].Default != float64(20) ||
|
||||
// design 47 H2 H-A-628 (3): the bound of a run's wait for a package's publish, the builder's default
|
||||
@@ -196,7 +196,9 @@ func TestManifest(t *testing.T) {
|
||||
// design 47 H2 §775, H-A-381 (2): the taken key's bound and the kept-call pace, runtime settings
|
||||
raw.Config["ask-taken-bound"].Default != "10m" || raw.Config["kept-call-pace-first"].Default != "1s" || raw.Config["kept-call-pace-max"].Default != "30s" || raw.Config["compose-ask-bound"].Default != "10s" || raw.Config["keeping-retry"].Default != "30s" ||
|
||||
// design 47 H §832 2.: the pace an owed event is said again at
|
||||
raw.Config["say-again-pace-first"].Default != "2s" || raw.Config["say-again-pace-max"].Default != "1m" {
|
||||
raw.Config["say-again-pace-first"].Default != "2s" || raw.Config["say-again-pace-max"].Default != "1m" ||
|
||||
// design 47 H2b §832 6.: how long an event may stay owed before it is the finding event-unsaid
|
||||
raw.Config["event-unsaid-after"].Default != "5m" {
|
||||
t.Errorf("config = %+v (%v), want outside-wait-minutes of 30, outside-settle-seconds of 90 and ask-operator-for of take-off,remove-node,stops (A-425a)", raw.Config, err)
|
||||
}
|
||||
for _, f := range []struct{ env, path, key string }{
|
||||
@@ -216,6 +218,7 @@ func TestManifest(t *testing.T) {
|
||||
{"MESH_ASSIGNER_READS_BOUND_FILE", "${dir:state}/reads-bound", "reads-bound"}, // design 47 H2 H-A-708 (3)
|
||||
{"MESH_ASSIGNER_SAY_AGAIN_PACE_FIRST_FILE", "${dir:state}/say-again-pace-first", "say-again-pace-first"}, // design 47 H §832 2.
|
||||
{"MESH_ASSIGNER_SAY_AGAIN_PACE_MAX_FILE", "${dir:state}/say-again-pace-max", "say-again-pace-max"},
|
||||
{"MESH_ASSIGNER_EVENT_UNSAID_AFTER_FILE", "${dir:state}/event-unsaid-after", "event-unsaid-after"}, // design 47 H2b §832 6.
|
||||
} {
|
||||
if !strings.Contains(string(file), `"`+f.env+`": "`+f.path+`"`) || !strings.Contains(string(file), `"path": "`+f.path+`"`) ||
|
||||
!strings.Contains(string(file), `"content": "${config:`+f.key+`}"`) {
|
||||
|
||||
@@ -31,7 +31,10 @@
|
||||
"compositions-drop",
|
||||
"validate",
|
||||
"keep-now",
|
||||
"drop"
|
||||
"drop",
|
||||
"owed",
|
||||
"owed-say",
|
||||
"owed-drop"
|
||||
]
|
||||
}
|
||||
],
|
||||
@@ -138,6 +141,9 @@
|
||||
"assigner_written",
|
||||
"assigner_progress_drop",
|
||||
"assigner_wait_drop",
|
||||
"assigner_owed",
|
||||
"assigner_owed_say",
|
||||
"assigner_owed_drop",
|
||||
"assigner_why",
|
||||
"assigner_want_drop",
|
||||
"assigner_assignment_drop",
|
||||
@@ -264,6 +270,12 @@
|
||||
"trusted": false,
|
||||
"default": "1m"
|
||||
},
|
||||
"event-unsaid-after": {
|
||||
"type": "string",
|
||||
"description": "how long an event of the seat mesh-wants may stay owed before it is the finding event-unsaid, a Go duration (design 47 H2b section 832 6.).",
|
||||
"trusted": false,
|
||||
"default": "5m"
|
||||
},
|
||||
"pass-stall-seconds": {
|
||||
"type": "number",
|
||||
"description": "seconds a pass of the assigner may run before it says in the journal which phase it is in, and again at each further bound until it ends (design 47 H2 H-A-635).",
|
||||
@@ -443,6 +455,14 @@
|
||||
"mode": "0600",
|
||||
"content": "${config:say-again-pace-max}"
|
||||
},
|
||||
{
|
||||
"id": "event-unsaid-after",
|
||||
"type": "file",
|
||||
"path": "${dir:state}/event-unsaid-after",
|
||||
"owner": "mesh-delivery-assigner",
|
||||
"mode": "0600",
|
||||
"content": "${config:event-unsaid-after}"
|
||||
},
|
||||
{
|
||||
"id": "pass-stall-seconds",
|
||||
"type": "file",
|
||||
@@ -483,7 +503,8 @@
|
||||
"MESH_ASSIGNER_PACKAGE_WAIT_FILE": "${dir:state}/package-wait-minutes",
|
||||
"MESH_ASSIGNER_PASS_STALL_FILE": "${dir:state}/pass-stall-seconds",
|
||||
"MESH_ASSIGNER_SAY_AGAIN_PACE_FIRST_FILE": "${dir:state}/say-again-pace-first",
|
||||
"MESH_ASSIGNER_SAY_AGAIN_PACE_MAX_FILE": "${dir:state}/say-again-pace-max"
|
||||
"MESH_ASSIGNER_SAY_AGAIN_PACE_MAX_FILE": "${dir:state}/say-again-pace-max",
|
||||
"MESH_ASSIGNER_EVENT_UNSAID_AFTER_FILE": "${dir:state}/event-unsaid-after"
|
||||
},
|
||||
"user": "mesh-delivery-assigner",
|
||||
"health": {
|
||||
|
||||
Reference in New Issue
Block a user