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

Make perform_enqueued_jobs compatible with all Active Job adapters #48599

Conversation

ghiculescu
Copy link
Member

@ghiculescu ghiculescu commented Jun 28, 2023

Motivation / Background

#37270 describes a common Active Job issue where if you try to set an adapter other than :test as your adapter in a test environment, you get some confusing results.

The most popular workaround on the issue is to add this to a setup block:

(ActiveJob::Base.descendants << ActiveJob::Base).each(&:disable_test_adapter)

This solves some issues, but causes others. bensheldon/good_job#846 is an example of an issue it causes. If you call assert_emails in an integration test, it will crash here because only the test adapter defines perform_enqueued_jobs.

I think we should fix the issue of Active Job adapters being inconsistent across tests fully, and #48585 is my work in progress for that. But I wanted to extract this fix from that PR since I think it's useful in isolation.

Detail

With this PR, perform_enqueued_jobs will yield if a block is given but the test adapter is not being used. This is the minimum required to make that method compatible with any adapter.

Additional information

ref: bensheldon/good_job#846, #37270

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one change. Changes that are unrelated should be opened in separate PRs.
  • Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: [Fix #issue-number]
  • Tests are added or updated if you fix a bug or add a feature.
  • CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included.

@ghiculescu ghiculescu force-pushed the perform_enqueued_jobs-with-different-adapter branch from c7be4a8 to ba70a5b Compare June 28, 2023 10:08
@rafaelfranca rafaelfranca merged commit 5b2523e into rails:main Jun 28, 2023
9 checks passed
@ghiculescu ghiculescu deleted the perform_enqueued_jobs-with-different-adapter branch June 28, 2023 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants