views: hear a seat's event on its bare subject as on its further parts
A seat's contract says an event on its bare subject (the seat mesh-catalog's registration-changed), while both view readers adopted it on `<subject>.>` alone, so the event hub acknowledged it unhandled and the part never acted. The process reader now registers one handler on both forms of the hub (the two patterns do not overlap, so a message reaches it once), and the stdio reader subscribes both forms with the one handler. Builds: design 47 H H-A-166
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -168,6 +169,20 @@ func subTheViewsReaderAndTwoHandlersShareTheModulesOneDurable(t *testing.T) {
|
||||
if _, err := r.Follow("o", "modules", "o.o_read_modules"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// H-A-166: a seat's event said on its bare subject (as the seat mesh-catalog says registration-changed) and one with
|
||||
// further parts both reach the one adopted handler, each once.
|
||||
if info, err := js.Stream(ctx, process.EventsStream); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if cfg := info.CachedInfo().Config; !slices.Contains(cfg.Subjects, "mesh.seat.*.event.>") {
|
||||
cfg.Subjects = append(cfg.Subjects, "mesh.seat.*.event.>")
|
||||
if _, err := js.UpdateStream(ctx, cfg); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
seatHeard := make(chan string, 8)
|
||||
if err := r.AdoptEvent("s", "registration-changed", func(_ context.Context, d []byte) error { seatHeard <- string(d); return nil }); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r.Start(ctx, js, cred, nil)
|
||||
if err := hub.Start(ctx, js, cred); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -181,8 +196,9 @@ func subTheViewsReaderAndTwoHandlersShareTheModulesOneDurable(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, s := range []string{"mesh.mod.p.event.a", "mesh.mod.q.event.b.c", "mesh.mod.z.event.nobody", "mesh.mod.p.event.a"} {
|
||||
if _, err := js.Publish(ctx, s, []byte("{}")); err != nil {
|
||||
for _, s := range []string{"mesh.mod.p.event.a", "mesh.mod.q.event.b.c", "mesh.mod.z.event.nobody", "mesh.mod.p.event.a",
|
||||
"mesh.seat.s.event.registration-changed", "mesh.seat.s.event.registration-changed.m"} {
|
||||
if _, err := js.Publish(ctx, s, []byte(`"`+s+`"`)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
@@ -199,8 +215,18 @@ func subTheViewsReaderAndTwoHandlersShareTheModulesOneDurable(t *testing.T) {
|
||||
t.Fatalf("handler %s got %s, wanted %s", want.who, s, want.subject)
|
||||
}
|
||||
}
|
||||
if len(got["a"])+len(got["b"]) != 0 {
|
||||
t.Fatal("a handler heard a message that was another's")
|
||||
for _, want := range []string{`"mesh.seat.s.event.registration-changed"`, `"mesh.seat.s.event.registration-changed.m"`} {
|
||||
select {
|
||||
case d := <-seatHeard:
|
||||
if d != want {
|
||||
t.Fatalf("the adopted seat event heard %s, wanted %s", d, want)
|
||||
}
|
||||
case <-time.After(10 * time.Second):
|
||||
t.Fatalf("the adopted seat event never heard %s", want)
|
||||
}
|
||||
}
|
||||
if len(got["a"])+len(got["b"])+len(seatHeard) != 0 {
|
||||
t.Fatal("a handler heard a message that was another's, or one twice")
|
||||
}
|
||||
cons, err := js.Consumer(ctx, process.EventsStream, cred.EventConsumerName())
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user