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

Change to CurrentAttributes leads to broken ActiveJob testing #335

Open
tmaier opened this issue Feb 13, 2024 · 0 comments
Open

Change to CurrentAttributes leads to broken ActiveJob testing #335

tmaier opened this issue Feb 13, 2024 · 0 comments

Comments

@tmaier
Copy link
Contributor

tmaier commented Feb 13, 2024

I have ActsAsTenant version 1.0.1 running in my Rails 7.0 application.

I just wanted to switch from Sidekiq to GoodJob.
For this, I also changed all my jobs from Sidekiq Workers to ActiveJob jobs.

I realized that some tests started to fail in an odd way.
Specifically, current_tenant was suddenly not set anymore.

I suspect there are multiple issues going on

One has been mentioned in #328. I think ActsAsTenant.with_tenant should be used here

The new issue I want to report here is that ActiveJob and ActiveSupport::CurrentAttributes have undesired side effects.

I learned at https://github.com/bensheldon/good_job/blob/ab5129030067f1c97253d90b3d1ef96da25ff733/lib/good_job/current_thread.rb#L8 the following:

module GoodJob
  # Thread-local attributes for passing values from Instrumentation.
  # (Cannot use ActiveSupport::CurrentAttributes because ActiveJob resets it)
  module CurrentThread
    # ...

This pointed me to the following issue at rails: rails/rails#49227
It confirms that "CurrentAttributes are cleared when a job gets executed inline in test".

This means inline tests of ActiveJobs are broken.
Side effects on other gems, like GoodJob have yet to be determined. I am checking this now...

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

No branches or pull requests

1 participant