Files
mesh-delivery/modules/mesh-delivery-watchman/internal/deadletters/deadletters_test.go
T
jschoubben 1dae2de835 Issue enrolments and keep dead letters without the lease (issue 1126, A2)
The controller ended by its unassignment, so its lease key is absent for
good and mesh-sdk reads that as not handed away: mesh-enrolment's issue
stayed off and the watchman never took DEAD_LETTER_NOTICES, whose notices
age out after a week. Both now act without reading the lease; the
watchman still waits, and says so, while the controller's consumer on the
notices stands. Neither manifest reads the lease any more.

Claude-Session: https://claude.ai/code/session_01NcbgfJ9Gum47zkFKWRaovL
2026-11-02 10:35:40 +01:00

61 lines
2.2 KiB
Go

package deadletters
import (
"strings"
"testing"
"time"
"github.com/nats-io/nats.go"
)
// 1952/WM5, ADR 0564 §5, 1126/A2/AC2: with no lease read at all (the controller ended by its unassignment), the watchman
// makes no consumer while `controller` stands on DEAD_LETTER_NOTICES and says the wait, and makes its own once it is gone;
// it delivers and drops nothing, naming why; and a kept message reads as the controller's copies do, a restricted one's
// age and work queue kept.
func TestTheWatchmanKeepsTheDeadLetters(t *testing.T) {
for _, c := range []struct {
controllerStands, take, waiting bool
}{
{true, false, true},
{false, true, false},
} {
take, waiting := Gate(c.controllerStands)
if take != c.take || waiting != c.waiting {
t.Errorf("Gate(%v) = %v, %v", c.controllerStands, take, waiting)
}
}
for _, c := range []struct {
act string
says string
}{
{"drop", "issue 1953"},
{"deliver", "delivered again"},
{"send", "not deliver or drop"},
} {
if err := Refusal(c.act); err == nil || !strings.Contains(err.Error(), c.says) {
t.Errorf("Refusal(%s) = %v, want it to say %q", c.act, err, c.says)
}
}
at := time.Date(2026, 10, 29, 12, 0, 0, 0, time.UTC)
h := nats.Header{}
h.Set(HeaderStream, "EVENTS")
h.Set(HeaderConsumer, "ace_web")
h.Set(HeaderSequence, "41")
h.Set(HeaderDeliveries, "5")
h.Set(HeaderGaveUp, at.Format(time.RFC3339Nano))
h.Set(HeaderRestricted, "true")
h.Set(HeaderWorkQueue, "true")
h.Set(HeaderAgesOut, at.Add(time.Hour).Format(time.RFC3339Nano))
h.Set("X-Own", "kept")
h.Set("Nats-Msg-Id", "EVENTS.ace_web.41")
d := Of(9, "mesh.events.dead.EVENTS.ace_web", h, []byte("body"), true)
if d.ID != 9 || d.Sequence != 41 || d.Deliveries != 5 || !d.GaveUp.Equal(at) || !d.Restricted || !d.WorkQueue ||
!d.AgesOut.Equal(at.Add(time.Hour)) || d.Who != "how web on ace hears what it consumes" ||
d.Body != "body" || len(d.Headers) != 1 || d.Headers["X-Own"][0] != "kept" {
t.Fatalf("dead letter = %+v", d)
}
if d := Of(10, "mesh.events.dead.SEAT_X.y_worker", nats.Header{}, nil, false); d.Stream != "SEAT_X" || d.Consumer != "y_worker" || d.Body != "" {
t.Fatalf("a copy without headers reads its stream and consumer from its subject: %+v", d)
}
}