Skip to content

Commit

Permalink
fix: correct pipeline error behavior
Browse files Browse the repository at this point in the history
The behavior of the mock was different than the one in `go-redis`.
In the real implementation the error of the last command is returned and all commands are executed (see https://github.com/redis/go-redis/blob/f752b9a9d5cc158381c2ffe5b13c531037426b39/redis.go#L501C22-L524)

In redismock the execution stopped on the first error, which is wrong.
  • Loading branch information
jonasmeier1212 committed Jun 14, 2024
1 parent 80794c9 commit 8363c28
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,17 @@ func (h redisClientHook) ProcessHook(_ redis.ProcessHook) redis.ProcessHook {

func (h redisClientHook) ProcessPipelineHook(_ redis.ProcessPipelineHook) redis.ProcessPipelineHook {
return func(ctx context.Context, cmds []redis.Cmder) error {
var lastErr error
for _, cmd := range cmds {
err := h.fn(cmd)
if h.returnErr != nil && (err == nil || cmd.Err() == nil) {
err = h.returnErr
}
if err != nil {
return err
lastErr = err
}
}
return nil
return lastErr
}
}

Expand Down Expand Up @@ -2862,29 +2863,29 @@ func (m *mock) ExpectTSMRangeWithArgs(fromTimestamp int, toTimestamp int, filter
}

func (m *mock) ExpectTSMRevRange(fromTimestamp int, toTimestamp int, filterExpr []string) *ExpectedMapStringSliceInterface {
e := &ExpectedMapStringSliceInterface{}
e.cmd = m.factory.TSMRevRange(m.ctx, fromTimestamp, toTimestamp, filterExpr)
m.pushExpect(e)
return e
e := &ExpectedMapStringSliceInterface{}
e.cmd = m.factory.TSMRevRange(m.ctx, fromTimestamp, toTimestamp, filterExpr)
m.pushExpect(e)
return e
}

func (m *mock) ExpectTSMRevRangeWithArgs(fromTimestamp int, toTimestamp int, filterExpr []string, options *redis.TSMRevRangeOptions) *ExpectedMapStringSliceInterface {
e := &ExpectedMapStringSliceInterface{}
e.cmd = m.factory.TSMRevRangeWithArgs(m.ctx, fromTimestamp, toTimestamp, filterExpr, options)
m.pushExpect(e)
return e
e := &ExpectedMapStringSliceInterface{}
e.cmd = m.factory.TSMRevRangeWithArgs(m.ctx, fromTimestamp, toTimestamp, filterExpr, options)
m.pushExpect(e)
return e
}

func (m *mock) ExpectTSMGet(filters []string) *ExpectedMapStringSliceInterface {
e := &ExpectedMapStringSliceInterface{}
e.cmd = m.factory.TSMGet(m.ctx, filters)
m.pushExpect(e)
return e
e := &ExpectedMapStringSliceInterface{}
e.cmd = m.factory.TSMGet(m.ctx, filters)
m.pushExpect(e)
return e
}

func (m *mock) ExpectTSMGetWithArgs(filters []string, options *redis.TSMGetOptions) *ExpectedMapStringSliceInterface {
e := &ExpectedMapStringSliceInterface{}
e.cmd = m.factory.TSMGetWithArgs(m.ctx, filters, options)
m.pushExpect(e)
return e
e := &ExpectedMapStringSliceInterface{}
e.cmd = m.factory.TSMGetWithArgs(m.ctx, filters, options)
m.pushExpect(e)
return e
}

0 comments on commit 8363c28

Please sign in to comment.