Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
karenychen committed Aug 5, 2024
1 parent 7f8dcda commit 0afa328
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions v2/lockrenewer.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ func (plr *peekLockRenewer) renewMessageLock(ctx context.Context, message *azser
// we should keep retrying until lock expiry or until message context is done
for time.Until(*message.LockedUntil) > 0 && ctx.Err() == nil {
err := plr.renewMessageLockWithTimeout(ctx, renewalTimeout, message, options)
// exit the renewal if we get any error other than context canceled or if the error is nil.
if !errors.Is(err, context.Canceled) {
// exit the renewal if we get any error other than context deadline exceeded or if the error is nil.
if !errors.Is(err, context.DeadlineExceeded) {
return err
}
}
Expand Down
26 changes: 13 additions & 13 deletions v2/lockrenewer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,10 @@ func Test_RenewPeriodically_Error(t *testing.T) {
},
},
{
name: "stop periodic renewal on renewal context deadline exceeded",
name: "stop periodic renewal on renewal context canceled",
isRenewerCanceled: false,
settler: &fakeSBRenewLockSettler{
Err: context.DeadlineExceeded,
Err: context.Canceled,
},
verify: func(g Gomega, tc *testCase, metrics *processor.Informer) {
g.Consistently(
Expand Down Expand Up @@ -381,16 +381,16 @@ func Test_RenewTimeoutOption(t *testing.T) {
},
},
{
name: "should exit after first lock renewal failure due to context deadline exceeded",
name: "should exit after first lock renewal failure due to context canceled",
settler: &fakeSBRenewLockSettler{
// set delay to be greater than interval to check for lockTimeout
Delay: time.Duration(100) * time.Millisecond,
// customized error to check renewal timeout config
Err: context.DeadlineExceeded,
Err: context.Canceled,
},
renewTimeout: to.Ptr(time.Duration(0)),
verify: func(g Gomega, tc *testCase, metrics *processor.Informer) {
// first renewal attempt at 0ms and finish at 50ms with error DeadlineExceeded
// first renewal attempt at 0ms and finish at 50ms with error Canceled
// lock renew handler cancels message context of downstream handler
g.Eventually(
func(g Gomega) { g.Expect(tc.settler.RenewCalled.Load()).To(Equal(int32(1))) },
Expand Down Expand Up @@ -464,7 +464,7 @@ func Test_RenewRetry(t *testing.T) {
settler: &fakeSBRenewLockSettler{
// set delay to be greater than interval to check for lockTimeout
Delay: time.Duration(100) * time.Millisecond,
Err: context.Canceled,
Err: context.DeadlineExceeded,
},
msgLockedDuration: 0,
renewTimeout: to.Ptr(60 * time.Millisecond),
Expand All @@ -479,16 +479,16 @@ func Test_RenewRetry(t *testing.T) {
},
},
{
name: "should continue retry if error is context Canceled",
name: "should continue retry if error is context deadline exceeded",
settler: &fakeSBRenewLockSettler{
// set delay to be greater than interval to check for lockTimeout
Delay: time.Duration(100) * time.Millisecond,
Err: context.Canceled,
Err: context.DeadlineExceeded,
},
msgLockedDuration: 1 * time.Minute,
renewTimeout: to.Ptr(60 * time.Millisecond),
verify: func(g Gomega, tc *testCase, metrics *processor.Informer) {
// renewal times out every 60ms with context.Canceled error
// renewal times out every 60ms with context.DeadlineExceeded error
// retry should continue until the downstream handler completes at 180ms
g.Eventually(
func(g Gomega) { g.Expect(tc.settler.RenewCalled.Load()).To(Equal(int32(3))) },
Expand All @@ -504,7 +504,7 @@ func Test_RenewRetry(t *testing.T) {
settler: &fakeSBRenewLockSettler{
// set delay to be greater than interval to check for lockTimeout
Delay: time.Duration(100) * time.Millisecond,
Err: context.Canceled,
Err: context.DeadlineExceeded,
},
msgLockedDuration: 1 * time.Minute,
renewTimeout: to.Ptr(50 * time.Millisecond),
Expand All @@ -526,7 +526,7 @@ func Test_RenewRetry(t *testing.T) {
settler: &fakeSBRenewLockSettler{
// set delay to be greater than interval to check for lockTimeout
Delay: time.Duration(100) * time.Millisecond,
Err: context.Canceled,
Err: context.DeadlineExceeded,
},
msgLockedDuration: 130 * time.Millisecond,
renewTimeout: to.Ptr(50 * time.Millisecond),
Expand Down Expand Up @@ -577,9 +577,9 @@ func Test_RenewRetry(t *testing.T) {
},
},
{
name: "should not retry if renew fails due to context timeout exceeded",
name: "should not retry if renew fails due to context canceled",
settler: &fakeSBRenewLockSettler{
Err: context.DeadlineExceeded,
Err: context.Canceled,
},
msgLockedDuration: 1 * time.Minute,
renewTimeout: to.Ptr(100 * time.Millisecond),
Expand Down

0 comments on commit 0afa328

Please sign in to comment.