G2 keeper-kept-durables: the bus module's process gets a heard durable on each kept stream its module consumes
The bus module's process (the keeper) gets, beside its consumer on EVENTS, a durable on each kept seat event's stream that carries a consume of its module, named as its durable on EVENTS, and the grants to read and acknowledge it as any process's heard durable has. Row in TestAProcessBusHearsWhatItsModuleConsumes. Builds: design 47 H2b §836 5.
This commit is contained in:
@@ -229,6 +229,11 @@ func ConsumersOf(users []Principal) []ModuleConsumer {
|
||||
if c, ok := keeperConsumer(p); ok {
|
||||
out = append(out, ModuleConsumer{Node: p.Node, Module: p.Module, Consumer: c})
|
||||
}
|
||||
for _, h := range p.Hears {
|
||||
if len(h.Filters) > 0 {
|
||||
out = append(out, ModuleConsumer{Node: p.Node, Module: p.Module, Consumer: heardConsumer(p, h)})
|
||||
}
|
||||
}
|
||||
}
|
||||
// Any other process hears what its bus consumes on consumers of its own: on EVENTS, and on each kept seat event's
|
||||
// stream (design 47 G A-340).
|
||||
|
||||
@@ -126,6 +126,7 @@ func processGrants(p Principal) (pub, sub []string, err error) {
|
||||
if c, ok := keeperConsumer(p); ok {
|
||||
pub = append(pub, keeperConsumerGrants(c)...)
|
||||
}
|
||||
pub = append(pub, heardGrants(p, p.Hears)...) // and its heard durable on each kept stream its module consumes (design 47 H2b §836 5.)
|
||||
pub = append(pub, ownStreamGrants(p.Module, p.Streams)...)
|
||||
pub = append(pub, p.SaysSeatEvents...)
|
||||
tp, ts := seatTrafficGrants(SeatTrafficOf(p.Module, nil, p.Uses, nil))
|
||||
|
||||
@@ -325,6 +325,9 @@ func Users(r Records) ([]Principal, error) {
|
||||
k.KeepsBus, k.KeepsBusState = true, BusStateNames(r.BusState, r.Bound)
|
||||
k.KeepsRestricted = restrictedStreamNames(r)
|
||||
k.Consumes, k.Streams = d.Consumes, d.Streams
|
||||
// A kept seat event its module consumes is heard on the event's own stream, as every other process hears one
|
||||
// (design 47 H2b §836 5.): its heard durable, named as its durable on EVENTS.
|
||||
_, k.Hears = SplitKept(r.Kept, d.Consumes)
|
||||
k.Watches = d.Watches
|
||||
k.SaysSeatEvents = brokerSeatEvents(d.Holds)
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package grants
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -62,8 +63,12 @@ func TestAProcessBusHearsWhatItsModuleConsumes(t *testing.T) {
|
||||
}
|
||||
const stream, subject = "SEAT_mesh-conditions_findings-asked", "mesh.seat.mesh-conditions.event.findings-asked"
|
||||
users, err := buscompose.Users(buscompose.Records{Nodes: []string{"ace"},
|
||||
Kept: []buscompose.KeptEvent{{Seat: "mesh-conditions", Event: "findings-asked", Stream: stream, Filter: subject}},
|
||||
Assigned: map[string][]buscompose.Declared{"ace": {{Module: "zfs", Consumes: m.Consumes, Processes: processesOf(m)}}}})
|
||||
Kept: []buscompose.KeptEvent{{Seat: "mesh-conditions", Event: "findings-asked", Stream: stream, Filter: subject}},
|
||||
Assigned: map[string][]buscompose.Declared{"ace": {{Module: "zfs", Consumes: m.Consumes, Processes: processesOf(m)},
|
||||
// 1984/AC-836l (design 47 H2b §836 5.): the bus module's process hears what its module consumes of a kept seat event on
|
||||
// the event's stream too, on a durable named as its durable on EVENTS.
|
||||
{Module: "nats", SnapshotsTheBus: true, Consumes: []string{"mesh-conditions.findings-asked"},
|
||||
Processes: []buscompose.ProcessPrincipal{{Process: "bus-keeper", Keeps: true}}}}}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -86,6 +91,25 @@ func TestAProcessBusHearsWhatItsModuleConsumes(t *testing.T) {
|
||||
buscompose.MayPublish(perms["keeper"], s), buscompose.MayPublish(perms["mute"], s))
|
||||
}
|
||||
}
|
||||
for _, u := range users {
|
||||
if u.Kind == buscompose.KindProcess && u.Process == "bus-keeper" {
|
||||
pm, err := buscompose.PermissionsFor(u)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
const keeperDurable = "ace_nats_bus-keeper"
|
||||
if !buscompose.MayPublish(pm, "$JS.API.CONSUMER.MSG.NEXT."+stream+"."+keeperDurable) || !buscompose.MayPublish(pm, "$JS.ACK."+stream+"."+keeperDurable+".1") {
|
||||
t.Errorf("the bus module's process may not read its durable on %s", stream)
|
||||
}
|
||||
heard := false
|
||||
for _, c := range buscompose.AccountConsumers(users) {
|
||||
heard = heard || c.Module == "nats" && c.Consumer.Stream == stream && c.Consumer.Name == keeperDurable && slices.Equal(c.Consumer.Filters, []string{subject})
|
||||
}
|
||||
if !heard {
|
||||
t.Errorf("the bus module's process has no durable %s on %s", keeperDurable, stream)
|
||||
}
|
||||
}
|
||||
}
|
||||
var made []string
|
||||
for _, c := range buscompose.AccountConsumers(users) {
|
||||
if c.Module == "zfs" && strings.HasPrefix(c.Consumer.Name, "ace_zfs_") && !strings.HasSuffix(c.Consumer.Name, buscompose.ToolsSuffix) { // the processes' own, not the module's nor its runner's
|
||||
|
||||
Reference in New Issue
Block a user