H1 one consumer loop: the follower hears on the module's one consumer
In a module's own runtime the branch follower (first views) and the bundles each bound the module's durable <node>_<module>_tools with a pull loop of their own, so each event reached one of the two: the catalog revision of main.1 reached the follower and never the indexer's bundle, whose revision verb answered none-yet. The runtime now binds the consumer once, for the bundles, and hands each event to the follower after the bundles took it (runtime.WithHearer); the machine's runtime keeps the follower's own binding. Builds: design 47 H §752, H-A-113, H-A-132 Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
This commit is contained in:
@@ -193,3 +193,44 @@ func TestAHeartbeatHandlerSetAgainWhileWordsAreHandedOnIsNotARace(t *testing.T)
|
||||
t.Error("a bundle gave a handler and no heartbeat is asked")
|
||||
}
|
||||
}
|
||||
|
||||
// In a module's own runtime the module's consumer is bound once: one event on it reaches the bundle and then the runtime's
|
||||
// hearer (the branch follower), and an event the bundle did not take is offered again before the hearer hears it (design 47
|
||||
// H §752, H-A-132).
|
||||
func TestOneEventOnAModulesConsumerReachesTheBundleAndTheHearer(t *testing.T) {
|
||||
var order []string
|
||||
all := &consumers{logf: t.Logf, of: map[string]*moduleEvents{}}
|
||||
WithHearer("mod", func(env bus.Envelope) error { order = append(order, "hearer "+env.Key); return nil })(all)
|
||||
m := &moduleEvents{}
|
||||
all.of["mod"] = m
|
||||
bundle := &deliverSlot{}
|
||||
refuse := false
|
||||
bundle.set(func(raw json.RawMessage) error {
|
||||
if refuse {
|
||||
return errorf("not now")
|
||||
}
|
||||
var env bus.Envelope
|
||||
if err := json.Unmarshal(raw, &env); err != nil {
|
||||
return err
|
||||
}
|
||||
order = append(order, "bundle "+env.Key)
|
||||
return nil
|
||||
})
|
||||
m.delivers = []*deliverSlot{bundle}
|
||||
if err := all.handOut("mod", m, bus.Envelope{Key: "mesh-catalog.catalog-revision.main", Body: json.RawMessage(`{}`)}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := strings.Join(order, ", "); got != "bundle mesh-catalog.catalog-revision.main, hearer mesh-catalog.catalog-revision.main" {
|
||||
t.Fatalf("the event reached %q, want the bundle and then the hearer", got)
|
||||
}
|
||||
order, refuse = nil, true
|
||||
if err := all.handOut("mod", m, bus.Envelope{Key: "a.b", Body: json.RawMessage(`{}`)}); err == nil || len(order) != 0 {
|
||||
t.Fatalf("an event the bundle did not take: err %v, reached %q; want it offered again, heard by none", err, order)
|
||||
}
|
||||
// Another module's events are handed to its bundles alone.
|
||||
other := &moduleEvents{delivers: []*deliverSlot{{f: func(json.RawMessage) error { order = append(order, "other"); return nil }}}}
|
||||
all.of["other"] = other
|
||||
if err := all.handOut("other", other, bus.Envelope{Key: "a.b", Body: json.RawMessage(`{}`)}); err != nil || strings.Join(order, ",") != "other" {
|
||||
t.Fatalf("another module's event: err %v, reached %q", err, order)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user