Conversation
- Add extensive tests to verify retry delay logging, callback accuracy, Retry-After header handling, and tracing delay correctness - Refactor retry delay calculation logic into separate helper methods - Improve separation of delay computation, delay modifiers, and retry callback invocation - Update tests to assert precise expected delay values for retries - Make retry delays predictable by disabling jitter in unit tests ref: #11 (comment) Signed-off-by: appleboy <appleboy.tw@gmail.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the retry delay calculation logic to improve code organization, testability, and observability accuracy. The changes separate delay computation from delay application, making it easier to verify that logged delays, callback parameters, and tracing events contain the correct values.
Changes:
- Refactored retry delay logic into helper functions
computeNextDelayandapplyDelayModifiersfor better separation of concerns - Restructured the retry loop into 4 clear phases (wait, execute, check, calculate next delay) for improved clarity
- Added comprehensive tests to verify delay accuracy in logging, callbacks, Retry-After handling, and tracing
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| retry.go | Refactored retry delay calculation into helper functions and restructured DoWithContext into 4 clear phases |
| retry_test.go | Updated TestWithOnRetry to verify specific delay values and add WithRetryDelayMultiple configuration |
| delay_accuracy_test.go | Added 4 new comprehensive tests verifying delay accuracy in logs, callbacks, Retry-After headers, and tracing |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ref: #11 (comment)