Compare commits
9
Commits
main
...
feat/47-H2b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
727e7fe90f | ||
|
|
0b8be7fff5 | ||
|
|
264dfb1660 | ||
|
|
37c350fb89 | ||
|
|
4d2f1ea1f3 | ||
|
|
254fc645fd | ||
|
|
4dbb4a2d4a | ||
|
|
174dead676 | ||
|
|
25c4c52396 |
@@ -198,6 +198,9 @@ type RecordEntry struct {
|
||||
Module string `json:"module"`
|
||||
Fingerprint string `json:"fingerprint"`
|
||||
Node string `json:"node,omitempty"`
|
||||
// WantRevision is the revision of the want's key the entry was written from; a want at a lower one for the same node
|
||||
// and module changes nothing (design 47 H §832 5.).
|
||||
WantRevision int64 `json:"want-revision,omitempty"`
|
||||
}
|
||||
|
||||
// EntryKey is the key of an entry: its module, its fingerprint and its node.
|
||||
|
||||
@@ -92,8 +92,8 @@ func decodeWait(body json.RawMessage, _ time.Time) ([]StepOutcome, error) {
|
||||
}
|
||||
|
||||
func decodeWanted(body json.RawMessage, _ time.Time) ([]StepOutcome, error) {
|
||||
var w wants.WantedEvent
|
||||
if err := strictly(body, &w); err != nil {
|
||||
w, _, err := wants.DecodeWantedEvent(body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if w.Module == "" || w.Node == "" {
|
||||
@@ -326,7 +326,20 @@ func (h *Holder) wantWritten(w wants.WantedEvent) error {
|
||||
if r == nil || r.Ended != nil {
|
||||
return nil
|
||||
}
|
||||
if err := h.Records.AddEntry(r, RecordEntry{Module: w.Module, Fingerprint: w.Fp, Node: w.Node}); err != nil {
|
||||
// A body with no want-revision is the earlier form: it is applied and leaves the held revision as it is (H-A-865).
|
||||
held := w.WantRevision
|
||||
for _, e := range r.Entries {
|
||||
if e.Module != w.Module || e.Node != w.Node {
|
||||
continue
|
||||
}
|
||||
if w.WantRevision > 0 && e.WantRevision > w.WantRevision {
|
||||
return nil
|
||||
}
|
||||
if w.WantRevision == 0 && e.WantRevision > held {
|
||||
held = e.WantRevision
|
||||
}
|
||||
}
|
||||
if err := h.Records.AddEntry(r, RecordEntry{Module: w.Module, Fingerprint: w.Fp, Node: w.Node, WantRevision: held}); err != nil {
|
||||
return err
|
||||
}
|
||||
at := h.Now().UTC()
|
||||
|
||||
@@ -103,15 +103,56 @@ func TestARecordFollowsItsPipelineToTheMachines(t *testing.T) {
|
||||
if _, ok := r.Entries[EntryKey("app", "f", "novox")]; ok {
|
||||
t.Fatal("a removed want is an entry")
|
||||
}
|
||||
// Design 47 H2b §832 5. (1984/AC-832g, H-A-832, H-A-842): a want at a want-revision below the one held for that node and
|
||||
// module changes nothing, a repeat of an applied body writes nothing new, and a field the contract does not know is
|
||||
// left unread.
|
||||
for _, w := range []string{
|
||||
`{"v":1,"node":"ace","module":"app","fp":"f","pipeline":"main.1","source":1,"revision":12,"want-revision":9,"future":1}`,
|
||||
`{"v":1,"node":"ace","module":"app","fp":"f2","pipeline":"main.1","source":1,"revision":12,"want-revision":8}`,
|
||||
} {
|
||||
hear(t, c, "mesh-wants.wanted.x.app", "", w)
|
||||
}
|
||||
if e, ok := r.Entries[EntryKey("app", "f", "ace")]; !ok || e.WantRevision != 9 {
|
||||
t.Fatalf("the want at want-revision 9 is %+v: applied with its unknown field unread", e)
|
||||
}
|
||||
if _, ok := r.Entries[EntryKey("app", "f2", "ace")]; ok {
|
||||
t.Fatal("a want at want-revision 8, below the 9 held, is an entry")
|
||||
}
|
||||
// A wanted of the earlier form (no want-revision) leaves the held 9 as it is, so a wanted at 8 changes nothing still
|
||||
// (H-A-865); and a body said again under a new id adds no ledger operation (1984/AC-832g).
|
||||
ledger := h.Records.Ledger.(*ledgerFake)
|
||||
hear(t, c, "mesh-wants.wanted.x.app", "", `{"v":1,"node":"ace","module":"app","fp":"f","pipeline":"main.1","source":1,"revision":12}`)
|
||||
hear(t, c, "mesh-wants.wanted.x.app", "", `{"v":1,"node":"ace","module":"app","fp":"f3","pipeline":"main.1","source":1,"revision":12,"want-revision":8}`)
|
||||
if e := r.Entries[EntryKey("app", "f", "ace")]; e.WantRevision != 9 {
|
||||
t.Fatalf("the entry is %+v: a wanted with no want-revision keeps the 9 held", e)
|
||||
}
|
||||
if _, ok := r.Entries[EntryKey("app", "f3", "ace")]; ok {
|
||||
t.Fatal("a want at want-revision 8 is an entry after a wanted of the earlier form")
|
||||
}
|
||||
before := len(ledger.history)
|
||||
again := `{"v":1,"node":"ace","module":"app","fp":"f","pipeline":"main.1","source":1,"revision":12,"want-revision":9}`
|
||||
for _, id := range []string{"id-1", "id-2"} {
|
||||
if err := c.Hear(stdio.Envelope{Key: "mesh-wants.wanted.x.app", Body: json.RawMessage(again), Headers: map[string]string{"Nats-Msg-Id": id}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if len(ledger.history) != before {
|
||||
t.Fatalf("a repeated wanted wrote %v", ledger.history[before:])
|
||||
}
|
||||
hear(t, c, "node-engine.running.ace.app", "ace", `{"v":1,"at":"2026-11-20T03:05:00Z","module":"app","node":"ace","fingerprint":"f","healthy":true}`)
|
||||
hear(t, c, "node-engine.running.g14.app", "g14", `{"v":1,"at":"2026-11-20T03:05:00Z","module":"app","node":"g14","fingerprint":"f","healthy":true}`)
|
||||
if o := r.Outcomes[OutcomeKey("app", "f", "g14", StepRunning)]; o.Outcome != OutcomeRunning || r.Ended != nil || len(*ended) != 0 {
|
||||
t.Fatalf("running is %+v and the record ended %+v: running ends nothing", o, r.Ended)
|
||||
}
|
||||
hear(t, c, "mesh-wants.pipeline-wanted.main.1", "", `{"v":1,"pipeline":"main.1","branch":"main","source":1,"outcome":"running"}`)
|
||||
hear(t, c, "mesh-wants.pipeline-wanted.main.1", "", `{"v":1,"pipeline":"main.1.again.2","branch":"main","source":1,"outcome":"running"}`) // an again pipeline's, on its source's subject (AC-824m)
|
||||
if r.Ended == nil || r.Ended.Why != WhyAllRun || len(*ended) != 1 {
|
||||
t.Fatalf("the record ended %+v, said %v", r.Ended, *ended)
|
||||
}
|
||||
// A tier-late said after the running changes nothing (1984/AC-832g).
|
||||
hear(t, c, "mesh-wants.pipeline-wanted.main.1", "", `{"v":1,"pipeline":"main.1","branch":"main","source":1,"outcome":"tier-late","not-running":[{"module":"app","machines":["ace"]}]}`)
|
||||
if r.Ended == nil || r.Ended.Why != WhyAllRun || len(*ended) != 1 {
|
||||
t.Fatalf("the record ended %+v, said %v: a tier-late after the running changes nothing", r.Ended, *ended)
|
||||
}
|
||||
if got, _ := h.Records.ByKey("main", 1); got != r {
|
||||
t.Fatal("the record read by its key is not the one the gate keeps")
|
||||
}
|
||||
@@ -405,20 +446,28 @@ func TestARecordsEndCountIsSaidAtEachEndAndAHigherPipelineEndReopensIt(t *testin
|
||||
// GATE-5/AC (design 47 H §738, §751; H-A-75, H-A-89 (3), (4)): a pipeline-ended not passed ends the record failed naming
|
||||
// the pipeline's why, and pipeline-wanted tier-late ends it failed naming the movers and machines not running.
|
||||
func TestARecordEndsFailedOnAPipelineNotPassedOrATierLate(t *testing.T) {
|
||||
for _, tc := range []struct{ name, key, body, why string }{
|
||||
for _, tc := range []struct{ name, key, body, why, then string }{
|
||||
{"pipeline failed", "mesh-pipeline-runner.pipeline-ended.main.1",
|
||||
`{"v":1,"branch":"main","source":1,"pipeline":"main.1","outcome":"failed","why":"build failed","movers":[{"module":"app","fingerprint":"f","tier":1,"steps":[{"step":"build","status":"required","outcome":"failed"}]}]}`,
|
||||
"failed: build failed"},
|
||||
"failed: build failed", ""},
|
||||
{"pipeline cancelled, no why", "mesh-pipeline-runner.pipeline-ended.main.1",
|
||||
`{"v":1,"branch":"main","source":1,"pipeline":"main.1","outcome":"cancelled","movers":[]}`,
|
||||
"failed: the pipeline main.1 ended cancelled"},
|
||||
"failed: the pipeline main.1 ended cancelled", ""},
|
||||
{"tier late", "mesh-wants.pipeline-wanted.main.1",
|
||||
`{"v":1,"pipeline":"main.1","branch":"main","source":1,"outcome":"tier-late","not-running":[{"module":"app","machines":["g14","ace"]}]}`,
|
||||
"failed: a tier is late: not running app on ace, g14"},
|
||||
"failed: a tier is late: not running app on ace, g14", ""},
|
||||
// 1984/AC-824f: a running after a tier-late leaves the record failed.
|
||||
{"running after tier late", "mesh-wants.pipeline-wanted.main.1",
|
||||
`{"v":1,"pipeline":"main.1","branch":"main","source":1,"outcome":"tier-late","not-running":[{"module":"app","machines":["ace"]}]}`,
|
||||
"failed: a tier is late: not running app on ace",
|
||||
`{"v":1,"pipeline":"main.1","branch":"main","source":1,"outcome":"running"}`},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
_, c, r, ended := pipelineBed(t)
|
||||
hear(t, c, tc.key, "", tc.body)
|
||||
if tc.then != "" {
|
||||
hear(t, c, tc.key, "", tc.then)
|
||||
}
|
||||
if r.Ended == nil || r.Ended.Why != tc.why || len(*ended) != 1 {
|
||||
t.Fatalf("the record ended %+v, said %v; want %q", r.Ended, *ended, tc.why)
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
"name": "records",
|
||||
"storage": "ledger",
|
||||
"template": "ledger",
|
||||
"form": 1,
|
||||
"options": {
|
||||
"max-mib": 3072
|
||||
},
|
||||
@@ -258,6 +259,9 @@
|
||||
},
|
||||
"ended": {
|
||||
"type": "object"
|
||||
},
|
||||
"want-revision": {
|
||||
"type": "integer"
|
||||
}
|
||||
},
|
||||
"operations": [
|
||||
@@ -280,7 +284,8 @@
|
||||
"key",
|
||||
"module",
|
||||
"fingerprint",
|
||||
"node"
|
||||
"node",
|
||||
"want-revision"
|
||||
],
|
||||
"into": "entries",
|
||||
"key": "key",
|
||||
|
||||
@@ -181,8 +181,9 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
// are answered (A-179, A-186): registered before the hub starts, read again once its events are live.
|
||||
seats := seatlist.NewPart("recovery")
|
||||
seats.Follow(seatlist.ProcessBus(conn.Call, hub), nil, logger.Printf)
|
||||
if err := hub.StartUntilBound(ctx, js, account, nil, seats.EventsLive); err != nil {
|
||||
logger.Printf("the consumer %s is not bound yet (%v): bound once the bus makes it, the seat list read then", account.EventConsumerName(), err)
|
||||
hub.OnAllHeard(seats.EventsLive)
|
||||
if err := hub.Start(ctx, js, account); err != nil {
|
||||
logger.Printf("the event hub is not started (%v): a stream it cannot bind is said by events-unheard and bound when its durable %s is composed, the seat list read then", err, account.EventConsumerName())
|
||||
}
|
||||
defer hub.Stop()
|
||||
stopAnswers, err := conn.AnswerSeat(recovery.Seat, seatlist.Definition(seats.Reader, recovery.Seat), e.Handlers())
|
||||
|
||||
@@ -239,7 +239,11 @@ func runKeeper(ctx context.Context, getenv func(string) string, logOut io.Writer
|
||||
default:
|
||||
}
|
||||
}
|
||||
follow, err := followCatalog(ctx, conn, writer, wakeMoved, logger.Printf)
|
||||
hub, err := newHub(account, logger.Printf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
follow, err := followCatalog(ctx, js, account, hub, conn, writer, wakeMoved, logger.Printf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -251,7 +255,7 @@ func runKeeper(ctx context.Context, getenv func(string) string, logOut io.Writer
|
||||
}
|
||||
defer stopAnswers()
|
||||
logger.Printf("started on the account %s: following the catalog half of every watched branch through the seat %s", account.User, catalog.Seat)
|
||||
return Keep(ctx, k, hearer(js, account, follow.take, follow.bound, logger.Printf), requestsOf(conn), moved, logger.Printf)
|
||||
return Keep(ctx, k, hearer(js, account, hub, follow.take, logger.Printf), requestsOf(conn), moved, logger.Printf)
|
||||
}
|
||||
|
||||
// catalogFollow is the keeper's reading of the catalog half and the seat list (design 47 G §532, §614): the reader, the
|
||||
@@ -265,9 +269,9 @@ type catalogFollow struct {
|
||||
}
|
||||
|
||||
// followCatalog wires the branch follower and the seat list, and asks their first views; moved is told of each change.
|
||||
func followCatalog(ctx context.Context, conn *process.Conn, writer views.WireWriter, moved func(), logf func(string, ...any)) (*catalogFollow, error) {
|
||||
func followCatalog(ctx context.Context, js jetstream.JetStream, account process.Account, hub *process.EventHub, conn *process.Conn, writer views.WireWriter, moved func(), logf func(string, ...any)) (*catalogFollow, error) {
|
||||
f := &catalogFollow{ctx: ctx, routes: &eventRoutes{by: map[string]func(jetstream.Msg){}}}
|
||||
f.reader = &views.ProcessReader{Module: keeper.Module, Call: conn.Call, Logf: logf, Findings: func() views.WireWriter { return writer }}
|
||||
f.reader = &views.ProcessReader{Module: keeper.Module, Call: conn.Call, Logf: logf, Hub: hub, Findings: func() views.WireWriter { return writer }}
|
||||
branches, err := meshcatalogclient.FollowBranchesProcess(f.reader, conn.Call)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("the catalog half cannot be followed: %w", err)
|
||||
@@ -286,7 +290,9 @@ func followCatalog(ctx context.Context, conn *process.Conn, writer views.WireWri
|
||||
if err != nil {
|
||||
logf("the seat list cannot be followed (%v): a module's sent store waits for it", err)
|
||||
}
|
||||
f.reader.Ask(ctx, nil)
|
||||
// The reader registers its views events and its findings on the hub, raises `events-unheard` from it, and tells each view the
|
||||
// bus made the keeper's consumer, so a first view taken before is asked again; the hub is started by the hearer.
|
||||
f.reader.Start(ctx, js, account, nil)
|
||||
return f, nil
|
||||
}
|
||||
|
||||
@@ -346,13 +352,6 @@ func (f *catalogFollow) take(m jetstream.Msg) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// bound tells each view the bus made the keeper's consumer then, so a first view taken before is asked again.
|
||||
func (f *catalogFollow) bound(created time.Time) {
|
||||
for _, fl := range f.reader.Followers() {
|
||||
fl.ConsumerMade(f.ctx, created)
|
||||
}
|
||||
}
|
||||
|
||||
// eventRoutes are the seat list's handlers of its events by subject, on the keeper's one durable consumer.
|
||||
type eventRoutes struct {
|
||||
mu sync.Mutex
|
||||
@@ -375,19 +374,21 @@ func (r *eventRoutes) get(subject string) func(jetstream.Msg) {
|
||||
return r.by[subject]
|
||||
}
|
||||
|
||||
// hearer binds the keeper's durable consumer on EVENTS (<node>_nats_keeper, filtered on its consumes): a message of the
|
||||
// catalog half or the seat list goes to take, which acknowledges it; every other to handle, acknowledged once applied.
|
||||
// bound is told when the bus made the consumer.
|
||||
func hearer(js jetstream.JetStream, a process.Account, take func(jetstream.Msg) bool, bound func(time.Time), logf func(string, ...any)) func(context.Context, func(subject string, body []byte) error) error {
|
||||
// newHub is the keeper's event hub: mesh-sdk's, binding the process's own durable `<node>_nats_keeper` on EVENTS and on every
|
||||
// kept seat event's stream that carries one of its patterns (design 47 H2b §836 5., H-A-876). Its views reader is given it
|
||||
// (ProcessReader.Hub), which raises `events-unheard` from it.
|
||||
func newHub(a process.Account, logf func(string, ...any)) (*process.EventHub, error) {
|
||||
hub := process.NewEventHub(logf)
|
||||
return hub, hub.ForProcess(a.ProcessID())
|
||||
}
|
||||
|
||||
// hearer registers the keeper's one handler on each event its module consumes and starts the hub, which binds each durable it can,
|
||||
// says each it cannot, and binds it when the grants part says it composed the module's durables and at a reconnect: a message of
|
||||
// the catalog half or the seat list goes to take, which acknowledges it; every other to handle, acknowledged once applied. The
|
||||
// error is the hub's refusal to start, never a stream not heard (that is `events-unheard`).
|
||||
func hearer(js jetstream.JetStream, a process.Account, hub *process.EventHub, take func(jetstream.Msg) bool, logf func(string, ...any)) func(context.Context, func(subject string, body []byte) error) error {
|
||||
return func(ctx context.Context, handle func(string, []byte) error) error {
|
||||
cons, err := js.Consumer(ctx, process.EventsStream, a.QueueConsumerName())
|
||||
if err != nil {
|
||||
return fmt.Errorf("the keeper's consumer %s on %s: %w", a.QueueConsumerName(), process.EventsStream, err)
|
||||
}
|
||||
if info, err := cons.Info(ctx); err == nil && bound != nil {
|
||||
bound(info.Created.UTC())
|
||||
}
|
||||
cc, err := process.HearEvents(cons, func(m jetstream.Msg) {
|
||||
deliver := func(m jetstream.Msg) {
|
||||
if take != nil && take(m) {
|
||||
return
|
||||
}
|
||||
@@ -397,15 +398,30 @@ func hearer(js jetstream.JetStream, a process.Account, take func(jetstream.Msg)
|
||||
return
|
||||
}
|
||||
_ = m.Ack()
|
||||
}, logf)
|
||||
if err != nil {
|
||||
}
|
||||
for _, pattern := range consumedPatterns {
|
||||
if err := hub.Handle(pattern, deliver); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if err := hub.Start(ctx, js, a); err != nil {
|
||||
return err
|
||||
}
|
||||
go func() { <-ctx.Done(); cc.Stop() }()
|
||||
go func() { <-ctx.Done(); hub.Stop() }()
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// consumedPatterns are the subjects of the events the keeper's module consumes that its views reader does not adopt (it registers
|
||||
// catalog-revision, registration-changed and source-moved on the hub itself): the seat list's two, findings-asked and the operator
|
||||
// channel's decided for its own asks, each from the contracts' subjects. Which a kept stream carries is the hub's to find.
|
||||
var consumedPatterns = []string{
|
||||
catalog.SubjectSeatDefinitionChanged,
|
||||
catalog.SubjectSeatDefinitionRemoved,
|
||||
meshconditions.SubjectFindingsAsked,
|
||||
DecidedSubject,
|
||||
}
|
||||
|
||||
// FillEvery is how often the keeper's fill pass runs: a minute (a test's shorter bound beside).
|
||||
var FillEvery = time.Minute
|
||||
|
||||
@@ -442,33 +458,16 @@ func Keep(ctx context.Context, k *keeper.Keeper, hear func(context.Context, func
|
||||
}
|
||||
}
|
||||
asked := make(chan struct{}, 1)
|
||||
for backoff := 10 * time.Second; ; backoff = min(backoff*2, 5*time.Minute) {
|
||||
err := hear(ctx, func(subject string, body []byte) error {
|
||||
if subject == DecidedSubject {
|
||||
// The operator answered one of the bus module's asks: the waiting requests are read again now.
|
||||
wake(asked)()
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
logf("the keeper's consumer cannot be heard yet (%v): asked again in %s", err, backoff)
|
||||
// The fill pass and the plans run on while the consumer is bound again (review round 2, running F1).
|
||||
bound := time.After(backoff)
|
||||
binding:
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
case <-tick.C:
|
||||
k.FillPass()
|
||||
case <-moved:
|
||||
plan()
|
||||
case <-bound:
|
||||
break binding
|
||||
}
|
||||
// The hub's refusal to start (a pattern refused, a start twice) is the program's fault and the same at every try, so it ends the
|
||||
// keeper; a stream not heard is no error here: the hub says it (`events-unheard`) and binds it when its durable is composed.
|
||||
if err := hear(ctx, func(subject string, body []byte) error {
|
||||
if subject == DecidedSubject {
|
||||
// The operator answered one of the bus module's asks: the waiting requests are read again now.
|
||||
wake(asked)()
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
return fmt.Errorf("the event hub is not started: %w", err)
|
||||
}
|
||||
if requests != nil {
|
||||
if err := requests(ctx, wake(asked)); err != nil {
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
||||
"maps"
|
||||
"os"
|
||||
"slices"
|
||||
@@ -24,6 +25,7 @@ import (
|
||||
"git.novox.be/novox/mesh-contracts/go/seats/meshbroker"
|
||||
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient"
|
||||
"git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions"
|
||||
meshgrants "git.novox.be/novox/mesh-contracts/identity-and-access/go/seats/meshgrants"
|
||||
occ "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/clients/operatorchannelclient"
|
||||
oc "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/seats/operatorchannel"
|
||||
catalog "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
@@ -231,7 +233,10 @@ func TestTheBusModuleRunsWhole(t *testing.T) {
|
||||
}()
|
||||
return nil
|
||||
}
|
||||
go func() { _ = Keep(kctx, k, hearer(js, account, nil, nil, t.Logf), watch, moved, t.Logf); close(done) }()
|
||||
go func() {
|
||||
_ = Keep(kctx, k, hearer(js, account, testHub(t, account), nil, t.Logf), watch, moved, t.Logf)
|
||||
close(done)
|
||||
}()
|
||||
return func() { stop(); <-done }
|
||||
}
|
||||
// onBranch puts a module's entry in a branch's newest revision (none: the module leaves it), and moves the keeper.
|
||||
@@ -306,24 +311,12 @@ func TestTheBusModuleRunsWhole(t *testing.T) {
|
||||
stopDown := run(down)
|
||||
eventually(t, "a fill pass with no first view", func() bool { return !down.Status().Pass.IsZero() && down.Status().FirstView.Answered.IsZero() })
|
||||
stopDown()
|
||||
// And while its consumer is bound again on its backoff (review round 2, running F1).
|
||||
was := FillEvery
|
||||
FillEvery = 20 * time.Millisecond
|
||||
defer func() { FillEvery = was }()
|
||||
// A hub that refuses to start ends the keeper with that error, after its first fill pass; no backoff retries a refusal.
|
||||
deaf := newKeeper()
|
||||
kctx, stopDeaf := context.WithCancel(ctx)
|
||||
done := make(chan struct{})
|
||||
go func() {
|
||||
_ = Keep(kctx, deaf, func(context.Context, func(string, []byte) error) error { return errors.New("no consumer yet") }, nil, nil, t.Logf)
|
||||
close(done)
|
||||
}()
|
||||
// A first view listing no module is none yet and never marked answered (A-367): the first fill pass is waited
|
||||
// for instead, then taken as the first (design 47 H, H-A-268).
|
||||
eventually(t, "the first fill pass", func() bool { return !deaf.Status().Pass.IsZero() })
|
||||
first := deaf.Status().Pass
|
||||
eventually(t, "a fill pass while the consumer is bound again", func() bool { return deaf.Status().Pass.After(first) })
|
||||
stopDeaf()
|
||||
<-done
|
||||
err := Keep(ctx, deaf, func(context.Context, func(string, []byte) error) error { return errors.New("no consumer yet") }, nil, nil, t.Logf)
|
||||
if err == nil || !strings.Contains(err.Error(), "the event hub is not started") || deaf.Status().Pass.IsZero() {
|
||||
t.Fatalf("the keeper ended with %v, last fill pass %v", err, deaf.Status().Pass)
|
||||
}
|
||||
})
|
||||
k := newKeeper()
|
||||
stop := run(k)
|
||||
@@ -835,6 +828,72 @@ func TestTheBusModuleRunsWhole(t *testing.T) {
|
||||
})
|
||||
})
|
||||
stop()
|
||||
// Design 47 H2b §836 5. (1984/AC-836g): a source-moved said on its kept stream reaches the keeper's handler; with that
|
||||
// durable not composed yet, the keeper says it unheard and binds it on the durables-composed that follows.
|
||||
t.Run("a kept seat event reaches the keeper, its durable bound when the grants part says it composed it", func(t *testing.T) {
|
||||
const stream = "SEAT_mesh-delivery_source-moved"
|
||||
// The kept stream as the grants part composes it: sourced from EVENTS by the event's subject (mesh-grants buscompose).
|
||||
if _, err := js.CreateStream(ctx, jetstream.StreamConfig{Name: stream,
|
||||
Sources: []*jetstream.StreamSource{{Name: "EVENTS", FilterSubject: "mesh.seat.mesh-delivery.event.source-moved.>"}}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
findings, err := js.KeyValue(ctx, "nats_findings")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
const findingKey = "module.nats=2eanchor.events-unheard" // the id `nats.anchor`, escaped as the views reader writes it
|
||||
var cmu sync.Mutex
|
||||
var told [][]process.Unheard
|
||||
var got []string
|
||||
kctx, kstop := context.WithCancel(ctx)
|
||||
defer kstop()
|
||||
// A kept stream the keeper consumes none of (a version-released) gets it no durable and is no finding.
|
||||
if _, err := js.CreateStream(ctx, jetstream.StreamConfig{Name: "SEAT_mesh-catalog_version-released",
|
||||
Sources: []*jetstream.StreamSource{{Name: "EVENTS", FilterSubject: "mesh.seat.mesh-catalog.event.version-released"}}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// The keeper's views reader is given the hub and raises `events-unheard` from it, through the writer.
|
||||
hub := testHub(t, account)
|
||||
hub.OnUnheard(func(l []process.Unheard) { cmu.Lock(); told = append(told, l); cmu.Unlock() })
|
||||
reader := &views.ProcessReader{Module: keeper.Module, Logf: t.Logf, Hub: hub, Findings: func() views.WireWriter { return writer }}
|
||||
// As followCatalog does: the catalog half is followed (its events adopted) before the reader starts on the hub.
|
||||
if _, err := meshcatalogclient.FollowBranchesProcess(reader, pconn.Call); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
reader.Start(kctx, js, account, nil)
|
||||
hear := hearer(js, account, hub, nil, t.Logf)
|
||||
if err := hear(kctx, func(subject string, _ []byte) error { cmu.Lock(); got = append(got, subject); cmu.Unlock(); return nil }); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
eventually(t, "the stream's durable said not composed", func() bool {
|
||||
cmu.Lock()
|
||||
defer cmu.Unlock()
|
||||
return len(told) > 0 && slices.ContainsFunc(told[0], func(u process.Unheard) bool { return u.Stream == stream && strings.HasPrefix(u.Why, "not composed") })
|
||||
})
|
||||
eventually(t, "the finding events-unheard raised", func() bool { _, err := findings.Get(ctx, findingKey); return err == nil })
|
||||
if _, err := js.CreateOrUpdateConsumer(ctx, stream, jetstream.ConsumerConfig{Durable: account.QueueConsumerName(), AckPolicy: jetstream.AckExplicitPolicy}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := nc.Publish(meshgrants.SubjectDurablesComposed(account.Node, account.Module), nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := js.Publish(ctx, "mesh.seat.mesh-delivery.event.source-moved.main", []byte(`{}`)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// The adopted source-moved goes to the keeper's views reader through the hub, on the durable just bound.
|
||||
eventually(t, "the source-moved delivered on the bound durable", func() bool {
|
||||
cons, err := js.Consumer(ctx, stream, account.QueueConsumerName())
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
info, err := cons.Info(ctx)
|
||||
cmu.Lock()
|
||||
defer cmu.Unlock()
|
||||
return err == nil && info.Delivered.Consumer >= 1 &&
|
||||
!slices.ContainsFunc(told[len(told)-1], func(u process.Unheard) bool { return u.Stream == stream })
|
||||
})
|
||||
eventually(t, "the finding events-unheard cleared", func() bool { _, err := findings.Get(ctx, findingKey); return errors.Is(err, jetstream.ErrKeyNotFound) })
|
||||
})
|
||||
}
|
||||
|
||||
func entry(name, storage, template string, options map[string]string) catalogue.BusStateEntry {
|
||||
@@ -847,3 +906,13 @@ func entry(name, storage, template string, options map[string]string) catalogue.
|
||||
}
|
||||
return e
|
||||
}
|
||||
|
||||
// testHub is the keeper's hub as the process makes it.
|
||||
func testHub(t *testing.T, account process.Account) *process.EventHub {
|
||||
t.Helper()
|
||||
hub, err := newHub(account, t.Logf)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return hub
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ require (
|
||||
git.novox.be/novox/mesh-contracts/go/seats/meshbroker v0.0.0-00010101000000-000000000000
|
||||
git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient v0.0.0-00010101000000-000000000000
|
||||
git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions v0.0.0-00010101000000-000000000000
|
||||
git.novox.be/novox/mesh-contracts/identity-and-access/go/seats/meshgrants v0.0.0-00010101000000-000000000000
|
||||
git.novox.be/novox/mesh-contracts/operator-and-conversation/go/clients/operatorchannelclient v0.0.0-00010101000000-000000000000
|
||||
git.novox.be/novox/mesh-contracts/operator-and-conversation/go/seats/operatorchannel v0.0.0-00010101000000-000000000000
|
||||
git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient v0.0.0-00010101000000-000000000000
|
||||
|
||||
Reference in New Issue
Block a user