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 rake tests by always loading Rake tasks once #439

Merged
merged 1 commit into from
Feb 7, 2025

Conversation

tdooner
Copy link
Contributor

@tdooner tdooner commented Feb 6, 2025

Ticket

No ticket - flaky tests.

Changes

  • Fix flaky rake tests by always loading Rake tasks once

Context for reviewers

If Rails.application.load_tasks is called multiple times, than any
invocation of a Rake task will actually happen multiple times. This is
problematic for non-idempotent Rake tasks (like
users:promote_to_service_account).

Let's prevent this issue by just loading the tasks in the
"rails_helper.rb" file so they're always available.

Acceptance testing

  • No acceptance testing needed
    • This change will not affect the user experience (bugfix, dependency updates, etc.)
  • Acceptance testing prior to merge
    • This change can be verified visually via screenshots attached below or by sending a link to a local development environment to the acceptance tester
    • Acceptance testing should be done by design for visual changes, product for behavior/logic changes, or both for changes that impact both.
  • Acceptance testing after merge
    • This change is hard to test locally, so we'll test it in the demo environment (deployed automatically after merge.)
    • Make sure to notify the team once this PR is merged so we don't inadvertently deploy the unaccepted change to production. (e.g. :alert: Deploy block! @ffs-eng I just merged PR [#123] and will be doing acceptance testing in demo - please don't deploy until I'm finished!)

If `Rails.application.load_tasks` is called multiple times, than any
invocation of a Rake task will actually happen multiple times. This is
problematic for non-idempotent Rake tasks (like
`users:promote_to_service_account`).

Let's prevent this issue by just loading the tasks in the
"rails_helper.rb" file so they're always available.
Copy link
Contributor

@allthesignals allthesignals left a comment

Choose a reason for hiding this comment

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

Amazing, thank you! Just tested by duplicating tests in my users spec file.

@tdooner tdooner merged commit 218cd58 into main Feb 7, 2025
14 checks passed
@tdooner tdooner deleted the td/fix-flaky-rake-tests branch February 7, 2025 00:00
tdooner added a commit that referenced this pull request Feb 7, 2025
…ow-use-new-database

* origin/main:
  Fix flaky rake tests by always loading Rake tasks once (#439)
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.

2 participants