From d4d78953929e7694971da19fbd31efb9186ee0df Mon Sep 17 00:00:00 2001 From: jochen Date: Sat, 21 Nov 2026 01:18:22 +0100 Subject: [PATCH] Indexer: the branch consumer fake answers its CachedInfo and ends when stopped MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With the SDK's guard of one pull per durable (pullOnce reads the consumer's CachedInfo and releases on the consume's Closed), the fake of a branch's durable embedded a nil consumer and a nil consume context, so TestABranchDurableNotThereIsMadeAndHeard panicked. The fake now answers a ConsumerInfo with its stream, name and a created time of its own, and its consume context closes when stopped. No other fake in mesh-delivery embeds jetstream.Consumer; the assigner's, runner's, builder's, watchman's and grants' unit suites pass with the new SDK unchanged. Builds: design 47 H-A-196, H §774 --- .../mesh-delivery-indexer/sourcemoved_test.go | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/sourcemoved_test.go b/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/sourcemoved_test.go index 9b3feb36..54707cda 100644 --- a/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/sourcemoved_test.go +++ b/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/sourcemoved_test.go @@ -7,6 +7,8 @@ import ( "reflect" "slices" "strings" + "sync" + "sync/atomic" "testing" "time" @@ -172,25 +174,43 @@ func (f *fakeBranchJS) Consumer(_ context.Context, stream, name string) (jetstre func (f *fakeBranchJS) CreateConsumer(_ context.Context, stream string, cfg jetstream.ConsumerConfig) (jetstream.Consumer, error) { f.made = append(f.made, cfg) - c := &fakeBranchConsumer{} + c := newFakeBranchConsumer(stream, cfg.Durable) f.held[stream+"/"+cfg.Durable] = c return c, nil } -// fakeBranchConsumer hands one source-moved to the hearing as soon as it is consumed. +// fakeBranchConsumer hands one source-moved to the hearing as soon as it is consumed. It answers its CachedInfo as the bus +// does, with its stream, name and created time, which the SDK's guard of one pull per durable keys by (design 47 H-A-196). type fakeBranchConsumer struct { jetstream.Consumer + info jetstream.ConsumerInfo heard int } -type fakeConsumeContext struct{ jetstream.ConsumeContext } +// fakeConsumersMade numbers the fakes, so each is created at a time of its own, as each durable the bus makes is. +var fakeConsumersMade atomic.Int64 -func (fakeConsumeContext) Stop() {} +func newFakeBranchConsumer(stream, durable string) *fakeBranchConsumer { + return &fakeBranchConsumer{info: jetstream.ConsumerInfo{Stream: stream, Name: durable, Config: jetstream.ConsumerConfig{Durable: durable}, + Created: time.Unix(0, fakeConsumersMade.Add(1)).UTC()}} +} + +func (c *fakeBranchConsumer) CachedInfo() *jetstream.ConsumerInfo { return &c.info } + +// fakeConsumeContext is a consume that ends when stopped, as the guard's release waits for (H-A-196). +type fakeConsumeContext struct { + jetstream.ConsumeContext + stop sync.Once + closed chan struct{} +} + +func (c *fakeConsumeContext) Stop() { c.stop.Do(func() { close(c.closed) }) } +func (c *fakeConsumeContext) Closed() <-chan struct{} { return c.closed } func (c *fakeBranchConsumer) Consume(handle jetstream.MessageHandler, _ ...jetstream.PullConsumeOpt) (jetstream.ConsumeContext, error) { c.heard++ handle(msgOf{f: &fakeMsg{subject: "mesh.seat.mesh-delivery.event.source-moved.main.2"}}) - return fakeConsumeContext{}, nil + return &fakeConsumeContext{closed: make(chan struct{})}, nil } // Design 47 H §743, H-A-134: a branch's durable the bus does not hold the indexer makes, as a module's seat-event consumer is @@ -207,7 +227,7 @@ func TestABranchDurableNotThereIsMadeAndHeard(t *testing.T) { name := "n1_mesh-delivery-indexer_" + keys.EscapeName("main") var existing *fakeBranchConsumer if tc.held { - existing = &fakeBranchConsumer{} + existing = newFakeBranchConsumer(meshdelivery.StreamSourceMoved, name) js.held[meshdelivery.StreamSourceMoved+"/"+name] = existing } var heard []string