package link import ( "strings" "testing" "time" "github.com/nats-io/nats.go" ) // A work-queue stream's dead letters are kept and shown as a restricted stream's are — aged with the // stream, never with their body or headers — and can only be dropped, never delivered again (novox/hq ADR // 0436 §6, changing ADR 0363 §7 for such a stream). // 1178/AC3: a dead letter's headers say it came from a work-queue stream, and reading it back carries that // (and the restricted flag its aging and hiding already key off, deadLetterOf being the one place both are // read: see DeadLetter.Restricted's doc). func TestAWorkQueueDeadLettersHeaderIsReadBack(t *testing.T) { agesOut := time.Now().Add(time.Hour).UTC() h := nats.Header{} h.Set(DeadHeaderStream, "MAIL_SENDS") h.Set(DeadHeaderConsumer, "novox_mesh-mail_send") h.Set(DeadHeaderSubject, "mesh.stream.mesh-mail.event.mail.send.approved") h.Set(DeadHeaderRestricted, "true") h.Set(DeadHeaderWorkQueue, "true") h.Set(DeadHeaderAgesOut, agesOut.Format(time.RFC3339Nano)) d := deadLetterOf(42, "mesh.stream.mesh-mail.event.mail.send.approved", h, []byte("secret body"), false) if !d.WorkQueue { t.Fatalf("a work-queue dead letter read as %+v", d) } if !d.Restricted { t.Fatalf("a work-queue dead letter is not read as restricted, so it would be shown with its body: %+v", d) } if !d.AgesOut.Equal(agesOut) { t.Fatalf("ages out at %v, want %v — it should age with its stream", d.AgesOut, agesOut) } } // 1178/AC3: asking to deliver a work-queue dead letter again is refused, naming ADR 0436 clause 6 — before // anything is asked of the bus, so it holds whatever max-deliver or age is left. func TestAWorkQueueDeadLetterIsNeverDeliveredAgain(t *testing.T) { d := DeadLetter{ID: 7, Stream: "MAIL_SENDS", Consumer: "novox_mesh-mail_send", Subject: "mesh.stream.mesh-mail.event.mail.send.approved", WorkQueue: true, Restricted: true, AgesOut: time.Now().Add(time.Hour)} if _, err := AgainTo(nil, d); err == nil || !strings.Contains(err.Error(), "ADR 0436 clause 6") || !strings.Contains(err.Error(), "Drop it") { t.Fatalf("delivering a work-queue dead letter again: %v; want a refusal naming ADR 0436 clause 6", err) } }