Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add WithTimeout() and TryUntil() config options #6

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

Conversation

moskyb
Copy link
Collaborator

@moskyb moskyb commented Nov 30, 2022

This PR: Adds functionality to make roko retry against a timeout, as well as a max attempt count. Note that this is independent of using a context with a timeout and retrier.DoWithContext(), which will also work fine. This PR just exposes similar features through a more fluent API.

We expose this through the WithTimeout(time.Duration) and Until(time.Time) config functions.

Still to do:

  • Maybe Until() should be called TryUntil() for symmetry with TryForever()?
  • I'm not operating at full capacity, but testing seems like it might be a bit annoying with this feature - we can't use the WithSleepFunc stuff that we've been using in other tests, as the timer that timeouts run on are out fo band from the normal sleep process. Would love to hear some ideas on how to test this functionality nicely
  • Update the Readme with examples, add docstrings to the config methods

@moskyb moskyb requested a review from a team November 30, 2022 09:40
@@ -112,6 +112,23 @@ func TestShouldGiveUp_WithMaxAttempts(t *testing.T) {
assert.Equal(t, 3, callcount)
}

func TestTimeout(t *testing.T) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this test super doesn't work, because the timeout function measures time inside the callback as well as time outside the callback (ie time spent waiting). The call count flakes between 92 and 93 before the timeout completes

@@ -275,6 +314,8 @@ func (r *Retrier) sleepOrDone(ctx context.Context, nextInterval time.Duration) e
close(sleepCh)
}()
select {
case <-timeouter.C:
return fmt.Errorf("retrier timed out after %v", r.timeout)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

possibly this should be a public error value so that people can test for errors.Is(err, roko.TimeoutExceeded) or something

@moskyb moskyb changed the title Add WithTimeout() and Until() config options Add WithTimeout() and TryUntil() config options Nov 30, 2022
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.

1 participant