From e49fe6da5c0797c66fec2a5c5541347e95d04bd1 Mon Sep 17 00:00:00 2001 From: jochen Date: Fri, 27 Nov 2026 03:52:27 +0100 Subject: [PATCH] H2b-review-2 wake-before-first-bind-row: a row where durables-composed is said from inside Start's failing bind and the stream is bound MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Builds: design 47 H2b ยง836 2. (review round 1, part 1, item 2) --- go/process/event_hub_test.go | 38 ++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/go/process/event_hub_test.go b/go/process/event_hub_test.go index 147f760d..e934434a 100644 --- a/go/process/event_hub_test.go +++ b/go/process/event_hub_test.go @@ -447,6 +447,8 @@ type fakeHubBus struct { onWake func() reconn func() stopped bool + // missed is called, with no lock held, from inside a bind that finds no durable composed (a test composes it there). + missed func(stream string) } func (b *fakeHubBus) streamNames(context.Context) ([]string, error) { return b.streams, nil } @@ -458,6 +460,11 @@ func (b *fakeHubBus) bind(stream string) (jetstream.ConsumeContext, time.Time, e defer b.mu.Unlock() err, ok := b.composed[stream] if !ok { + if b.missed != nil { + b.mu.Unlock() + b.missed(stream) + b.mu.Lock() + } return nil, time.Time{}, fmt.Errorf("no durable: %w", jetstream.ErrConsumerNotFound) } if err != nil { @@ -559,6 +566,37 @@ func subTheHubStartBindsEveryPatternAndSaysWhenAllAreHeard(t *testing.T) { t.Errorf("OnUnheard was told %v", unheardTold) } }) + // AC-836b clause 2: the wake is made before the first bind, so the word that the durables were composed, said from inside + // Start's own failing bind, binds the stream. + t.Run("composed while Start's bind fails", func(t *testing.T) { + bus := base(map[string]error{EventsStream: nil}) + bus.missed = func(stream string) { + bus.mu.Lock() + bus.composed[stream] = nil + wake := bus.onWake + bus.mu.Unlock() + if wake != nil { + go wake() // the subscription's own goroutine: it waits for Start's pass to end + } + } + h, allHeard, _ := newHub(bus) + heard := make(chan struct{}, 4) + h.OnAllHeard(func() { heard <- struct{}{} }) + if err := h.start(context.Background(), bus, cred); err != nil { + t.Fatal(err) + } + defer h.Stop() + select { + case <-heard: + case <-time.After(10 * time.Second): + t.Fatalf("the durable composed during Start's bind was never bound: binds %v", bus.binds) + } + bus.mu.Lock() + defer bus.mu.Unlock() + if *allHeard != 1 || !slices.Contains(bus.binds, kept) { + t.Errorf("all heard %d, binds %v", *allHeard, bus.binds) + } + }) t.Run("no stream carries a pattern", func(t *testing.T) { bus := base(map[string]error{EventsStream: nil, kept: nil}) bus.subjects = []string{"mesh.seat.*.event.>"}