Skip to content

Fix flaky spec for mobile version of the search form#11558

Merged
andreslucena merged 1 commit intodevelopfrom
test/fix-flaky-mobile-search
Sep 12, 2023
Merged

Fix flaky spec for mobile version of the search form#11558
andreslucena merged 1 commit intodevelopfrom
test/fix-flaky-mobile-search

Conversation

@andreslucena
Copy link
Copy Markdown
Member

🎩 What? Why?

This past week I saw a couple of times a flaky spec related to the mobile search.

See example in CI. As this will expire in a couple days, here's the relevant output:

Failures:

  1. Search when the device is a mobile shows the mobile version of the search form
    Failure/Error: click_button(id: "dropdown-trigger-links-mobile-search")

    Selenium::WebDriver::Error::ElementClickInterceptedError:
    element click intercepted: Element ... is not clickable at point (144, 630). Other element would receive the click: ...
    (Session info: headless chrome=116.0.5845.96)

Failed examples:

rspec ./spec/system/search_spec.rb:43 # Search when the device is a mobile shows the mobile version of the search form

And this is what the screenshot is giving us:

failures_r_spec_example_groups_search_when_the_device_is_a_mobile_shows_the_mobile_version_of_the_search_form_844

Seeing the relevant lines of the spec itself:

click_button(id: "dc-dialog-accept")
click_button(id: "dropdown-trigger-links-mobile-search")

My hypothesis on what's happening is the following:

  1. The page is loading
  2. Sometimes the browser is slow and the animation for the cookie banner takes a bit more than usual
  3. Due to the animation, Capybara clicks wrongly on the "Settings" button instead of "Accept all", so instead of closing the cookie banner it opens the the modal.

Testing

As this is a flaky, it's difficult to test. I found two strategies for now. In both strategies you should check the failure first in develop and then you should apply this PR and run it again to see that it doesn't fail anymore.

Slow strategy

In a bash shell:

for i in $(seq 1 500); do bin/rspec decidim-core/spec/system/search_spec.rb   || break; done

Fast strategy

I'm still working on refining a bit this one, but it's using the same sequential approach with also a parallel one 🚀.

Steps to follow:

  1. With a working parallel_tests set-up, so:
cd spec/decidim_dummy_app/
bundle exec rake parallel:create
bundle exec rake parallel:prepare
cd -
  1. Apply the following patch
diff --git a/decidim-core/spec/system/search_spec.rb b/decidim-core/spec/system/search_spec.rb
index abde92a5ba..ec587f8562 100644
--- a/decidim-core/spec/system/search_spec.rb
+++ b/decidim-core/spec/system/search_spec.rb
@@ -40,8 +40,10 @@ describe "Search", type: :system do
       click_button(id: "dropdown-trigger-links-mobile-search")
     end
 
-    it "shows the mobile version of the search form" do
-      expect(page).to have_css("#input-search-mobile")
+    1000.times do
+      it "shows the mobile version of the search form" do
+        expect(page).to have_css("#input-search-mobile")
+      end
     end
   end
 end
  1. Run the spec with parallel_spec. It's important to do it with the --exec option, as if we don't do it like this it will try to run it in 1 process.
cd decidim-core
RAILS_ENV=test bundle exec parallel_test --exec "bundle exec rspec spec/system/search_spec.rb"

What I could not find the way (for now) is to stop in a failing spec, so you need to check out the output to see if there's a FAILED spec manually 😞

♥️ Thank you!

@andreslucena andreslucena added flaky spec type: internal PRs that aren't necessary to add to the CHANGELOG for implementers labels Sep 1, 2023
@alecslupu alecslupu self-assigned this Sep 5, 2023
@alecslupu alecslupu requested a review from a team September 8, 2023 20:06
Copy link
Copy Markdown
Contributor

@alecslupu alecslupu left a comment

Choose a reason for hiding this comment

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

LGTM.

By looking at the changed code, i can see that we reduce the animation from 500 to 50 ms.
I have tried to replicate (make it fail with the advertised error on develop) it on my local, but i was not able.

@andreslucena please feel free to merge it.

@alecslupu alecslupu added this to the 0.28.0 milestone Sep 8, 2023
@andreslucena
Copy link
Copy Markdown
Member Author

I have tried to replicate (make it fail with the advertised error on develop) it on my local, but i was not able.

At least with the parallel_spec approach I could reproduce it pretty fast (in less than 2 minutes). I'll try to clean-up this approach in the next flaky that I find.

@andreslucena andreslucena merged commit 1404881 into develop Sep 12, 2023
@andreslucena andreslucena deleted the test/fix-flaky-mobile-search branch September 12, 2023 09:22
entantoencuanto added a commit that referenced this pull request Sep 12, 2023
* develop:
  Enable identical and similar code statements in CodeClimate configuration (#10383)
  Fix flaky spec for mobile version of the search form (#11558)
  Remove duplication for ParticipatorySpace User examples (#11578)
  Add title in arrows while navigating meetings (#11574)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flaky spec type: internal PRs that aren't necessary to add to the CHANGELOG for implementers

Projects

No open projects
Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants