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

Fix flaky spec: Proposals Voting Voting proposals on behalf of someone in show view #2697

Conversation

javierv
Copy link
Contributor

@javierv javierv commented Jun 23, 2018

References

Objectives

Fix the flaky that appeared in spec/features/management/proposals_spec.rb:164: "Proposals Voting Voting proposals on behalf of someone in show view".

Explain why the test is flaky, or under which conditions/scenario it fails randomly

It's hard to reproduce and be sure about what was going on, so here is my best guess. Given the code:

within(".proposals-list") { click_link proposal.title }
within("#proposal_#{proposal.id}_votes") { click_link('Support') }

The first clicked link generates an AJAX request. Usually, Capybara would wait for the AJAX request to generate a "Support" link in the element #proposal_XX_votes. However, there's already a #proposal_XX_votes element with a "Support" link on the proposals index page!

Support link inspection in the browser

So Capybara doesn't have to wait for the AJAX request to finish before clicking the "Support" link. From then on, anything can happen.

As stated on issue #2558, on my machine the best chance to reproduce the failure was running bundle exec rspec spec/features/management/proposals_spec.rb --seed 8625 (fails about 20% of the time).

Explain why your PR fixes it

By checking the proposal code is present, which is present on the proposals show page but not on the proposals index page, we ensure we've left the proposals index page when we click the "Support" link.

Notes

  • In the commit message there's a mention to two possible implementations. One of them depends on the proposal code being present while the other one depends on a CSS selector being present. I'm not sure which one is better.

@javierv javierv changed the title Fix flaky spec in proposals #2558 Fix flaky spec in proposals Jun 24, 2018
There was a flaky spec supporting proposals. It's hard to reproduce and
be sure about what was going on, so here is my best guess. Given the
code:

```
within(".proposals-list") { click_link proposal.title }
within("#proposal_#{proposal.id}_votes") { click_link('Support') }
```

The first clicked link generates an AJAX request. Usually, Capybara
would wait for the AJAX request to generate a "Support" link in the
element `#proposal_XX_votes`. However, there's already a
`#proposal_XX_votes` element with a "Support" link on the proposals
index page!

So Capybara doesn't have to wait for the AJAX request to finish before
clicking the "Support" link. From then on, anything can happen.

Another option that works:

```
within(".proposals-list") { click_link proposal.title }
within(".proposal-show #proposal_#{proposal.id}_votes") { click_link('Support') }
```

With this code, the link selector fails on the proposals index page, and
Capybara waits for the AJAX request to finish.

Related to issue consuldemocracy#2558.
@javierv javierv force-pushed the 2558-fix_flay_spec_supporting_proposals branch from 2c6ac70 to b1996e5 Compare July 3, 2018 22:01
@javierv javierv changed the title Fix flaky spec in proposals Fix flaky spec: Proposals Voting Voting proposals on behalf of someone in show view Jul 6, 2018
Copy link
Member

@voodoorai2000 voodoorai2000 left a comment

Choose a reason for hiding this comment

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

👌

@voodoorai2000 voodoorai2000 merged commit 06689d9 into consuldemocracy:master Jul 12, 2018
@javierv javierv deleted the 2558-fix_flay_spec_supporting_proposals branch July 12, 2018 15:09
@javierm javierm self-assigned this Nov 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants