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 ActiveJob tests for Rails 7.2 and 8.0 #2487

Merged

Conversation

olivier-thatch
Copy link
Contributor

@olivier-thatch olivier-thatch commented Dec 7, 2024

Description

This PR fixes the test suite so that the ActiveJob related tests pass with Rails 7.2 and 8.0.

While working on the ActiveJob integration, I noticed that one of the tests was failing with Rails 7.2 and 8.0, specifically this one:

context "when we are using an adapter which has a specific integration" do
before do
Sentry.configuration.rails.skippable_job_adapters = ["ActiveJob::QueueAdapters::TestAdapter"]
end
after do
Sentry.configuration.rails.skippable_job_adapters = []
end
it "does not trigger sentry and re-raises" do
expect { FailedJob.perform_now }.to raise_error(FailedJob::TestError)
expect(transport.events.size).to eq(0)
end
end

After investigating, I realized that with Rails >= 7.2, all the test jobs were using ActiveJob::QueueAdapters::AsyncAdapter as their queue adapter instead of ActiveJob::QueueAdapters::TestAdapter. This is likely because of this change that was introduced in Rails 7.2.

The fix is easy enough: we simply need to make sure ActiveJob::TestHelper is included before the test suite runs. After including the helper module, all test jobs correctly use ActiveJob::QueueAdapters::TestAdapter as their queue adapter.

What I don't understand is why this happens locally but not in CI 🤔

#skip-changelog

Copy link

codecov bot commented Dec 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.18%. Comparing base (7ad595a) to head (7e69e17).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2487   +/-   ##
=======================================
  Coverage   98.18%   98.18%           
=======================================
  Files         128      128           
  Lines        4845     4845           
=======================================
  Hits         4757     4757           
  Misses         88       88           
Components Coverage Δ
sentry-ruby 98.57% <ø> (ø)
sentry-rails 97.07% <ø> (ø)
sentry-sidekiq 97.09% <ø> (ø)
sentry-resque 92.85% <ø> (ø)
sentry-delayed_job 95.65% <ø> (ø)
sentry-opentelemetry 99.31% <ø> (ø)

Copy link
Collaborator

@solnic solnic left a comment

Choose a reason for hiding this comment

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

Thanks! Could you please rebase this on top of latest master before we merge it?

@olivier-thatch olivier-thatch force-pushed the olivier-fix-activejob-tests branch from 325b3c1 to 7e69e17 Compare January 2, 2025 17:14
@olivier-thatch
Copy link
Contributor Author

@solnic Done!

@olivier-thatch olivier-thatch requested a review from solnic January 2, 2025 17:16
@solnic
Copy link
Collaborator

solnic commented Jan 2, 2025

What I don't understand is why this happens locally but not in CI 🤔

@olivier-thatch on CI we run all the specs, and the spec fails locally only if you run it separately (at least for me). This means that there's some state that changes during whole spec suite run that causes this spec to pass, but it's different when we run it in isolation.

Copy link
Collaborator

@solnic solnic left a comment

Choose a reason for hiding this comment

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

Thanks, this indeed fixes the problem :)

@solnic solnic merged commit a9301f3 into getsentry:master Jan 2, 2025
147 checks passed
@olivier-thatch olivier-thatch deleted the olivier-fix-activejob-tests branch January 2, 2025 21:05
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