@@ -153,40 +153,48 @@ func TestRetrierRunFnWithInfinite(t *testing.T) {
153
153
}
154
154
}
155
155
156
- func TestRetrierCtxSurfaceWorkErrors (t * testing.T ) {
157
- // Will timeout before getting to errBar.
158
- ctx , cancel := context .WithTimeout (context .Background (), 7 * time .Millisecond )
156
+ func TestRetrierRunFnWithSurfaceWorkErrors (t * testing.T ) {
157
+ ctx , cancel := context .WithCancel (context .Background ())
159
158
defer cancel ()
160
159
r := New ([]time.Duration {0 , 10 * time .Millisecond }, nil ).WithSurfaceWorkErrors ()
161
- errExpected := []error {errFoo , errFoo , errBar , errBaz }
162
- retries := 0
163
- err := r .RunCtx (ctx , func (ctx context.Context ) error {
160
+ errExpected := []error {errFoo , errBar , errBaz }
161
+
162
+ err := r .RunFn (ctx , func (ctx context.Context , retries int ) error {
164
163
if retries >= len (errExpected ) {
165
164
return nil
166
165
}
166
+ if retries == 1 {
167
+ // Context canceled inside second call to work function.
168
+ cancel ()
169
+ }
167
170
err := errExpected [retries ]
168
171
retries ++
169
172
return err
170
173
})
171
- if err != errFoo {
174
+ if err != errBar {
172
175
t .Error (err )
173
176
}
174
177
}
175
178
176
- func TestRetrierRunFnWithSurfaceWorkErrors (t * testing.T ) {
177
- // Will timeout before getting to errBar.
178
- ctx , cancel := context .WithTimeout (context .Background (), 7 * time .Millisecond )
179
+ func TestRetrierRunFnWithoutSurfaceWorkErrors (t * testing.T ) {
180
+ ctx , cancel := context .WithCancel (context .Background ())
179
181
defer cancel ()
180
- r := New ([]time.Duration {0 , 10 * time .Millisecond }, nil ). WithSurfaceWorkErrors ()
181
- errExpected := []error {errFoo , errFoo , errFoo , errBar , errBaz }
182
+ r := New ([]time.Duration {0 , 10 * time .Millisecond }, nil )
183
+ errExpected := []error {errFoo , errBar , errBaz }
182
184
183
185
err := r .RunFn (ctx , func (ctx context.Context , retries int ) error {
184
186
if retries >= len (errExpected ) {
185
187
return nil
186
188
}
187
- return errExpected [retries ]
189
+ if retries == 1 {
190
+ // Context canceled inside second call to work function.
191
+ cancel ()
192
+ }
193
+ err := errExpected [retries ]
194
+ retries ++
195
+ return err
188
196
})
189
- if err != errFoo {
197
+ if err != context . Canceled {
190
198
t .Error (err )
191
199
}
192
200
}
0 commit comments