[retry] implement waitFor method#21747
Merged
spalger merged 3 commits intoelastic:masterfrom Aug 14, 2018
Merged
Conversation
Contributor
💚 Build Succeeded |
|
Would retry.waitFor work with expect statements? We don't |
Contributor
Author
|
retry.try(async () => {
// ...
expect(someBoolean).to.be(true)
})with retry.waitFor('some boolean', async () => {
// ...
return someBoolean
})Retry's that are checking other things might be converted like so: retry.waitFor('all visualizations to render', async () => {
const renderedCount = await PageObjects.dashboard.countRenderedVisualizations();
return renderedCount === expectedAmount
})using |
Contributor
Author
|
You can see an example implementation that's actually improving the stability of the tests in #21629 here: https://github.com/elastic/kibana/blob/7cb23e9d1dd4aeba3c6869b3b6ddbd93e58c74c6/test/functional/page_objects/dashboard_page.js#L179-L181 |
LeeDr
approved these changes
Aug 14, 2018
LeeDr
left a comment
There was a problem hiding this comment.
LGTM - code reviewed only. Passing in Jenkins.
spalger
pushed a commit
to spalger/kibana
that referenced
this pull request
Aug 14, 2018
We currently use the `retry` service to call a function over and over in a loop, waiting for it to run without throwing an error, and ultimately failing if it does not succeed before a timeout is exceeded. This is the easiest way to get certain interactions to work, either because we don't know when we should be able to execute the interaction successfully, or because the timing is just too tricky to plan out correctly. Another place where we are using the `retry` service, which I don't think is appropriate, is when we need to wait for a certain condition to be met. This is where `retry.waitFor()` comes in:
```js
await retry.waitFor('dashboard search to be enabled', async () => {
const searchInput = await testSubjects.find('savedObjectFinderSearchInput');
return await searchInput.isEnabled();
})
```
The `retry.waitFor()` method behaves much like the `retry.try()` method behind the scenes, calling a function over and over, but instead of waiting for it to run without throwing an error it waits for it to return a "truthy" value. It also requires a description string that is used to make rather nice log output and a more descriptive error message than something like https://github.com/elastic/kibana/blob/master/test/functional/apps/dashboard/_data_shared_attributes.js#L61-L67
This was referenced Aug 14, 2018
spalger
pushed a commit
to spalger/kibana
that referenced
this pull request
Aug 14, 2018
We currently use the `retry` service to call a function over and over in a loop, waiting for it to run without throwing an error, and ultimately failing if it does not succeed before a timeout is exceeded. This is the easiest way to get certain interactions to work, either because we don't know when we should be able to execute the interaction successfully, or because the timing is just too tricky to plan out correctly. Another place where we are using the `retry` service, which I don't think is appropriate, is when we need to wait for a certain condition to be met. This is where `retry.waitFor()` comes in:
```js
await retry.waitFor('dashboard search to be enabled', async () => {
const searchInput = await testSubjects.find('savedObjectFinderSearchInput');
return await searchInput.isEnabled();
})
```
The `retry.waitFor()` method behaves much like the `retry.try()` method behind the scenes, calling a function over and over, but instead of waiting for it to run without throwing an error it waits for it to return a "truthy" value. It also requires a description string that is used to make rather nice log output and a more descriptive error message than something like https://github.com/elastic/kibana/blob/master/test/functional/apps/dashboard/_data_shared_attributes.js#L61-L67
spalger
pushed a commit
that referenced
this pull request
Aug 14, 2018
spalger
pushed a commit
that referenced
this pull request
Aug 14, 2018
Contributor
Author
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.
We currently use the
retryservice to call a function over and over in a loop, waiting for it to run without throwing an error, and ultimately failing if it does not succeed before a timeout is exceeded. This is the easiest way to get certain interactions to work, either because we don't know when we should be able to execute the interaction successfully, or because the timing is just too tricky to plan out correctly. Another place where we are using theretryservice, which I don't think is appropriate, is when we need to wait for a certain condition to be met. This is whereretry.waitFor()comes in:The
retry.waitFor()method behaves much like theretry.try()method behind the scenes, calling a function over and over, but instead of waiting for it to run without throwing an error it waits for it to return a "truthy" value. It also requires a description string that is used to make rather nice log output and a more descriptive error message than something like https://github.com/elastic/kibana/blob/master/test/functional/apps/dashboard/_data_shared_attributes.js#L61-L67