Skip to content

Commit 8363c28

Browse files
fix: correct pipeline error behavior
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.
1 parent 80794c9 commit 8363c28

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

mock.go

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,17 @@ func (h redisClientHook) ProcessHook(_ redis.ProcessHook) redis.ProcessHook {
107107

108108
func (h redisClientHook) ProcessPipelineHook(_ redis.ProcessPipelineHook) redis.ProcessPipelineHook {
109109
return func(ctx context.Context, cmds []redis.Cmder) error {
110+
var lastErr error
110111
for _, cmd := range cmds {
111112
err := h.fn(cmd)
112113
if h.returnErr != nil && (err == nil || cmd.Err() == nil) {
113114
err = h.returnErr
114115
}
115116
if err != nil {
116-
return err
117+
lastErr = err
117118
}
118119
}
119-
return nil
120+
return lastErr
120121
}
121122
}
122123

@@ -2862,29 +2863,29 @@ func (m *mock) ExpectTSMRangeWithArgs(fromTimestamp int, toTimestamp int, filter
28622863
}
28632864

28642865
func (m *mock) ExpectTSMRevRange(fromTimestamp int, toTimestamp int, filterExpr []string) *ExpectedMapStringSliceInterface {
2865-
e := &ExpectedMapStringSliceInterface{}
2866-
e.cmd = m.factory.TSMRevRange(m.ctx, fromTimestamp, toTimestamp, filterExpr)
2867-
m.pushExpect(e)
2868-
return e
2866+
e := &ExpectedMapStringSliceInterface{}
2867+
e.cmd = m.factory.TSMRevRange(m.ctx, fromTimestamp, toTimestamp, filterExpr)
2868+
m.pushExpect(e)
2869+
return e
28692870
}
28702871

28712872
func (m *mock) ExpectTSMRevRangeWithArgs(fromTimestamp int, toTimestamp int, filterExpr []string, options *redis.TSMRevRangeOptions) *ExpectedMapStringSliceInterface {
2872-
e := &ExpectedMapStringSliceInterface{}
2873-
e.cmd = m.factory.TSMRevRangeWithArgs(m.ctx, fromTimestamp, toTimestamp, filterExpr, options)
2874-
m.pushExpect(e)
2875-
return e
2873+
e := &ExpectedMapStringSliceInterface{}
2874+
e.cmd = m.factory.TSMRevRangeWithArgs(m.ctx, fromTimestamp, toTimestamp, filterExpr, options)
2875+
m.pushExpect(e)
2876+
return e
28762877
}
28772878

28782879
func (m *mock) ExpectTSMGet(filters []string) *ExpectedMapStringSliceInterface {
2879-
e := &ExpectedMapStringSliceInterface{}
2880-
e.cmd = m.factory.TSMGet(m.ctx, filters)
2881-
m.pushExpect(e)
2882-
return e
2880+
e := &ExpectedMapStringSliceInterface{}
2881+
e.cmd = m.factory.TSMGet(m.ctx, filters)
2882+
m.pushExpect(e)
2883+
return e
28832884
}
28842885

28852886
func (m *mock) ExpectTSMGetWithArgs(filters []string, options *redis.TSMGetOptions) *ExpectedMapStringSliceInterface {
2886-
e := &ExpectedMapStringSliceInterface{}
2887-
e.cmd = m.factory.TSMGetWithArgs(m.ctx, filters, options)
2888-
m.pushExpect(e)
2889-
return e
2887+
e := &ExpectedMapStringSliceInterface{}
2888+
e.cmd = m.factory.TSMGetWithArgs(m.ctx, filters, options)
2889+
m.pushExpect(e)
2890+
return e
28902891
}

0 commit comments

Comments
 (0)