@@ -17,6 +17,7 @@ func TestLoopDo(t *testing.T) {
1717 t .Run ("Stopping" , testLoopDoStopping )
1818 t .Run ("Panic" , testLoopDoPanic )
1919 t .Run ("Sleep" , testLoopDoSleep )
20+ t .Run ("MultiFunc" , testLoopDoMultiFunc )
2021}
2122
2223func testLoopDoReturn (t * testing.T ) {
@@ -256,3 +257,59 @@ func testLoopDoSleepIncrementalMethodZero(t *testing.T) {
256257 fmt .Sprintf ("take (%s) more than expected: %s" , finished .Sub (started ), time .Second ),
257258 )
258259}
260+
261+ func testLoopDoMultiFunc (t * testing.T ) {
262+ t .Parallel ()
263+ t .Run ("FirstErrors" , testLoopDoMultiFuncFirstErrors )
264+ t .Run ("SecondErrors" , testLoopDoMultiFuncSecondErrors )
265+ t .Run ("NoErrors" , testLoopDoMultiFuncNoErrors )
266+ }
267+
268+ func testLoopDoMultiFuncFirstErrors (t * testing.T ) {
269+ t .Parallel ()
270+ l := & retry.Retry {
271+ Attempts : 3 ,
272+ }
273+ err := l .Do (func () error {
274+ return assert .AnError
275+ }, func () error {
276+ t .Error ("should not be called" )
277+ return nil
278+ })
279+ assert .Equal (t , assert .AnError , errors .Cause (err ))
280+ }
281+
282+ func testLoopDoMultiFuncSecondErrors (t * testing.T ) {
283+ t .Parallel ()
284+ l := & retry.Retry {
285+ Attempts : 3 ,
286+ }
287+
288+ calls := 0
289+ err := l .Do (func () error {
290+ calls ++
291+ return nil
292+ }, func () error {
293+ return assert .AnError
294+ })
295+ assert .Equal (t , assert .AnError , errors .Cause (err ))
296+ assert .Equal (t , 3 , calls )
297+ }
298+
299+ func testLoopDoMultiFuncNoErrors (t * testing.T ) {
300+ t .Parallel ()
301+ l := & retry.Retry {
302+ Attempts : 3 ,
303+ }
304+
305+ calls := 0
306+ err := l .Do (func () error {
307+ calls ++
308+ return nil
309+ }, func () error {
310+ calls ++
311+ return nil
312+ })
313+ assert .NoError (t , err )
314+ assert .Equal (t , 2 , calls )
315+ }
0 commit comments