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

Tentative fix for flaky specs #3141

Merged
merged 5 commits into from
Mar 27, 2019

Conversation

kennyadsl
Copy link
Member

@kennyadsl kennyadsl commented Mar 13, 2019

Description

This PR is an attempt to fix flaky specs:

For more info it's better to take a look at individual commits.

Checklist:

@kennyadsl kennyadsl self-assigned this Mar 13, 2019
@kennyadsl
Copy link
Member Author

This is passing, I rerun this workflow several times and it is always green (first failure is due to a force push, not a real failure). I think we can try to merge this.

@kennyadsl kennyadsl marked this pull request as ready for review March 14, 2019 16:51
Copy link
Contributor

@aitbw aitbw left a comment

Choose a reason for hiding this comment

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

Ran the spec several times locally with no failures whatsoever, 🙏

@kennyadsl
Copy link
Member Author

It failed again on the CI :(

https://circleci.com/gh/nebulab/solidus/1625#tests/containers/1

@kennyadsl
Copy link
Member Author

By looking at the last failure on CircleCI it's evident what happens:

The page fails in this state (at least when the screenshot is taken):

img

and the failure says:

Failure/Error: expect(page).to have_css(".select2-search-choice", text: taxon.name)
  expected to find visible css ".select2-search-choice" with text "Clothing" but there were no matches. Also found "Ruby on Rails", which matched the selector but not all filters. 

This is the failing code:

def select_select2_result(value)
# results are in a div appended to the end of the document
within_entire_page do
page.find("div.select2-result-label", text: /#{Regexp.escape(value)}/i, match: :prefer_exact).click
end
end

page.find should wait for 10 (Capybara.default_max_wait_time) seconds, so I don't think it's an issue related to the page waiting for div to be populated correctly. Also, if Clothing were not found and clicked in the results div, Capybara would raise an exception. So for some reason, that result is found, clicked but it's not doing anything. I'll put some more debugging code, so it will be more clear what's happening.

@kennyadsl kennyadsl force-pushed the kennyadsl/fix-flacky-specs branch from 55618c9 to e49cde5 Compare March 20, 2019 15:37
Copy link
Contributor

@jacobherrington jacobherrington left a comment

Choose a reason for hiding this comment

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

👍 This works for now.

By checking that select2 has correctly been updated before
submitting the form, we ensure that we are passing the right
data to the server.

I also update the portion of the page where we look for the flash
message so it will check for it after the element will be visible
on the page (it is displayed after page load with js).
It looks like sometimes active is not recognized as a real
method of Spree::StockLocation::ActiveRecord_Relation.

Here's an example of the flaky spec failing:

https://circleci.com/gh/nebulab/solidus/1701
@kennyadsl kennyadsl force-pushed the kennyadsl/fix-flacky-specs branch from e49cde5 to 967e2f5 Compare March 26, 2019 13:07
Copy link
Member

@tvdeyen tvdeyen left a comment

Choose a reason for hiding this comment

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

👍 for the select2 fixes. This library causes so many troubles. We really should think about removing it sooner or later.

The second spec should be rewritten IMO


without_partial_double_verification do
expect(stock_locations).to receive(:active) { active_stock_locations }
end
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I am not a huge fan of these kind of specs. Could we rewrite the spec into something that actually test the result instead of stubbing the implementation?

Create two stock locations, one active, one not. Expect the active one is the result.

@jacobherrington
Copy link
Contributor

jacobherrington commented Mar 26, 2019

+1 for getting rid of select2. Something I'd love to tackle if I had the time.

@tvdeyen
Copy link
Member

tvdeyen commented Mar 26, 2019

+1 for getting rid of select2. Something I'd love to tackle if I had the time.

@jacobherrington Awesome! keep in mind, though, that we already only using select2 for multiple selects and autocomplete. Normal selects are already browser selects. John looked into an alternative, but didn’t finished his work.

In order to avoid stubbing the implementation. This could have benefits
in terms of speed but everything is more complex to read and
it's causing flaky specs in combination with verifying partial doubles.
This is not releated with this PR but I think we should change
this code here to discourage adopting a practice that we don't
want to see into other specs.
@kennyadsl
Copy link
Member Author

@tvdeyen I've done the suggested changes to specs. I also changed Stock Location Sorter specs that I wrongly used as a reference when writing these ones.

@kennyadsl
Copy link
Member Author

Aaaaand... there's another flaky: https://circleci.com/gh/nebulab/solidus/1726#tests/containers/2

@tvdeyen
Copy link
Member

tvdeyen commented Mar 27, 2019

These feature specs are all written very poorly. One does not expect database changes in a feature spec. One expects changes in the request outcome (html). This particular one should be easily fixed by waiting for a string present on the screen before making that assertion about a change in the database (that happen in another thread and therefore can’t be predictable)

@kennyadsl kennyadsl force-pushed the kennyadsl/fix-flacky-specs branch from fc8e82f to b5529d3 Compare March 27, 2019 10:29
They rely on the database to be filled to check things
happened correctly. This is a bad practice and we can easily check
the same thing by checking the output of the page.

This should fix this flaky spec: https://circleci.com/gh/nebulab/solidus/1726#tests/containers/2
@kennyadsl kennyadsl force-pushed the kennyadsl/fix-flacky-specs branch from b5529d3 to b7b918a Compare March 27, 2019 10:30
@kennyadsl kennyadsl requested a review from tvdeyen March 27, 2019 10:53
Copy link
Member

@tvdeyen tvdeyen left a comment

Choose a reason for hiding this comment

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

Awesome. Thank you!

@kennyadsl kennyadsl merged commit 767c238 into solidusio:master Mar 27, 2019
@kennyadsl kennyadsl deleted the kennyadsl/fix-flacky-specs branch March 27, 2019 10:57
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.

4 participants