Skip to content

test: refactor and test retry delay logic for improved accuracy#14

Merged
appleboy merged 1 commit intomainfrom
retry
Feb 15, 2026
Merged

test: refactor and test retry delay logic for improved accuracy#14
appleboy merged 1 commit intomainfrom
retry

Conversation

@appleboy
Copy link
Owner

  • 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)

- 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>
Copilot AI review requested due to automatic review settings February 15, 2026 05:27
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 computeNextDelay and applyDelayModifiers for 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.

@appleboy appleboy merged commit 37dae4c into main Feb 15, 2026
26 checks passed
@appleboy appleboy deleted the retry branch February 15, 2026 05:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants