-
Notifications
You must be signed in to change notification settings - Fork 19
Flaky Tests
Craig Reese edited this page Dec 26, 2023
·
5 revisions
- A flaky test is one that intermittently fails in the CI test runs (GitHub Actions), or fails in the CI tests runs but passes locally
- Check if the test passes locally. This may require running the test multiple times to see if it always fails or only sometimes fails.
- Only using the "re-run failed jobs" button in Github Actions is not always enough. Sometimes tests fail only in the CI environment, so testing them locally is a must.
- If the test passes locally, check the Jira flaky test epic to see if the test or test file is documented as flaky
- In short, yes. We should all be making an attempt to identify what the root cause of the flaky test is. However, if you spend some time looking at the test and are unable to identify why it may be flaky, follow the steps in the sections below to skip the test in the suite and inform a TL or dev who has expertise in that area.
- See the best practices section in the Backend Pattern Test wiki entry for recommendations and advice. In general:
- Minimize writing to the database:
- Use
let
instead oflet!
wherever possible;let!
instantiates the variable any time it enters the scope of the test whether it is used or not, whilelet
only instantiates a variable if it is called
- Use
- For feature specs, consolidate checks into a single test and use
:aggregate_failures
to reduce the number of DB writes and HTTP requests that need to be made - For feature specs, use Capybara matchers instead of Rspec matchers wherever possible. Capybara matchers are set up to wait until elements appear on a page, Rspec matchers are not
- Do not rely on data being created in or fetched from the database in the order that it was written to be created in a test. If you are checking one object in a set of three that are created, don't use
{model}.first
unless you have sorted the array by some other value and know that it will always come back from the database in that order. - If you have a failing test that visits the Case Details page, check to see if it is failing to load the case (the "Unable to load this case" page appearing). If it is, the following line can be added before the
visit
call:page.find("a", text: "refresh the page").click if page.has_text?(COPY::CASE_DETAILS_LOADING_FAILURE_TITLE)
. This will click the "refresh the page" link on the error page, and is usually enough to properly load a Case Details page.
- Minimize writing to the database:
- If there is no open Jira story or task for the test, create a jira story under the flaky test epic detailing the file, test scenario, and reason (if known) that the test is flaky
- Use comments in the test to document what you have done to try and fix the test or information you've found
- Skip the test in the file using
skip: "some description here"
- Home
- Acronyms and Glossary
- Caseflow products
- Caseflow Intake
- Caseflow Queue
- Appeals Consumer
- Caseflow Reader
- Caseflow eFolder
- Caseflow Hearings
- Caseflow Certification
- Caseflow APIs
- Appeal Status API
- Caseflow Dispatch
-
CSUM Roles
- System Admin
- VHA Team Management
- Active Record Queries Resource
- External Integrations
- Caseflow Demo
- Caseflow ProdTest
- Background
- Stuck Jobs
- VA Notify
-
Caseflow-Team
- Tier 4
- Bat Team
- Technical Documentation
- Backend Code Patterns
- Backend Working Group
- FACOLS, VACOLS DB Schema
- Asyncable Models
- External Data: where and why
- Data Fetching Scripts
- Caseflow Data Model and Dictionary
- User Access Permissions
- Controller Schemas
- Constants
- Frontend Best Practices
- Accessibility
- How-To
- Debugging Tips
- Adding a Feature Flag with FeatureToggle
- Editing AMA issues
- Editing a decision review
- Fixing task trees
- Investigating and diagnosing issues
- Data and Metric Request Workflow
- Exporting and Importing Appeals
- Explain page for Appeals
- Record associations and Foreign Keys
- Upgrading Ruby
- Stuck Appeals
- Testing Action Mailer Messages Locally
- Re-running Seed Files
- Rake Generator for Legacy Appeals
- Manually running Scheduled Jobs
- System Admin UI
- Caseflow Makefile
- Upgrading Postgresql from v11.7 to v14.8 Locally
- VACOLS VM Trigger Fix M1
- Using SlackService to Send a Job Alert
- Technical Talks