Design 47 H1: the views reader's test waits for the acknowledged floor, not the pending count (H-A-196, H-A-197) #205

Merged
mesh-tools merged 1 commits from fix/47-H1-sdk-views-one-durable into main 2026-11-21 00:27:19 +00:00
+18 -3
View File
@@ -154,7 +154,9 @@ func subTheViewsReaderAndTwoHandlersShareTheModulesOneDurable(t *testing.T) {
hub := process.NewEventHub(t.Logf)
got := map[string]chan string{"a": make(chan string, 8), "b": make(chan string, 8)}
for name, pattern := range map[string]string{"a": "mesh.mod.p.event.a", "b": "mesh.mod.q.event.b.*"} {
if err := hub.Handle(pattern, func(m jetstream.Msg) { _ = m.Ack(); got[name] <- m.Subject() }); err != nil {
// The handlers' acknowledgement waits for the bus's answer, so a message a handler handed on is acknowledged
// on the bus, and every one the hub handed before it too (acks of one consumer are taken in order).
if err := hub.Handle(pattern, func(m jetstream.Msg) { _ = m.DoubleAck(ctx); got[name] <- m.Subject() }); err != nil {
t.Fatal(err)
}
}
@@ -230,12 +232,25 @@ func subTheViewsReaderAndTwoHandlersShareTheModulesOneDurable(t *testing.T) {
if len(got["a"])+len(got["b"])+len(seatHeard) != 0 {
t.Fatal("a handler heard a message that was another's, or one twice")
}
// The reader acknowledges an event after it took it into its picture and the adopted handler returned, so the
// picture and the handler say nothing of its ack: one more event, handed after them in order and acknowledged with
// the bus's answer, is the mark that every ack before it has landed (the build node, main.54, read one pending). An
// event said after the mark (the owner's own mark of its burst) may still wait for its ack, so the floor is read.
mark, err := js.Publish(ctx, "mesh.mod.p.event.a", []byte(`"the mark"`))
if err != nil {
t.Fatal(err)
}
select {
case <-got["a"]:
case <-time.After(10 * time.Second):
t.Fatal("the mark after the handled events was not heard")
}
cons, err := js.Consumer(ctx, process.EventsStream, cred.EventConsumerName())
if err != nil {
t.Fatal(err)
}
if info, err := cons.Info(ctx); err != nil || info.NumAckPending != 0 {
t.Fatalf("a message was left unacknowledged: %+v %v", info, err)
if info, err := cons.Info(ctx); err != nil || info.AckFloor.Stream < mark.Sequence {
t.Fatalf("a message up to the mark %d was left unacknowledged: %+v %v", mark.Sequence, info, err)
}
// H-A-169: the one event no handler takes is the module's finding event-unhandled, counted once, naming its subject,
// though the reader started twice.