Skip to content

feat: use rspec retry to deflake ci#6285

Merged
elasticspoon merged 6 commits intomainfrom
deflake-with-retries
Mar 31, 2025
Merged

feat: use rspec retry to deflake ci#6285
elasticspoon merged 6 commits intomainfrom
deflake-with-retries

Conversation

@elasticspoon
Copy link
Copy Markdown
Collaborator

@elasticspoon elasticspoon commented Mar 30, 2025

Adds rspec-retry to compensate for some flakiness by retrying failures.

The basic issue in common with the failures is a pattern like:

  • perform action on page
  • assert some database state

The issue is that the tests are often faster than the server, thus, the check it the action worked happens before the action finished. Ex:

  • click submit to create case contact
  • controller gets the request and starts working
  • check that count of contacts went up => fails controller not done yet
  • controller finishes

Thus, we can use capybara waits to fix this. Basically we want to check that the front end shows the action finished (we see an alert) then check the database state.

  • perform action on page
  • check for front end flash message (capybara will wait on these)
  • assert some database state

@github-actions github-actions bot added dependencies Pull requests that update a dependency file ruby Pull requests that update Ruby code labels Mar 30, 2025
This is a bandaid fix that does not address the root cause.
@elasticspoon elasticspoon force-pushed the deflake-with-retries branch from 94c145b to fb55e24 Compare March 30, 2025 22:23
@github-actions github-actions bot added javascript for use by Github Labeler to mark pull requests that update Javascript code Tests! 🎉💖👏 labels Mar 30, 2025
@elasticspoon elasticspoon force-pushed the deflake-with-retries branch from fb55e24 to c2a68f5 Compare March 30, 2025 22:39
@elasticspoon elasticspoon force-pushed the deflake-with-retries branch 2 times, most recently from 2e7e930 to cbab1ac Compare March 31, 2025 01:31
@elasticspoon elasticspoon force-pushed the deflake-with-retries branch from cbab1ac to 0445b8d Compare March 31, 2025 01:42
Comment on lines +58 to +61
within ".ts-dropdown-content" do
expect(page).not_to have_css("input.form-check-input--unchecked")
expect(page).to have_css("input.form-check-input--checked", count: 3)
end
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is an ugly fix but the issue with the initial code is that when you run checked? on the nodes rspec won't use any capybara waiting. It checks right at the moment and either passes or fails.

Thus, if the test runs that check before the javascript on the page runs the test will fail. When we use have_ selectors we can avoid this issue.

I would like to have done something more like `have_checked("id_of_input") but tomselect does not give us something like that. instead I added a css class for checked and unchecked inputs in tomselect and assert against that.

@elasticspoon elasticspoon marked this pull request as ready for review March 31, 2025 01:55
@elasticspoon elasticspoon merged commit 582073f into main Mar 31, 2025
13 checks passed
@elasticspoon elasticspoon deleted the deflake-with-retries branch March 31, 2025 01:57
@compwron
Copy link
Copy Markdown
Collaborator

:)

group :test do
gem "brakeman" # security inspection
gem "capybara"
gem "rspec-retry" # for retrying flaky tests
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

https://rubygems.org/gems/rspec-retry seems reasonable, last update 2019 but simple

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file javascript for use by Github Labeler to mark pull requests that update Javascript code ruby Pull requests that update Ruby code Tests! 🎉💖👏

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants