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

correctly set test adapter when configure the queue adapter on a per job #26690

Merged
merged 2 commits into from
Jan 31, 2017

Conversation

y-yagi
Copy link
Member

@y-yagi y-yagi commented Oct 3, 2016

Summary

The ActiveJob::TestHelper replace the adapter to test adapter in before_setup.
It gets the target class using the descendants, but if the test target job
class is not loaded, will not be a replacement of the adapter.
To avoid this, modified to load the test target class.

Fixes #26360

@rails-bot
Copy link

r? @arthurnn

(@rails-bot has picked a reviewer for you, use r? to override)

@@ -10,6 +10,7 @@ module TestHelper

def before_setup # :nodoc:
test_adapter = queue_adapter_for_test
self.class.to_s.gsub(/Test\z/, "").safe_constantize
Copy link
Member

Choose a reason for hiding this comment

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

This line is confusing, as we constantize something, and don't assign it to any variable.
Would be nice to add a comment in it, to make it more clear.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd write this as self.class.name.chomp('Test').safe_constantize.

What happens if users call tests SomethingUnconventional?
I found the original issue tough to grasp, but is this the best way we can find to solve the issue?

Copy link
Member Author

Choose a reason for hiding this comment

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

What happens if users call tests SomethingUnconventional?

ActiveJob::TestCase does not have tests method. So, calling tests will an error.

but is this the best way we can find to solve the issue?

I think your concern is correct. I think again about the solution.

Copy link
Contributor

Choose a reason for hiding this comment

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

ActiveJob::TestCase does not have tests method

People could include ActiveJob::TestHelper into an ActiveSupport::TestCase class and then it'd be there, iirc.

I think your concern is correct. I think again about the solution.

❤️

The `ActiveJob::TestHelper` replace the adapter to test adapter in
`before_setup`. It gets the target class using the `descendants`, but if
the test target job class is not loaded, will not be a replacement of
the adapter.
Therefore, instead of replacing with `before_setup`, modified to
replace when setting adapter.

Fixes rails#26360
@y-yagi y-yagi force-pushed the load_job_class_before_run_test branch from 2e487db to e94aee7 Compare January 27, 2017 04:11
@y-yagi y-yagi changed the title load the test target job class before run tests correctly set test adapter when configure the queue adapter on a per job Jan 27, 2017
@y-yagi
Copy link
Member Author

y-yagi commented Jan 27, 2017

I changed the solution.
When acquiring test adapter, it modified to return it if test adapter is set.

@arthurnn
Copy link
Member

@kaspth thoughts?

Copy link
Member

@rafaelfranca rafaelfranca left a comment

Choose a reason for hiding this comment

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

@arthurnn arthurnn merged commit 80dc309 into rails:master Jan 31, 2017
@rafaelfranca
Copy link
Member

Just avoid to use the conflict fix button on github because it creates an extra commit 😢

@arthurnn
Copy link
Member

Just avoid to use the conflict fix button on github because it creates an extra commit 😢

I rebased/squash in the end =)

@y-yagi y-yagi deleted the load_job_class_before_run_test branch January 31, 2017 23:08
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

6 participants