Merge pull request 'Design 47 H1: the indexer's test fakes answer what the SDK's pull guard reads (H-A-196)' (#300) from fix/47-H1-indexer-fake-consumer into main
This commit was merged in pull request #300.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user