An event a module consumes that no handler takes was said in the journal alone, so a part that never acted on it (the runner's placing at 17:34) was seen only by reading the log. The event hub now tells a hook of each such subject; the process reader, where it holds a findings writer, counts them in one finding event-unhandled per module (the count since the start and the last subject) and clears it at its start, since a new build may handle the event. Without a findings writer the journal line stands alone. Builds: design 47 H H-A-166, H-A-169
69 lines
2.9 KiB
Go
69 lines
2.9 KiB
Go
package process
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/nats-io/nats.go/jetstream"
|
|
)
|
|
|
|
func TestTheHubMatchesSubjectsAndRefusesOverlappingPatterns(t *testing.T) {
|
|
for _, c := range []struct {
|
|
a, b string
|
|
match, overlap bool
|
|
}{
|
|
{"mesh.mod.*.event.views.*", "mesh.mod.o.event.views.x", true, true},
|
|
{"mesh.mod.p.event.>", "mesh.mod.p.event", false, false},
|
|
{"mesh.mod.p.event.a", "mesh.mod.q.event.a", false, false},
|
|
{"mesh.mod.p.event.>", "mesh.mod.*.event.a", false, true},
|
|
{"mesh.mod.p.event.a", "mesh.mod.p.event.a.b", false, false},
|
|
} {
|
|
if got := subjectMatches(c.a, c.b); got != c.match && c.match {
|
|
t.Errorf("%s should match %s", c.a, c.b)
|
|
}
|
|
if got := subjectsOverlap(c.a, c.b); got != c.overlap {
|
|
t.Errorf("overlap(%s, %s) = %v", c.a, c.b, got)
|
|
}
|
|
}
|
|
h := NewEventHub(nil)
|
|
nop := func(jetstream.Msg) {}
|
|
if err := h.Handle("mesh.mod.p.event.>", nop); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := h.Handle("mesh.mod.*.event.a", nop); err == nil {
|
|
t.Fatal("an overlapping pattern was accepted")
|
|
}
|
|
if err := h.Handle("mesh.mod.q.event.>", nop); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// H-A-169: a message no handler takes is acknowledged and told to each OnUnhandled hook, with its subject; one taken is not.
|
|
var told []string
|
|
h.OnUnhandled(func(subject string) { told = append(told, subject) })
|
|
taken, lost := &bindMsg{subject: "mesh.mod.q.event.x"}, &bindMsg{subject: "mesh.seat.s.event.nobody"}
|
|
h.hear(taken)
|
|
h.hear(lost)
|
|
if !lost.acked || len(told) != 1 || told[0] != "mesh.seat.s.event.nobody" {
|
|
t.Errorf("the unhandled message: acked %v, told %v", lost.acked, told)
|
|
}
|
|
// W1.12: a seat's event kept in a stream of its own is heard on one bus name and one durable, the maker's and the
|
|
// hearer's alike; an event kept last per subject is delivered from the last of each subject. The name is the
|
|
// contract's Stream<E> as it stands (seatdef.KeptStream), never made again here: a dotted or unprefixed name is
|
|
// refused by name before the bus is asked.
|
|
a := Account{Node: "ace", Module: "mesh-grants"}
|
|
for _, stream := range []string{"node-engine.running", "SEAT_node-engine.running", "SEAT_", "EVENTS"} {
|
|
if _, err := a.HearSeatEvents(context.Background(), nil, stream, func(jetstream.Msg) {}, nil); err == nil ||
|
|
!strings.Contains(err.Error(), "is not the bus's name of a seat event's stream") {
|
|
t.Errorf("hearing %q: %v", stream, err)
|
|
}
|
|
}
|
|
cfg := a.SeatEventConsumerConfig([]string{"mesh.seat.node-engine.event.running.>"}, true)
|
|
if cfg.Durable != "ace_mesh-grants" || cfg.DeliverPolicy != jetstream.DeliverLastPerSubjectPolicy ||
|
|
cfg.AckPolicy != jetstream.AckExplicitPolicy || len(cfg.FilterSubjects) != 1 {
|
|
t.Errorf("the durable on a stream kept last per subject: %+v", cfg)
|
|
}
|
|
if cfg := a.SeatEventConsumerConfig(nil, false); cfg.DeliverPolicy != jetstream.DeliverAllPolicy {
|
|
t.Errorf("the durable on a stream kept with an age starts from its first message, got %v", cfg.DeliverPolicy)
|
|
}
|
|
}
|