Active Job unit tests fail using que 2.2.0
Steps to reproduce
Active Job CI has been failing since que 2.2.0 is installed. https://buildkite.com/rails/rails/builds/89068#0182e6b9-7c84-4b85-a651-8d640f5eb076
git clone https://github.com/rails/rails
cd rails/activejob
bundle update que
AJ_ADAPTER=que bin/test test/cases/queuing_test.rb:13
Although there are 3 failures and 75 errors. This script just runs a single test because it looks the root cause is the same.
Expected behavior
It should pass.
Actual behavior
It raises ArgumentError: wrong number of arguments (given 2, expected 1)
.
$ AJ_ADAPTER=que bin/test test/cases/queuing_test.rb:13
Using que
Run options: --seed 62302
# Running:
E
Error:
QueuingTest#test_run_queued_job:
ArgumentError: wrong number of arguments (given 2, expected 1)
/home/yahonda/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/que-2.2.0/lib/que/active_job/extensions.rb:78:in `run'
/home/yahonda/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/que-2.2.0/lib/que/job_methods.rb:51:in `_run'
/home/yahonda/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/que-2.2.0/lib/que/job.rb:248:in `block (2 levels) in _run_attrs'
(eval):9:in `run_job_middleware'
/home/yahonda/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/que-2.2.0/lib/que/job.rb:247:in `block in _run_attrs'
<internal:kernel>:90:in `tap'
/home/yahonda/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/que-2.2.0/lib/que/job.rb:246:in `_run_attrs'
/home/yahonda/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/que-2.2.0/lib/que/job.rb:223:in `run'
/home/yahonda/src/github.com/rails/rails/activejob/test/support/que/inline.rb:15:in `enqueue'
/home/yahonda/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/que-2.2.0/lib/que/active_job/extensions.rb:66:in `enqueue'
/home/yahonda/src/github.com/rails/rails/activejob/lib/active_job/queue_adapters/que_adapter.rb:27:in `enqueue'
/home/yahonda/src/github.com/rails/rails/activejob/lib/active_job/enqueuing.rb:67:in `block in enqueue'
/home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/callbacks.rb:118:in `block in run_callbacks'
/home/yahonda/src/github.com/rails/rails/activejob/lib/active_job/instrumentation.rb:28:in `block in instrument'
/home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/notifications.rb:206:in `block in instrument'
/home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/notifications/instrumenter.rb:58:in `instrument'
/home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/notifications.rb:206:in `instrument'
/home/yahonda/src/github.com/rails/rails/activejob/lib/active_job/instrumentation.rb:27:in `instrument'
/home/yahonda/src/github.com/rails/rails/activejob/lib/active_job/instrumentation.rb:9:in `block (2 levels) in <module:Instrumentation>'
/home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/callbacks.rb:127:in `instance_exec'
/home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/callbacks.rb:127:in `block in run_callbacks'
/home/yahonda/src/github.com/rails/rails/activejob/lib/active_job/logging.rb:27:in `tag_logger'
/home/yahonda/src/github.com/rails/rails/activejob/lib/active_job/logging.rb:14:in `block (2 levels) in <module:Logging>'
/home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/callbacks.rb:127:in `instance_exec'
/home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/callbacks.rb:127:in `block in run_callbacks'
/home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/callbacks.rb:138:in `run_callbacks'
/home/yahonda/src/github.com/rails/rails/activejob/lib/active_job/enqueuing.rb:63:in `enqueue'
/home/yahonda/src/github.com/rails/rails/activejob/lib/active_job/enqueuing.rb:30:in `perform_later'
/home/yahonda/src/github.com/rails/rails/activejob/test/cases/queuing_test.rb:14:in `block in <class:QueuingTest>'
bin/test test/cases/queuing_test.rb:13
Finished in 0.008930s, 111.9768 runs/s, 0.0000 assertions/s.
1 runs, 0 assertions, 0 failures, 1 errors, 0 skips
$
Additional information
-
require_job_options_kwarg?
always returnsfalse
becauseJobWrapper.method(:enqueue).parameters
does not have any[:key, :job_options]
where it looks expected to returntrue
.
$ AJ_ADAPTER=que bin/test test/cases/queuing_test.rb:13
Using que
Run options: --seed 32774
# Running:
[46, 55] in ~/src/github.com/rails/rails/activejob/lib/active_job/queue_adapters/que_adapter.rb
46| end
47|
48| private
49| def require_job_options_kwarg?
50| require 'debug'
=> 51| binding.break
52| `@require_job_options_kwarg` ||=
53| JobWrapper.method(:enqueue).parameters.any? { |ptype, pname| ptype == :key && pname == :job_options }
54| end
55|
=>#0 ActiveJob::QueueAdapters::QueAdapter#require_job_options_kwarg? at ~/src/github.com/rails/rails/activejob/lib/active_job/queue_adapters/que_adapter.rb:51
#1 ActiveJob::QueueAdapters::QueAdapter#enqueue(job=#<HelloJob:0x00007fc861807740 `@arguments...`) at ~/src/github.com/rails/rails/activejob/lib/active_job/queue_adapters/que_adapter.rb:24
# and 40 frames (use `bt' command for all frames)
(rdbg) JobWrapper.method(:enqueue).parameters.any? { |ptype, pname| ptype == :key && pname == :job_options } # ruby
false
(rdbg) JobWrapper.method(:enqueue).parameters # ruby
[[:req, :args], [:keyreq, :priority], [:keyreq, :queue], [:key, :run_at]]
(rdbg) quit # command
Really quit? [Y/n] Y
- By changing
require_job_options_kwarg?
always returnstrue
, it raisesArgumentError: missing keywords: :priority, :queue
$ git diff
diff --git a/activejob/lib/active_job/queue_adapters/que_adapter.rb b/activejob/lib/active_job/queue_adapters/que_adapter.rb
index 41b3633a07..54e8cbc39b 100644
--- a/activejob/lib/active_job/queue_adapters/que_adapter.rb
+++ b/activejob/lib/active_job/queue_adapters/que_adapter.rb
@@ -47,6 +47,7 @@ def enqueue_at(job, timestamp) # :nodoc:
private
def require_job_options_kwarg?
+ return true
@require_job_options_kwarg ||=
JobWrapper.method(:enqueue).parameters.any? { |ptype, pname| ptype == :key && pname == :job_options }
end
$
$ AJ_ADAPTER=que bin/test test/cases/queuing_test.rb:13
Using que
Run options: --seed 21508
# Running:
E
Error:
QueuingTest#test_run_queued_job:
ArgumentError: missing keywords: :priority, :queue
/home/yahonda/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/que-2.2.0/lib/que/active_job/extensions.rb:65:in `enqueue'
/home/yahonda/src/github.com/rails/rails/activejob/lib/active_job/queue_adapters/que_adapter.rb:25:in `enqueue'
/home/yahonda/src/github.com/rails/rails/activejob/lib/active_job/enqueuing.rb:67:in `block in enqueue'
/home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/callbacks.rb:118:in `block in run_callbacks'
/home/yahonda/src/github.com/rails/rails/activejob/lib/active_job/instrumentation.rb:28:in `block in instrument'
/home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/notifications.rb:206:in `block in instrument'
/home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/notifications/instrumenter.rb:58:in `instrument'
/home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/notifications.rb:206:in `instrument'
/home/yahonda/src/github.com/rails/rails/activejob/lib/active_job/instrumentation.rb:27:in `instrument'
/home/yahonda/src/github.com/rails/rails/activejob/lib/active_job/instrumentation.rb:9:in `block (2 levels) in <module:Instrumentation>'
/home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/callbacks.rb:127:in `instance_exec'
/home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/callbacks.rb:127:in `block in run_callbacks'
/home/yahonda/src/github.com/rails/rails/activejob/lib/active_job/logging.rb:27:in `tag_logger'
/home/yahonda/src/github.com/rails/rails/activejob/lib/active_job/logging.rb:14:in `block (2 levels) in <module:Logging>'
/home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/callbacks.rb:127:in `instance_exec'
/home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/callbacks.rb:127:in `block in run_callbacks'
/home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/callbacks.rb:138:in `run_callbacks'
/home/yahonda/src/github.com/rails/rails/activejob/lib/active_job/enqueuing.rb:63:in `enqueue'
/home/yahonda/src/github.com/rails/rails/activejob/lib/active_job/enqueuing.rb:30:in `perform_later'
/home/yahonda/src/github.com/rails/rails/activejob/test/cases/queuing_test.rb:14:in `block in <class:QueuingTest>'
bin/test test/cases/queuing_test.rb:13
Finished in 0.008724s, 114.6312 runs/s, 0.0000 assertions/s.
1 runs, 0 assertions, 0 failures, 1 errors, 0 skips
$
System configuration
Rails version: main branch
Ruby version: $ ruby -v ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-linux]