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

Builds: design 47 H2b §836 2. (review round 1, part 1, item 2)
This commit is contained in:
2026-11-27 03:52:27 +01:00
parent c2972eb338
commit e49fe6da5c
+38
View File
@@ -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.>"}