Skip to content

Commit

Permalink
changed to check ctx is not closed at the start of processing
Browse files Browse the repository at this point in the history
  • Loading branch information
convto committed Dec 26, 2022
1 parent 9a38d4c commit daa4e7b
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions async_retry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,16 @@ func Test_asyncRetry_Do(t *testing.T) {
name: "Timeout set correctly for each try",
args: args{
f: func(ctx context.Context) error {
started := time.Now()
select {
case <-ctx.Done():
// Check ctx passed from async-retry is not closed at the start of f() processing.
return fmt.Errorf("context already closed")
default:
}

counter++
select {
case <-ctx.Done():
// Since the timeout for this test case is 10 msec,
// even considering the error of the measurement,
// at least 9 msec should have elapsed by the time `ctx.Done()` is received.
if time.Since(started) < (9 * time.Millisecond) {
return Unrecoverable(fmt.Errorf("timeout is too fast"))
}
if counter < 3 {
return fmt.Errorf("timeout")
}
Expand All @@ -147,7 +147,7 @@ func Test_asyncRetry_Do(t *testing.T) {
},
opts: []Option{
Delay(1 * time.Millisecond),
Timeout(10 * time.Millisecond),
Timeout(1 * time.Second),
Attempts(5),
},
},
Expand Down

0 comments on commit daa4e7b

Please sign in to comment.