-
Notifications
You must be signed in to change notification settings - Fork 177
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!: Drop DelayedJob ActiveRecord in Tests #685
Changes from 1 commit
a3ff8ed
428a0a1
5141f8e
1a86951
b3bf814
038db9d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,8 +7,13 @@ | |
require 'bundler/setup' | ||
Bundler.require(:default, :development, :test) | ||
|
||
# These are dependencies that delayed job assumes are already loaded | ||
# We are compensating for that here in this test... that is a smell | ||
# NoMethodError: undefined method `extract_options!' for [#<ActiveJobPayload:0x0000000108bf5d48>, {}]:Array | ||
# delayed_job-4.1.11/lib/delayed/backend/job_preparer.rb:7:in `initialize'0 | ||
require 'active_support/core_ext/array' | ||
|
||
require 'opentelemetry-instrumentation-delayed_job' | ||
require 'active_support/core_ext/kernel/reporting' | ||
|
||
require 'minitest/autorun' | ||
require 'rspec/mocks/minitest_integration' | ||
|
@@ -24,31 +29,8 @@ | |
c.add_span_processor span_processor | ||
end | ||
|
||
ActiveRecord::Migration.verbose = false | ||
|
||
module TestHelper | ||
extend self | ||
|
||
def setup_active_record | ||
::ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:') | ||
::ActiveRecord::Schema.define do | ||
create_table 'delayed_jobs', force: :cascade do |t| | ||
t.integer 'priority', default: 0, null: false | ||
t.integer 'attempts', default: 0, null: false | ||
t.text 'handler', null: false | ||
t.text 'last_error' | ||
t.datetime 'run_at' | ||
t.datetime 'locked_at' | ||
t.datetime 'failed_at' | ||
t.string 'locked_by' | ||
t.string 'queue' | ||
t.datetime 'created_at' | ||
t.datetime 'updated_at' | ||
end | ||
end | ||
end | ||
|
||
def teardown_active_record | ||
::ActiveRecord::Base.connection.close | ||
end | ||
end | ||
gem_dir = Gem::Specification.find_by_name('delayed_job').gem_dir | ||
require "#{gem_dir}/spec/delayed/serialization/test" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason to load this empty file? https://github.com/collectiveidea/delayed_job/blob/v4.1.11/spec/delayed/serialization/test.rb There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This may not be required since I am using the class instead of a symbol. I will remove it and see if tests pass. https://github.com/collectiveidea/delayed_job/blob/master/lib/delayed/worker.rb#L67 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I removed this line and the tests pass.
arielvalentin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
require "#{gem_dir}/spec/delayed/backend/test" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMHO it would make sense to add PR to delayed job to move this file into lib folder since it is useful for testing depending libs. Should I try to open PR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That would be great! Thank you There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lead time seems like it is about 3-4 months in my experience collectiveidea/delayed_job#1169 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. definitely not blocker from my side |
||
|
||
Delayed::Worker.backend = Delayed::Backend::Test::Job |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason to not just require
delayed_job
itself here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delayed_job
is loaded by bundler therefore it is not necessary to load it twice.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if required properly, it would load this https://github.com/collectiveidea/delayed_job/blob/b66bb64437a8606a414a390531ac73108911434e/lib/delayed_job.rb#L11 and that would load https://github.com/collectiveidea/delayed_job/blob/b66bb64437a8606a414a390531ac73108911434e/lib/delayed/backend/job_preparer.rb#L1
🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is very curious isn't it!
Let me try this again and see what I can figure out
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting in that it fails for Rails 7.0 but not for 7.1 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The curious part for me here is that the backtrace clearly states its raised in JobPreparer, which is what requires the file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Explicitly requiring
delayed_job
and still get this error.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/open-telemetry/opentelemetry-ruby-contrib/actions/runs/6443662571/job/17495853381?pr=685