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

Allow to determine the duration before retry according the retry number #772

Merged
merged 2 commits into from Sep 22, 2019

Conversation

cchantep
Copy link
Contributor

Usage:

eventually(retries = 3, _ * 100.milliseconds) {
  ???
}

foo must beTrue.eventually(3, _ * 75.milliseconds + 1.second)

Copy link
Owner

@etorreborre etorreborre left a comment

Choose a reason for hiding this comment

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

That's a nice feature! I think we can implement some methods in terms of others but it's otherwise all good. If you can do those 2 changes I'll merge next. Do you need a release soon?

/** @return a result that is retried at least 40 times until it's ok */
def eventually[T : AsResult](result: =>T): T =
eventually(40, 100.millis)(result)
eventually(40, (_: Int) => 100.millis)(result)
Copy link
Owner

Choose a reason for hiding this comment

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

You should be able to write eventually(40, 100.millis)(result) here, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, just prefer to directly call the more primitive variant

Copy link
Owner

Choose a reason for hiding this comment

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

Ok, that's fine. On the other hand most of the tests are not passing. Could you please investigate why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

if (retries <= 1) {
r
def eventually[T : AsResult](retries: Int, sleep: Int => Duration)(result: =>T): T = {
@annotation.tailrec def retry(retried: Int): T = {
Copy link
Owner

Choose a reason for hiding this comment

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

Good naming change 👍


/** @return a matcher that will retry the nested matcher 40 times */
def eventually[T](nested: =>Matcher[T]): Matcher[T] = eventually(nested, 40, 100.millis)
def eventually[T](nested: =>Matcher[T]): Matcher[T] = eventually(nested, 40, (_: Int) => 100.millis)
Copy link
Owner

Choose a reason for hiding this comment

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

Here you should also be able to call eventually(nested, 40, 100.millis) directly

@etorreborre etorreborre merged commit 46bdd56 into etorreborre:master Sep 22, 2019
@etorreborre
Copy link
Owner

All tests passing indeed, thanks!

@cchantep
Copy link
Contributor Author

Thx @etorreborre for the quick review

@cchantep cchantep deleted the feature/variable-retry-sleep branch September 22, 2019 17:06
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.

None yet

2 participants