perf(cmpp): decouple supplier result callbacks
This commit is contained in:
@@ -17,6 +17,24 @@ type recordingLimiter struct {
|
||||
called bool
|
||||
}
|
||||
|
||||
type acknowledgingResultOutbox struct {
|
||||
client *redis.Client
|
||||
}
|
||||
|
||||
func (o acknowledgingResultOutbox) PublishSubmitResultAndAck(
|
||||
ctx context.Context,
|
||||
commandStream string,
|
||||
commandGroup string,
|
||||
commandMessageID string,
|
||||
_ queue.SubmitCommand,
|
||||
_ queue.SubmitResult,
|
||||
) error {
|
||||
if o.client == nil {
|
||||
return nil
|
||||
}
|
||||
return o.client.XAck(ctx, commandStream, commandGroup, commandMessageID).Err()
|
||||
}
|
||||
|
||||
func (l *recordingLimiter) Wait(_ context.Context, channelID string, rate int) (time.Duration, error) {
|
||||
l.called = true
|
||||
l.channelID = channelID
|
||||
@@ -139,7 +157,8 @@ func TestMessageWorkPoolContinuouslyRefillsWithoutWaitingForSlowSibling(t *testi
|
||||
startedC := make(chan struct{})
|
||||
releaseA := make(chan struct{})
|
||||
worker := &Worker{
|
||||
Redis: client,
|
||||
Redis: client,
|
||||
ResultOutbox: acknowledgingResultOutbox{client: client},
|
||||
Submit: func(_ context.Context, command queue.SubmitCommand) (queue.SubmitResult, error) {
|
||||
switch command.ChannelID {
|
||||
case "channel-a":
|
||||
@@ -188,7 +207,7 @@ func TestMessageWorkPoolContinuouslyRefillsWithoutWaitingForSlowSibling(t *testi
|
||||
func TestMessageWorkPoolAcknowledgesFastMessageBeforeSlowSiblingCompletes(t *testing.T) {
|
||||
mr := miniredis.RunT(t)
|
||||
client := redis.NewClient(&redis.Options{Addr: mr.Addr()})
|
||||
worker := &Worker{Redis: client, Stream: "gateway.submit.commands", Group: "cmpp-gateway"}
|
||||
worker := &Worker{Redis: client, Stream: "gateway.submit.commands", Group: "cmpp-gateway", ResultOutbox: acknowledgingResultOutbox{client: client}}
|
||||
ctx := context.Background()
|
||||
if err := worker.ensureGroup(ctx); err != nil {
|
||||
t.Fatalf("ensureGroup: %v", err)
|
||||
@@ -246,7 +265,7 @@ func TestMessageWorkPoolAcknowledgesFastMessageBeforeSlowSiblingCompletes(t *tes
|
||||
func TestPendingRecoveryDoesNotDuplicateAnActiveOrAlreadyAcknowledgedMessage(t *testing.T) {
|
||||
mr := miniredis.RunT(t)
|
||||
client := redis.NewClient(&redis.Options{Addr: mr.Addr()})
|
||||
worker := &Worker{Redis: client, Stream: "gateway.submit.commands", Group: "cmpp-gateway", MinIdle: time.Millisecond}
|
||||
worker := &Worker{Redis: client, Stream: "gateway.submit.commands", Group: "cmpp-gateway", MinIdle: time.Millisecond, ResultOutbox: acknowledgingResultOutbox{client: client}}
|
||||
ctx := context.Background()
|
||||
if err := worker.ensureGroup(ctx); err != nil {
|
||||
t.Fatalf("ensureGroup: %v", err)
|
||||
|
||||
Reference in New Issue
Block a user