package broker import "testing" // mailSendsStream is mesh-mail's future `mail-sends` stream (novox/hq ADR 0436 §7, §8), as the bus holds it: // work-queue retention, a 24-hour duplicate window, kept one day and at most 64 MiB. var mailSendsStream = ModuleStream{Module: "mesh-mail", Name: "MAIL_SENDS", Events: []string{"mail.send.approved"}, MaxAgeDays: 1, MaxMiB: 64, WorkQueue: true, Duplicates: 24} // 1177/AC1: a work-queue stream is composed with work-queue retention, refusing a new message when full // (DiscardNew), a 24-hour duplicate window, a one-day maximum age and a 64 MiB cap. func TestAWorkQueueStreamIsComposedToRefuseWhenFull(t *testing.T) { s := mailSendsStream.Stream() if s.Retention != RetentionWorkQueue { t.Fatalf("retention: %v, want %v", s.Retention, RetentionWorkQueue) } if !s.DiscardNew { t.Fatal("a work-queue stream did not refuse a new message when full") } if s.DuplicatesSeconds != 24*60*60 { t.Fatalf("duplicate window: %d seconds, want %d (24 hours)", s.DuplicatesSeconds, 24*60*60) } if s.MaxAge != 24*60*60 { t.Fatalf("max age: %d seconds, want %d (1 day)", s.MaxAge, 24*60*60) } if s.MaxBytes != 64<<20 { t.Fatalf("max bytes: %d, want %d (64 MiB)", s.MaxBytes, 64<<20) } } // 1177/AC3: a stream with no work-queue clause composes exactly as main does: limits retention, dropping its // oldest, never refusing a new message. func TestANonWorkQueueStreamStillDropsItsOldest(t *testing.T) { s := mailStream.Stream() if s.Retention != RetentionLimits || s.DiscardNew || s.DuplicatesSeconds != 0 { t.Fatalf("composed as %+v; want limits retention, never discarding new, no duplicate window", s) } } // 1178/AC1: the process a work-queue stream's bus.queues names gets exactly one durable consumer, // __, with the stream's declared max-deliver — composed even though mesh-mail's // sender otherwise consumes and watches nothing of its own, which alone would give ConsumerFor nothing // needed. Explicit acknowledgement is EnsureConsumer's own rule for every consumer it makes (jetstream.go), // so it is not re-asserted here. func TestTheOneProcessAWorkQueuesBusNamesGetsItsOwnConsumer(t *testing.T) { sender := Principal{Kind: KindModule, Node: "novox", Module: "mesh-mail", PasswordHash: "x", Queues: []QueueOwner{{Process: "send", Stream: "MAIL_SENDS", MaxDeliver: 5}}} got := ConsumersOf([]Principal{sender}) if len(got) != 1 { t.Fatalf("mesh-mail's consumers: %+v", got) } c := got[0].Consumer if c.Name != "novox_mesh-mail_send" || c.Stream != "MAIL_SENDS" || c.MaxDeliver != 5 { t.Fatalf("the queue's consumer: %+v", c) } }