H1 one consumer loop: serve's first views wiring in one tested function
Review round 1: no test failed when serve went back to firstview.Start. startViews starts the follower and answers the options runtime.Run is given; its test holds that on a module's own account the follower binds nothing and the runtime is given the hearer, and on the machine's account the follower binds its own. Builds: design 47 H §752, H-A-113, H-A-132, H-A-133 Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
This commit is contained in:
@@ -91,11 +91,8 @@ func serve(ctx context.Context) error {
|
||||
// ADR 0615 §1; design 46 7-approval-mark §5).
|
||||
// In a module's own runtime the follower hears on the module's one consumer, bound by the runtime for its bundle (design 47
|
||||
// H §752, H-A-132).
|
||||
followed, hearer := followerOnOwnConsumer(firstview.DepsOf(conn, log.Printf), served, cred.Module)
|
||||
if hearer != nil {
|
||||
opts = append(opts, runtime.WithHearer(cred.Module, hearer.hear))
|
||||
}
|
||||
source, stopViews := firstview.StartWith(context.Background(), followed, log.Printf)
|
||||
source, stopViews, hearing := startViews(context.Background(), firstview.DepsOf(conn, log.Printf), served, cred.Module, log.Printf)
|
||||
opts = append(opts, hearing...)
|
||||
defer stopViews()
|
||||
approvals := approvalsState{conn: conn, module: cred.Module}
|
||||
gate := approval.New(approval.Deps{Node: conn.Node(), Runner: cred.Module, Catalog: source.ApprovalCatalog(definitionsOf(seatList)), Wait: source.WaitCatalog,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
"github.com/novox/mesh-tools/node-tools/internal/bus"
|
||||
@@ -53,3 +54,15 @@ func followerOnOwnConsumer(d firstview.Deps, served []runtime.Served, own string
|
||||
}
|
||||
return d, nil
|
||||
}
|
||||
|
||||
// startViews is serve's first views: it starts the follower over d and answers the options runtime.Run is given, so that on a
|
||||
// module's own account the follower binds nothing and hears on the module's one consumer (runtime.WithHearer), and on the
|
||||
// machine's account the follower binds its own (design 47 H §752, H-A-132, H-A-133).
|
||||
func startViews(ctx context.Context, d firstview.Deps, served []runtime.Served, own string, logf func(string, ...any)) (*firstview.Views, func(), []runtime.Option) {
|
||||
followed, hearer := followerOnOwnConsumer(d, served, own)
|
||||
source, stop := firstview.StartWith(ctx, followed, logf)
|
||||
if hearer == nil {
|
||||
return source, stop, nil
|
||||
}
|
||||
return source, stop, []runtime.Option{runtime.WithHearer(own, hearer.hear)}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/novox/mesh-tools/node-tools/internal/bus"
|
||||
@@ -47,3 +49,28 @@ func TestTheFollowerHearsOnTheOwnModulesOneConsumer(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// serve's first views: on a module's own account the follower binds nothing and the runtime is given the hearer; on the
|
||||
// machine's account the follower binds its own consumer and the runtime is given nothing (design 47 H §752, H-A-132).
|
||||
func TestServesFollowerBindsOnlyOnTheMachinesAccount(t *testing.T) {
|
||||
served := []runtime.Served{{Module: "mesh-delivery-indexer"}}
|
||||
for _, row := range []struct {
|
||||
own string
|
||||
binds bool
|
||||
}{{"mesh-delivery-indexer", false}, {runtime.NodeRuntimeModule, true}} {
|
||||
t.Run(row.own, func(t *testing.T) {
|
||||
bound := 0
|
||||
d := firstview.Deps{Module: row.own,
|
||||
Ask: func(string, any) (json.RawMessage, error) { return nil, errors.New("no owner here") },
|
||||
Consume: func(func(bus.Envelope) error) (func(), error) { bound++; return func() {}, nil }}
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
_, stop, opts := startViews(ctx, d, served, row.own, t.Logf)
|
||||
cancel()
|
||||
stop()
|
||||
if (bound == 1) != row.binds || (len(opts) == 1) == row.binds {
|
||||
t.Fatalf("the follower bound %d consumer(s), the runtime is given %d option(s); want the follower's own binding %v",
|
||||
bound, len(opts), row.binds)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user