aboutsummaryrefslogtreecommitdiffstats
path: root/activejob/test
diff options
context:
space:
mode:
Diffstat (limited to 'activejob/test')
-rw-r--r--activejob/test/adapters/backburner.rb4
-rw-r--r--activejob/test/adapters/delayed_job.rb1
-rw-r--r--activejob/test/adapters/inline.rb2
-rw-r--r--activejob/test/adapters/qu.rb2
-rw-r--r--activejob/test/adapters/que.rb2
-rw-r--r--activejob/test/adapters/queue_classic.rb2
-rw-r--r--activejob/test/adapters/sidekiq.rb2
-rw-r--r--activejob/test/adapters/sneakers.rb2
-rw-r--r--activejob/test/adapters/sucker_punch.rb2
-rw-r--r--activejob/test/cases/adapter_test.rb2
-rw-r--r--activejob/test/cases/argument_serialization_test.rb52
-rw-r--r--activejob/test/cases/callbacks_test.rb10
-rw-r--r--activejob/test/cases/exceptions_test.rb107
-rw-r--r--activejob/test/cases/job_serialization_test.rb28
-rw-r--r--activejob/test/cases/logging_test.rb19
-rw-r--r--activejob/test/cases/queue_adapter_test.rb10
-rw-r--r--activejob/test/cases/queue_naming_test.rb42
-rw-r--r--activejob/test/cases/queue_priority_test.rb20
-rw-r--r--activejob/test/cases/queuing_test.rb18
-rw-r--r--activejob/test/cases/rescue_test.rb20
-rw-r--r--activejob/test/cases/test_case_test.rb12
-rw-r--r--activejob/test/cases/test_helper_test.rb133
-rw-r--r--activejob/test/cases/translation_test.rb8
-rw-r--r--activejob/test/helper.rb14
-rw-r--r--activejob/test/integration/queuing_test.rb52
-rw-r--r--activejob/test/jobs/application_job.rb4
-rw-r--r--activejob/test/jobs/callback_job.rb2
-rw-r--r--activejob/test/jobs/gid_job.rb3
-rw-r--r--activejob/test/jobs/hello_job.rb2
-rw-r--r--activejob/test/jobs/inherited_job.rb5
-rw-r--r--activejob/test/jobs/kwargs_job.rb2
-rw-r--r--activejob/test/jobs/logging_job.rb1
-rw-r--r--activejob/test/jobs/nested_job.rb1
-rw-r--r--activejob/test/jobs/overridden_logging_job.rb9
-rw-r--r--activejob/test/jobs/provider_jid_job.rb7
-rw-r--r--activejob/test/jobs/queue_as_job.rb2
-rw-r--r--activejob/test/jobs/rescue_job.rb8
-rw-r--r--activejob/test/jobs/retry_job.rb29
-rw-r--r--activejob/test/jobs/translated_hello_job.rb4
-rw-r--r--activejob/test/support/backburner/inline.rb4
-rw-r--r--activejob/test/support/delayed_job/delayed/backend/test.rb16
-rw-r--r--activejob/test/support/integration/adapters/backburner.rb1
-rw-r--r--activejob/test/support/integration/adapters/delayed_job.rb4
-rw-r--r--activejob/test/support/integration/adapters/inline.rb1
-rw-r--r--activejob/test/support/integration/adapters/qu.rb6
-rw-r--r--activejob/test/support/integration/adapters/que.rb6
-rw-r--r--activejob/test/support/integration/adapters/queue_classic.rb14
-rw-r--r--activejob/test/support/integration/adapters/resque.rb2
-rw-r--r--activejob/test/support/integration/adapters/sidekiq.rb16
-rw-r--r--activejob/test/support/integration/adapters/sneakers.rb32
-rw-r--r--activejob/test/support/integration/dummy_app_template.rb8
-rw-r--r--activejob/test/support/integration/helper.rb8
-rw-r--r--activejob/test/support/integration/jobs_manager.rb2
-rw-r--r--activejob/test/support/integration/test_case_helpers.rb8
-rw-r--r--activejob/test/support/que/inline.rb4
-rw-r--r--activejob/test/support/queue_classic/inline.rb8
-rw-r--r--activejob/test/support/sneakers/inline.rb2
57 files changed, 487 insertions, 300 deletions
diff --git a/activejob/test/adapters/backburner.rb b/activejob/test/adapters/backburner.rb
index 65d05f850b..17ba07b802 100644
--- a/activejob/test/adapters/backburner.rb
+++ b/activejob/test/adapters/backburner.rb
@@ -1,3 +1,3 @@
-require 'support/backburner/inline'
+require "support/backburner/inline"
-ActiveJob::Base.queue_adapter = :backburner \ No newline at end of file
+ActiveJob::Base.queue_adapter = :backburner
diff --git a/activejob/test/adapters/delayed_job.rb b/activejob/test/adapters/delayed_job.rb
index afd9c9deb7..5f0ee2418c 100644
--- a/activejob/test/adapters/delayed_job.rb
+++ b/activejob/test/adapters/delayed_job.rb
@@ -4,4 +4,3 @@ $LOAD_PATH << File.dirname(__FILE__) + "/../support/delayed_job"
Delayed::Worker.delay_jobs = false
Delayed::Worker.backend = :test
-
diff --git a/activejob/test/adapters/inline.rb b/activejob/test/adapters/inline.rb
index e0092552c4..24113dfa5a 100644
--- a/activejob/test/adapters/inline.rb
+++ b/activejob/test/adapters/inline.rb
@@ -1 +1 @@
-ActiveJob::Base.queue_adapter = :inline \ No newline at end of file
+ActiveJob::Base.queue_adapter = :inline
diff --git a/activejob/test/adapters/qu.rb b/activejob/test/adapters/qu.rb
index 7728c843b4..b89c504091 100644
--- a/activejob/test/adapters/qu.rb
+++ b/activejob/test/adapters/qu.rb
@@ -1,3 +1,3 @@
-require 'qu-immediate'
+require "qu-immediate"
ActiveJob::Base.queue_adapter = :qu
diff --git a/activejob/test/adapters/que.rb b/activejob/test/adapters/que.rb
index e6abc57457..0c49274a4e 100644
--- a/activejob/test/adapters/que.rb
+++ b/activejob/test/adapters/que.rb
@@ -1,4 +1,4 @@
-require 'support/que/inline'
+require "support/que/inline"
ActiveJob::Base.queue_adapter = :que
Que.mode = :sync
diff --git a/activejob/test/adapters/queue_classic.rb b/activejob/test/adapters/queue_classic.rb
index ad5ced3cc2..e301a7ca96 100644
--- a/activejob/test/adapters/queue_classic.rb
+++ b/activejob/test/adapters/queue_classic.rb
@@ -1,2 +1,2 @@
-require 'support/queue_classic/inline'
+require "support/queue_classic/inline"
ActiveJob::Base.queue_adapter = :queue_classic
diff --git a/activejob/test/adapters/sidekiq.rb b/activejob/test/adapters/sidekiq.rb
index cd9d2034de..8036331ef1 100644
--- a/activejob/test/adapters/sidekiq.rb
+++ b/activejob/test/adapters/sidekiq.rb
@@ -1,2 +1,2 @@
-require 'sidekiq/testing/inline'
+require "sidekiq/testing/inline"
ActiveJob::Base.queue_adapter = :sidekiq
diff --git a/activejob/test/adapters/sneakers.rb b/activejob/test/adapters/sneakers.rb
index 204166a700..159c0d1906 100644
--- a/activejob/test/adapters/sneakers.rb
+++ b/activejob/test/adapters/sneakers.rb
@@ -1,2 +1,2 @@
-require 'support/sneakers/inline'
+require "support/sneakers/inline"
ActiveJob::Base.queue_adapter = :sneakers
diff --git a/activejob/test/adapters/sucker_punch.rb b/activejob/test/adapters/sucker_punch.rb
index d2d1712946..5661b6ee92 100644
--- a/activejob/test/adapters/sucker_punch.rb
+++ b/activejob/test/adapters/sucker_punch.rb
@@ -1,2 +1,2 @@
-require 'sucker_punch/testing/inline'
+require "sucker_punch/testing/inline"
ActiveJob::Base.queue_adapter = :sucker_punch
diff --git a/activejob/test/cases/adapter_test.rb b/activejob/test/cases/adapter_test.rb
index 6d75ae9a7c..caf5d44a5e 100644
--- a/activejob/test/cases/adapter_test.rb
+++ b/activejob/test/cases/adapter_test.rb
@@ -1,4 +1,4 @@
-require 'helper'
+require "helper"
class AdapterTest < ActiveSupport::TestCase
test "should load #{ENV['AJ_ADAPTER']} adapter" do
diff --git a/activejob/test/cases/argument_serialization_test.rb b/activejob/test/cases/argument_serialization_test.rb
index 59dc3d7f78..7934d8e556 100644
--- a/activejob/test/cases/argument_serialization_test.rb
+++ b/activejob/test/cases/argument_serialization_test.rb
@@ -1,25 +1,25 @@
-require 'helper'
-require 'active_job/arguments'
-require 'models/person'
-require 'active_support/core_ext/hash/indifferent_access'
-require 'jobs/kwargs_job'
+require "helper"
+require "active_job/arguments"
+require "models/person"
+require "active_support/core_ext/hash/indifferent_access"
+require "jobs/kwargs_job"
class ArgumentSerializationTest < ActiveSupport::TestCase
setup do
- @person = Person.find('5')
+ @person = Person.find("5")
end
[ nil, 1, 1.0, 1_000_000_000_000_000_000_000,
- 'a', true, false, BigDecimal.new(5),
- [ 1, 'a' ],
- { 'a' => 1 }
+ "a", true, false, BigDecimal.new(5),
+ [ 1, "a" ],
+ { "a" => 1 }
].each do |arg|
- test "serializes #{arg.class} verbatim" do
+ test "serializes #{arg.class} - #{arg} verbatim" do
assert_arguments_unchanged arg
end
end
- [ :a, Object.new, self, Person.find('5').to_gid ].each do |arg|
+ [ :a, Object.new, self, Person.find("5").to_gid ].each do |arg|
test "does not serialize #{arg.class}" do
assert_raises ActiveJob::SerializationError do
ActiveJob::Arguments.serialize [ arg ]
@@ -31,22 +31,22 @@ class ArgumentSerializationTest < ActiveSupport::TestCase
end
end
- test 'should convert records to Global IDs' do
+ test "should convert records to Global IDs" do
assert_arguments_roundtrip [@person]
end
- test 'should dive deep into arrays and hashes' do
+ test "should dive deep into arrays and hashes" do
assert_arguments_roundtrip [3, [@person]]
- assert_arguments_roundtrip [{ 'a' => @person }]
+ assert_arguments_roundtrip [{ "a" => @person }]
end
- test 'should maintain string and symbol keys' do
+ test "should maintain string and symbol keys" do
assert_arguments_roundtrip([a: 1, "b" => 2])
end
- test 'should maintain hash with indifferent access' do
+ test "should maintain hash with indifferent access" do
symbol_key = { a: 1 }
- string_key = { 'a' => 1 }
+ string_key = { "a" => 1 }
indifferent_access = { a: 1 }.with_indifferent_access
assert_not_instance_of ActiveSupport::HashWithIndifferentAccess, perform_round_trip([symbol_key]).first
@@ -54,26 +54,26 @@ class ArgumentSerializationTest < ActiveSupport::TestCase
assert_instance_of ActiveSupport::HashWithIndifferentAccess, perform_round_trip([indifferent_access]).first
end
- test 'should disallow non-string/symbol hash keys' do
+ test "should disallow non-string/symbol hash keys" do
assert_raises ActiveJob::SerializationError do
ActiveJob::Arguments.serialize [ { 1 => 2 } ]
end
assert_raises ActiveJob::SerializationError do
- ActiveJob::Arguments.serialize [ { :a => [{ 2 => 3 }] } ]
+ ActiveJob::Arguments.serialize [ { a: [{ 2 => 3 }] } ]
end
end
- test 'should not allow reserved hash keys' do
- ['_aj_globalid', :_aj_globalid, '_aj_symbol_keys', :_aj_symbol_keys,
- '_aj_hash_with_indifferent_access', :_aj_hash_with_indifferent_access].each do |key|
+ test "should not allow reserved hash keys" do
+ ["_aj_globalid", :_aj_globalid, "_aj_symbol_keys", :_aj_symbol_keys,
+ "_aj_hash_with_indifferent_access", :_aj_hash_with_indifferent_access].each do |key|
assert_raises ActiveJob::SerializationError do
ActiveJob::Arguments.serialize [key => 1]
end
end
end
- test 'should not allow non-primitive objects' do
+ test "should not allow non-primitive objects" do
assert_raises ActiveJob::SerializationError do
ActiveJob::Arguments.serialize [Object.new]
end
@@ -83,17 +83,17 @@ class ArgumentSerializationTest < ActiveSupport::TestCase
end
end
- test 'allows for keyword arguments' do
+ test "allows for keyword arguments" do
KwargsJob.perform_later(argument: 2)
assert_equal "Job with argument: 2", JobBuffer.last_value
end
- test 'raises a friendly SerializationError for records without ids' do
+ test "raises a friendly SerializationError for records without ids" do
err = assert_raises ActiveJob::SerializationError do
ActiveJob::Arguments.serialize [Person.new(nil)]
end
- assert_match 'Unable to serialize Person without an id.', err.message
+ assert_match "Unable to serialize Person without an id.", err.message
end
private
diff --git a/activejob/test/cases/callbacks_test.rb b/activejob/test/cases/callbacks_test.rb
index 9af2380767..8d1c9c3058 100644
--- a/activejob/test/cases/callbacks_test.rb
+++ b/activejob/test/cases/callbacks_test.rb
@@ -1,10 +1,10 @@
-require 'helper'
-require 'jobs/callback_job'
+require "helper"
+require "jobs/callback_job"
-require 'active_support/core_ext/object/inclusion'
+require "active_support/core_ext/object/inclusion"
class CallbacksTest < ActiveSupport::TestCase
- test 'perform callbacks' do
+ test "perform callbacks" do
performed_callback_job = CallbackJob.new("A-JOB-ID")
performed_callback_job.perform_now
assert "CallbackJob ran before_perform".in? performed_callback_job.history
@@ -13,7 +13,7 @@ class CallbacksTest < ActiveSupport::TestCase
assert "CallbackJob ran around_perform_stop".in? performed_callback_job.history
end
- test 'enqueue callbacks' do
+ test "enqueue callbacks" do
enqueued_callback_job = CallbackJob.perform_later
assert "CallbackJob ran before_enqueue".in? enqueued_callback_job.history
assert "CallbackJob ran after_enqueue".in? enqueued_callback_job.history
diff --git a/activejob/test/cases/exceptions_test.rb b/activejob/test/cases/exceptions_test.rb
new file mode 100644
index 0000000000..dbe55f7430
--- /dev/null
+++ b/activejob/test/cases/exceptions_test.rb
@@ -0,0 +1,107 @@
+require "helper"
+require "jobs/retry_job"
+
+class ExceptionsTest < ActiveJob::TestCase
+ setup do
+ JobBuffer.clear
+ skip if ActiveJob::Base.queue_adapter.is_a?(ActiveJob::QueueAdapters::InlineAdapter)
+ end
+
+ test "successfully retry job throwing exception against defaults" do
+ perform_enqueued_jobs do
+ RetryJob.perform_later "DefaultsError", 5
+
+ assert_equal [
+ "Raised DefaultsError for the 1st time",
+ "Raised DefaultsError for the 2nd time",
+ "Raised DefaultsError for the 3rd time",
+ "Raised DefaultsError for the 4th time",
+ "Successfully completed job" ], JobBuffer.values
+ end
+ end
+
+ test "successfully retry job throwing exception against higher limit" do
+ perform_enqueued_jobs do
+ RetryJob.perform_later "ShortWaitTenAttemptsError", 9
+ assert_equal 9, JobBuffer.values.count
+ end
+ end
+
+ test "failed retry job when exception kept occurring against defaults" do
+ perform_enqueued_jobs do
+ begin
+ RetryJob.perform_later "DefaultsError", 6
+ assert_equal "Raised DefaultsError for the 5th time", JobBuffer.last_value
+ rescue DefaultsError
+ pass
+ end
+ end
+ end
+
+ test "failed retry job when exception kept occurring against higher limit" do
+ perform_enqueued_jobs do
+ begin
+ RetryJob.perform_later "ShortWaitTenAttemptsError", 11
+ assert_equal "Raised ShortWaitTenAttemptsError for the 10th time", JobBuffer.last_value
+ rescue ShortWaitTenAttemptsError
+ pass
+ end
+ end
+ end
+
+ test "discard job" do
+ perform_enqueued_jobs do
+ RetryJob.perform_later "DiscardableError", 2
+ assert_equal "Raised DiscardableError for the 1st time", JobBuffer.last_value
+ end
+ end
+
+ test "custom handling of job that exceeds retry attempts" do
+ perform_enqueued_jobs do
+ RetryJob.perform_later "CustomCatchError", 6
+ assert_equal "Dealt with a job that failed to retry in a custom way after 6 attempts", JobBuffer.last_value
+ end
+ end
+
+ test "long wait job" do
+ travel_to Time.now
+
+ perform_enqueued_jobs do
+ assert_performed_with at: (Time.now + 3600.seconds).to_i do
+ RetryJob.perform_later "LongWaitError", 5
+ end
+ end
+ end
+
+ test "exponentially retrying job" do
+ travel_to Time.now
+
+ perform_enqueued_jobs do
+ assert_performed_with at: (Time.now + 3.seconds).to_i do
+ assert_performed_with at: (Time.now + 18.seconds).to_i do
+ assert_performed_with at: (Time.now + 83.seconds).to_i do
+ assert_performed_with at: (Time.now + 258.seconds).to_i do
+ RetryJob.perform_later "ExponentialWaitTenAttemptsError", 5
+ end
+ end
+ end
+ end
+ end
+ end
+
+ test "custom wait retrying job" do
+ travel_to Time.now
+
+ perform_enqueued_jobs do
+ assert_performed_with at: (Time.now + 2.seconds).to_i do
+ assert_performed_with at: (Time.now + 4.seconds).to_i do
+ assert_performed_with at: (Time.now + 6.seconds).to_i do
+ assert_performed_with at: (Time.now + 8.seconds).to_i do
+ RetryJob.perform_later "CustomWaitTenAttemptsError", 5
+ end
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/activejob/test/cases/job_serialization_test.rb b/activejob/test/cases/job_serialization_test.rb
index fa94209889..3f2e300dfa 100644
--- a/activejob/test/cases/job_serialization_test.rb
+++ b/activejob/test/cases/job_serialization_test.rb
@@ -1,8 +1,8 @@
-require 'helper'
-require 'jobs/gid_job'
-require 'jobs/hello_job'
-require 'models/person'
-require 'json'
+require "helper"
+require "jobs/gid_job"
+require "jobs/hello_job"
+require "models/person"
+require "json"
class JobSerializationTest < ActiveSupport::TestCase
setup do
@@ -10,16 +10,16 @@ class JobSerializationTest < ActiveSupport::TestCase
@person = Person.find(5)
end
- test 'serialize job with gid' do
+ test "serialize job with gid" do
GidJob.perform_later @person
assert_equal "Person with ID: 5", JobBuffer.last_value
end
- test 'serialize includes current locale' do
- assert_equal 'en', HelloJob.new.serialize['locale']
+ test "serialize includes current locale" do
+ assert_equal "en", HelloJob.new.serialize["locale"]
end
- test 'serialize and deserialize are symmetric' do
+ test "serialize and deserialize are symmetric" do
# Round trip a job in memory only
h1 = HelloJob.new
h1.deserialize(h1.serialize)
@@ -33,15 +33,15 @@ class JobSerializationTest < ActiveSupport::TestCase
assert_equal h1.serialize, h2.serialize
end
- test 'deserialize sets locale' do
+ test "deserialize sets locale" do
job = HelloJob.new
- job.deserialize 'locale' => 'es'
- assert_equal 'es', job.locale
+ job.deserialize "locale" => "es"
+ assert_equal "es", job.locale
end
- test 'deserialize sets default locale' do
+ test "deserialize sets default locale" do
job = HelloJob.new
job.deserialize({})
- assert_equal 'en', job.locale
+ assert_equal "en", job.locale
end
end
diff --git a/activejob/test/cases/logging_test.rb b/activejob/test/cases/logging_test.rb
index 820e9112de..954974b2a5 100644
--- a/activejob/test/cases/logging_test.rb
+++ b/activejob/test/cases/logging_test.rb
@@ -1,10 +1,11 @@
-require 'helper'
+require "helper"
require "active_support/log_subscriber/test_helper"
-require 'active_support/core_ext/numeric/time'
-require 'jobs/hello_job'
-require 'jobs/logging_job'
-require 'jobs/nested_job'
-require 'models/person'
+require "active_support/core_ext/numeric/time"
+require "jobs/hello_job"
+require "jobs/logging_job"
+require "jobs/overridden_logging_job"
+require "jobs/nested_job"
+require "models/person"
class LoggingTest < ActiveSupport::TestCase
include ActiveSupport::LogSubscriber::TestHelper
@@ -41,7 +42,6 @@ class LoggingTest < ActiveSupport::TestCase
ActiveJob::Base.logger = logger
end
-
def test_uses_active_job_as_tag
HelloJob.perform_later "Cristian"
assert_match(/\[ActiveJob\]/, @logger.messages)
@@ -119,4 +119,9 @@ class LoggingTest < ActiveSupport::TestCase
rescue NotImplementedError
skip
end
+
+ def test_for_tagged_logger_support_is_consistent
+ set_logger ::Logger.new(nil)
+ OverriddenLoggingJob.perform_later "Dummy"
+ end
end
diff --git a/activejob/test/cases/queue_adapter_test.rb b/activejob/test/cases/queue_adapter_test.rb
index fb3fdc392f..dc862450aa 100644
--- a/activejob/test/cases/queue_adapter_test.rb
+++ b/activejob/test/cases/queue_adapter_test.rb
@@ -1,4 +1,4 @@
-require 'helper'
+require "helper"
module ActiveJob
module QueueAdapters
@@ -15,15 +15,15 @@ module ActiveJob
end
class QueueAdapterTest < ActiveJob::TestCase
- test 'should forbid nonsense arguments' do
+ test "should forbid nonsense arguments" do
assert_raises(ArgumentError) { ActiveJob::Base.queue_adapter = Mutex }
assert_raises(ArgumentError) { ActiveJob::Base.queue_adapter = Mutex.new }
end
- test 'should warn on passing an adapter class' do
+ test "should warn on passing an adapter class" do
klass = Class.new do
def self.name
- 'fake'
+ "fake"
end
def enqueue(*); end
@@ -33,7 +33,7 @@ class QueueAdapterTest < ActiveJob::TestCase
assert_deprecated { ActiveJob::Base.queue_adapter = klass }
end
- test 'should allow overriding the queue_adapter at the child class level without affecting the parent or its sibling' do
+ test "should allow overriding the queue_adapter at the child class level without affecting the parent or its sibling" do
base_queue_adapter = ActiveJob::Base.queue_adapter
child_job_one = Class.new(ActiveJob::Base)
diff --git a/activejob/test/cases/queue_naming_test.rb b/activejob/test/cases/queue_naming_test.rb
index 898016a704..7777e557c9 100644
--- a/activejob/test/cases/queue_naming_test.rb
+++ b/activejob/test/cases/queue_naming_test.rb
@@ -1,14 +1,14 @@
-require 'helper'
-require 'jobs/hello_job'
-require 'jobs/logging_job'
-require 'jobs/nested_job'
+require "helper"
+require "jobs/hello_job"
+require "jobs/logging_job"
+require "jobs/nested_job"
class QueueNamingTest < ActiveSupport::TestCase
- test 'name derived from base' do
+ test "name derived from base" do
assert_equal "default", HelloJob.queue_name
end
- test 'uses given queue name job' do
+ test "uses given queue name job" do
original_queue_name = HelloJob.queue_name
begin
@@ -19,7 +19,7 @@ class QueueNamingTest < ActiveSupport::TestCase
end
end
- test 'allows a blank queue name' do
+ test "allows a blank queue name" do
original_queue_name = HelloJob.queue_name
begin
@@ -30,7 +30,7 @@ class QueueNamingTest < ActiveSupport::TestCase
end
end
- test 'does not use a nil queue name' do
+ test "does not use a nil queue name" do
original_queue_name = HelloJob.queue_name
begin
@@ -41,7 +41,7 @@ class QueueNamingTest < ActiveSupport::TestCase
end
end
- test 'evals block given to queue_as to determine queue' do
+ test "evals block given to queue_as to determine queue" do
original_queue_name = HelloJob.queue_name
begin
@@ -52,42 +52,42 @@ class QueueNamingTest < ActiveSupport::TestCase
end
end
- test 'can use arguments to determine queue_name in queue_as block' do
+ test "can use arguments to determine queue_name in queue_as block" do
original_queue_name = HelloJob.queue_name
begin
- HelloJob.queue_as { self.arguments.first=='1' ? :one : :two }
- assert_equal "one", HelloJob.new('1').queue_name
- assert_equal "two", HelloJob.new('3').queue_name
+ HelloJob.queue_as { self.arguments.first=="1" ? :one : :two }
+ assert_equal "one", HelloJob.new("1").queue_name
+ assert_equal "two", HelloJob.new("3").queue_name
ensure
HelloJob.queue_name = original_queue_name
end
end
- test 'queue_name_prefix prepended to the queue name with default delimiter' do
+ test "queue_name_prefix prepended to the queue name with default delimiter" do
original_queue_name_prefix = ActiveJob::Base.queue_name_prefix
original_queue_name = HelloJob.queue_name
begin
- ActiveJob::Base.queue_name_prefix = 'aj'
+ ActiveJob::Base.queue_name_prefix = "aj"
HelloJob.queue_as :low
- assert_equal 'aj_low', HelloJob.queue_name
+ assert_equal "aj_low", HelloJob.queue_name
ensure
ActiveJob::Base.queue_name_prefix = original_queue_name_prefix
HelloJob.queue_name = original_queue_name
end
end
- test 'queue_name_prefix prepended to the queue name with custom delimiter' do
+ test "queue_name_prefix prepended to the queue name with custom delimiter" do
original_queue_name_prefix = ActiveJob::Base.queue_name_prefix
original_queue_name_delimiter = ActiveJob::Base.queue_name_delimiter
original_queue_name = HelloJob.queue_name
begin
- ActiveJob::Base.queue_name_delimiter = '.'
- ActiveJob::Base.queue_name_prefix = 'aj'
+ ActiveJob::Base.queue_name_delimiter = "."
+ ActiveJob::Base.queue_name_prefix = "aj"
HelloJob.queue_as :low
- assert_equal 'aj.low', HelloJob.queue_name
+ assert_equal "aj.low", HelloJob.queue_name
ensure
ActiveJob::Base.queue_name_prefix = original_queue_name_prefix
ActiveJob::Base.queue_name_delimiter = original_queue_name_delimiter
@@ -95,7 +95,7 @@ class QueueNamingTest < ActiveSupport::TestCase
end
end
- test 'uses queue passed to #set' do
+ test "uses queue passed to #set" do
job = HelloJob.set(queue: :some_queue).perform_later
assert_equal "some_queue", job.queue_name
end
diff --git a/activejob/test/cases/queue_priority_test.rb b/activejob/test/cases/queue_priority_test.rb
index ca17b51dad..ab4a1bdf7b 100644
--- a/activejob/test/cases/queue_priority_test.rb
+++ b/activejob/test/cases/queue_priority_test.rb
@@ -1,12 +1,12 @@
-require 'helper'
-require 'jobs/hello_job'
+require "helper"
+require "jobs/hello_job"
class QueuePriorityTest < ActiveSupport::TestCase
- test 'priority unset by default' do
+ test "priority unset by default" do
assert_equal nil, HelloJob.priority
end
- test 'uses given priority' do
+ test "uses given priority" do
original_priority = HelloJob.priority
begin
@@ -17,7 +17,7 @@ class QueuePriorityTest < ActiveSupport::TestCase
end
end
- test 'evals block given to priority to determine priority' do
+ test "evals block given to priority to determine priority" do
original_priority = HelloJob.priority
begin
@@ -28,19 +28,19 @@ class QueuePriorityTest < ActiveSupport::TestCase
end
end
- test 'can use arguments to determine priority in priority block' do
+ test "can use arguments to determine priority in priority block" do
original_priority = HelloJob.priority
begin
- HelloJob.queue_with_priority { self.arguments.first=='1' ? 99 : 11 }
- assert_equal 99, HelloJob.new('1').priority
- assert_equal 11, HelloJob.new('3').priority
+ HelloJob.queue_with_priority { self.arguments.first=="1" ? 99 : 11 }
+ assert_equal 99, HelloJob.new("1").priority
+ assert_equal 11, HelloJob.new("3").priority
ensure
HelloJob.priority = original_priority
end
end
- test 'uses priority passed to #set' do
+ test "uses priority passed to #set" do
job = HelloJob.set(priority: 123).perform_later
assert_equal 123, job.priority
end
diff --git a/activejob/test/cases/queuing_test.rb b/activejob/test/cases/queuing_test.rb
index 0eeabbf693..a3ecb15c31 100644
--- a/activejob/test/cases/queuing_test.rb
+++ b/activejob/test/cases/queuing_test.rb
@@ -1,24 +1,23 @@
-require 'helper'
-require 'jobs/hello_job'
-require 'active_support/core_ext/numeric/time'
-
+require "helper"
+require "jobs/hello_job"
+require "active_support/core_ext/numeric/time"
class QueuingTest < ActiveSupport::TestCase
setup do
JobBuffer.clear
end
- test 'run queued job' do
+ test "run queued job" do
HelloJob.perform_later
assert_equal "David says hello", JobBuffer.last_value
end
- test 'run queued job with arguments' do
+ test "run queued job with arguments" do
HelloJob.perform_later "Jamie"
assert_equal "Jamie says hello", JobBuffer.last_value
end
- test 'run queued job later' do
+ test "run queued job later" do
begin
result = HelloJob.set(wait_until: 1.second.ago).perform_later "Jamie"
assert result
@@ -27,13 +26,12 @@ class QueuingTest < ActiveSupport::TestCase
end
end
- test 'job returned by enqueue has the arguments available' do
+ test "job returned by enqueue has the arguments available" do
job = HelloJob.perform_later "Jamie"
assert_equal [ "Jamie" ], job.arguments
end
-
- test 'job returned by perform_at has the timestamp available' do
+ test "job returned by perform_at has the timestamp available" do
begin
job = HelloJob.set(wait_until: Time.utc(2014, 1, 1)).perform_later
assert_equal Time.utc(2014, 1, 1).to_f, job.scheduled_at
diff --git a/activejob/test/cases/rescue_test.rb b/activejob/test/cases/rescue_test.rb
index 58c9ca8992..afb1b48831 100644
--- a/activejob/test/cases/rescue_test.rb
+++ b/activejob/test/cases/rescue_test.rb
@@ -1,34 +1,34 @@
-require 'helper'
-require 'jobs/rescue_job'
-require 'models/person'
+require "helper"
+require "jobs/rescue_job"
+require "models/person"
class RescueTest < ActiveSupport::TestCase
setup do
JobBuffer.clear
end
- test 'rescue perform exception with retry' do
+ test "rescue perform exception with retry" do
job = RescueJob.new("david")
job.perform_now
assert_equal [ "rescued from ArgumentError", "performed beautifully" ], JobBuffer.values
end
- test 'let through unhandled perform exception' do
+ test "let through unhandled perform exception" do
job = RescueJob.new("other")
assert_raises(RescueJob::OtherError) do
job.perform_now
end
end
- test 'rescue from deserialization errors' do
+ test "rescue from deserialization errors" do
RescueJob.perform_later Person.new(404)
- assert_includes JobBuffer.values, 'rescued from DeserializationError'
- assert_includes JobBuffer.values, 'DeserializationError original exception was Person::RecordNotFound'
- assert_not_includes JobBuffer.values, 'performed beautifully'
+ assert_includes JobBuffer.values, "rescued from DeserializationError"
+ assert_includes JobBuffer.values, "DeserializationError original exception was Person::RecordNotFound"
+ assert_not_includes JobBuffer.values, "performed beautifully"
end
test "should not wrap DeserializationError in DeserializationError" do
RescueJob.perform_later [Person.new(404)]
- assert_includes JobBuffer.values, 'DeserializationError original exception was Person::RecordNotFound'
+ assert_includes JobBuffer.values, "DeserializationError original exception was Person::RecordNotFound"
end
end
diff --git a/activejob/test/cases/test_case_test.rb b/activejob/test/cases/test_case_test.rb
index 616454a4b6..3db2d9dec7 100644
--- a/activejob/test/cases/test_case_test.rb
+++ b/activejob/test/cases/test_case_test.rb
@@ -1,7 +1,7 @@
-require 'helper'
-require 'jobs/hello_job'
-require 'jobs/logging_job'
-require 'jobs/nested_job'
+require "helper"
+require "jobs/hello_job"
+require "jobs/logging_job"
+require "jobs/nested_job"
class ActiveJobTestCaseTest < ActiveJob::TestCase
# this tests that this job class doesn't get its adapter set.
@@ -9,7 +9,7 @@ class ActiveJobTestCaseTest < ActiveJob::TestCase
# the `class_attribute` inheritance
class TestClassAttributeInheritanceJob < ActiveJob::Base
def self.queue_adapter=(*)
- raise 'Attempting to break `class_attribute` inheritance, bad!'
+ raise "Attempting to break `class_attribute` inheritance, bad!"
end
end
@@ -18,6 +18,6 @@ class ActiveJobTestCaseTest < ActiveJob::TestCase
end
def test_set_test_adapter
- assert_kind_of ActiveJob::QueueAdapters::TestAdapter, self.queue_adapter
+ assert_kind_of ActiveJob::QueueAdapters::TestAdapter, queue_adapter
end
end
diff --git a/activejob/test/cases/test_helper_test.rb b/activejob/test/cases/test_helper_test.rb
index f7ee763e8a..253c557cc5 100644
--- a/activejob/test/cases/test_helper_test.rb
+++ b/activejob/test/cases/test_helper_test.rb
@@ -1,17 +1,18 @@
-require 'helper'
-require 'active_support/core_ext/time'
-require 'active_support/core_ext/date'
-require 'jobs/hello_job'
-require 'jobs/logging_job'
-require 'jobs/nested_job'
-require 'jobs/rescue_job'
-require 'models/person'
+require "helper"
+require "active_support/core_ext/time"
+require "active_support/core_ext/date"
+require "jobs/hello_job"
+require "jobs/logging_job"
+require "jobs/nested_job"
+require "jobs/rescue_job"
+require "jobs/inherited_job"
+require "models/person"
class EnqueuedJobsTest < ActiveJob::TestCase
def test_assert_enqueued_jobs
assert_nothing_raised do
assert_enqueued_jobs 1 do
- HelloJob.perform_later('david')
+ HelloJob.perform_later("david")
end
end
end
@@ -19,23 +20,23 @@ class EnqueuedJobsTest < ActiveJob::TestCase
def test_repeated_enqueued_jobs_calls
assert_nothing_raised do
assert_enqueued_jobs 1 do
- HelloJob.perform_later('abdelkader')
+ HelloJob.perform_later("abdelkader")
end
end
assert_nothing_raised do
assert_enqueued_jobs 2 do
- HelloJob.perform_later('sean')
- HelloJob.perform_later('yves')
+ HelloJob.perform_later("sean")
+ HelloJob.perform_later("yves")
end
end
end
def test_assert_enqueued_jobs_message
- HelloJob.perform_later('sean')
+ HelloJob.perform_later("sean")
e = assert_raises Minitest::Assertion do
assert_enqueued_jobs 2 do
- HelloJob.perform_later('sean')
+ HelloJob.perform_later("sean")
end
end
assert_match "Expected: 2", e.message
@@ -44,13 +45,13 @@ class EnqueuedJobsTest < ActiveJob::TestCase
def test_assert_enqueued_jobs_with_no_block
assert_nothing_raised do
- HelloJob.perform_later('rafael')
+ HelloJob.perform_later("rafael")
assert_enqueued_jobs 1
end
assert_nothing_raised do
- HelloJob.perform_later('aaron')
- HelloJob.perform_later('matthew')
+ HelloJob.perform_later("aaron")
+ HelloJob.perform_later("matthew")
assert_enqueued_jobs 3
end
end
@@ -72,7 +73,7 @@ class EnqueuedJobsTest < ActiveJob::TestCase
def test_assert_enqueued_jobs_too_few_sent
error = assert_raise ActiveSupport::TestCase::Assertion do
assert_enqueued_jobs 2 do
- HelloJob.perform_later('xavier')
+ HelloJob.perform_later("xavier")
end
end
@@ -82,8 +83,8 @@ class EnqueuedJobsTest < ActiveJob::TestCase
def test_assert_enqueued_jobs_too_many_sent
error = assert_raise ActiveSupport::TestCase::Assertion do
assert_enqueued_jobs 1 do
- HelloJob.perform_later('cristian')
- HelloJob.perform_later('guillermo')
+ HelloJob.perform_later("cristian")
+ HelloJob.perform_later("guillermo")
end
end
@@ -93,7 +94,7 @@ class EnqueuedJobsTest < ActiveJob::TestCase
def test_assert_no_enqueued_jobs_failure
error = assert_raise ActiveSupport::TestCase::Assertion do
assert_no_enqueued_jobs do
- HelloJob.perform_later('jeremy')
+ HelloJob.perform_later("jeremy")
end
end
@@ -103,7 +104,7 @@ class EnqueuedJobsTest < ActiveJob::TestCase
def test_assert_enqueued_jobs_with_only_option
assert_nothing_raised do
assert_enqueued_jobs 1, only: HelloJob do
- HelloJob.perform_later('jeremy')
+ HelloJob.perform_later("jeremy")
LoggingJob.perform_later
end
end
@@ -122,7 +123,7 @@ class EnqueuedJobsTest < ActiveJob::TestCase
def test_assert_enqueued_jobs_with_only_option_and_too_few_sent
error = assert_raise ActiveSupport::TestCase::Assertion do
assert_enqueued_jobs 5, only: HelloJob do
- HelloJob.perform_later('jeremy')
+ HelloJob.perform_later("jeremy")
4.times { LoggingJob.perform_later }
end
end
@@ -133,7 +134,7 @@ class EnqueuedJobsTest < ActiveJob::TestCase
def test_assert_enqueued_jobs_with_only_option_and_too_many_sent
error = assert_raise ActiveSupport::TestCase::Assertion do
assert_enqueued_jobs 1, only: HelloJob do
- 2.times { HelloJob.perform_later('jeremy') }
+ 2.times { HelloJob.perform_later("jeremy") }
end
end
@@ -143,9 +144,9 @@ class EnqueuedJobsTest < ActiveJob::TestCase
def test_assert_enqueued_jobs_with_only_option_as_array
assert_nothing_raised do
assert_enqueued_jobs 2, only: [HelloJob, LoggingJob] do
- HelloJob.perform_later('jeremy')
- LoggingJob.perform_later('stewie')
- RescueJob.perform_later('david')
+ HelloJob.perform_later("jeremy")
+ LoggingJob.perform_later("stewie")
+ RescueJob.perform_later("david")
end
end
end
@@ -161,7 +162,7 @@ class EnqueuedJobsTest < ActiveJob::TestCase
def test_assert_no_enqueued_jobs_with_only_option_failure
error = assert_raise ActiveSupport::TestCase::Assertion do
assert_no_enqueued_jobs only: HelloJob do
- HelloJob.perform_later('jeremy')
+ HelloJob.perform_later("jeremy")
LoggingJob.perform_later
end
end
@@ -178,7 +179,7 @@ class EnqueuedJobsTest < ActiveJob::TestCase
end
def test_assert_enqueued_job
- assert_enqueued_with(job: LoggingJob, queue: 'default') do
+ assert_enqueued_with(job: LoggingJob, queue: "default") do
LoggingJob.set(wait_until: Date.tomorrow.noon).perform_later
end
end
@@ -190,19 +191,19 @@ class EnqueuedJobsTest < ActiveJob::TestCase
assert_instance_of LoggingJob, job
assert_in_delta 5.minutes.from_now, job.scheduled_at, 1
- assert_equal 'default', job.queue_name
+ assert_equal "default", job.queue_name
assert_equal [1, 2, 3], job.arguments
end
def test_assert_enqueued_job_failure
assert_raise ActiveSupport::TestCase::Assertion do
- assert_enqueued_with(job: LoggingJob, queue: 'default') do
+ assert_enqueued_with(job: LoggingJob, queue: "default") do
NestedJob.perform_later
end
end
error = assert_raise ActiveSupport::TestCase::Assertion do
- assert_enqueued_with(job: NestedJob, queue: 'low') do
+ assert_enqueued_with(job: NestedJob, queue: "low") do
NestedJob.perform_later
end
end
@@ -265,7 +266,7 @@ class PerformedJobsTest < ActiveJob::TestCase
def test_assert_performed_jobs
assert_nothing_raised do
assert_performed_jobs 1 do
- HelloJob.perform_later('david')
+ HelloJob.perform_later("david")
end
end
end
@@ -273,23 +274,23 @@ class PerformedJobsTest < ActiveJob::TestCase
def test_repeated_performed_jobs_calls
assert_nothing_raised do
assert_performed_jobs 1 do
- HelloJob.perform_later('abdelkader')
+ HelloJob.perform_later("abdelkader")
end
end
assert_nothing_raised do
assert_performed_jobs 2 do
- HelloJob.perform_later('sean')
- HelloJob.perform_later('yves')
+ HelloJob.perform_later("sean")
+ HelloJob.perform_later("yves")
end
end
end
def test_assert_performed_jobs_message
- HelloJob.perform_later('sean')
+ HelloJob.perform_later("sean")
e = assert_raises Minitest::Assertion do
assert_performed_jobs 2 do
- HelloJob.perform_later('sean')
+ HelloJob.perform_later("sean")
end
end
assert_match "Expected: 2", e.message
@@ -299,15 +300,15 @@ class PerformedJobsTest < ActiveJob::TestCase
def test_assert_performed_jobs_with_no_block
assert_nothing_raised do
perform_enqueued_jobs do
- HelloJob.perform_later('rafael')
+ HelloJob.perform_later("rafael")
end
assert_performed_jobs 1
end
assert_nothing_raised do
perform_enqueued_jobs do
- HelloJob.perform_later('aaron')
- HelloJob.perform_later('matthew')
+ HelloJob.perform_later("aaron")
+ HelloJob.perform_later("matthew")
assert_performed_jobs 3
end
end
@@ -330,7 +331,7 @@ class PerformedJobsTest < ActiveJob::TestCase
def test_assert_performed_jobs_too_few_sent
error = assert_raise ActiveSupport::TestCase::Assertion do
assert_performed_jobs 2 do
- HelloJob.perform_later('xavier')
+ HelloJob.perform_later("xavier")
end
end
@@ -340,8 +341,8 @@ class PerformedJobsTest < ActiveJob::TestCase
def test_assert_performed_jobs_too_many_sent
error = assert_raise ActiveSupport::TestCase::Assertion do
assert_performed_jobs 1 do
- HelloJob.perform_later('cristian')
- HelloJob.perform_later('guillermo')
+ HelloJob.perform_later("cristian")
+ HelloJob.perform_later("guillermo")
end
end
@@ -351,7 +352,7 @@ class PerformedJobsTest < ActiveJob::TestCase
def test_assert_no_performed_jobs_failure
error = assert_raise ActiveSupport::TestCase::Assertion do
assert_no_performed_jobs do
- HelloJob.perform_later('jeremy')
+ HelloJob.perform_later("jeremy")
end
end
@@ -361,7 +362,7 @@ class PerformedJobsTest < ActiveJob::TestCase
def test_assert_performed_jobs_with_only_option
assert_nothing_raised do
assert_performed_jobs 1, only: HelloJob do
- HelloJob.perform_later('jeremy')
+ HelloJob.perform_later("jeremy")
LoggingJob.perform_later
end
end
@@ -370,9 +371,9 @@ class PerformedJobsTest < ActiveJob::TestCase
def test_assert_performed_jobs_with_only_option_as_array
assert_nothing_raised do
assert_performed_jobs 2, only: [HelloJob, LoggingJob] do
- HelloJob.perform_later('jeremy')
- LoggingJob.perform_later('stewie')
- RescueJob.perform_later('david')
+ HelloJob.perform_later("jeremy")
+ LoggingJob.perform_later("stewie")
+ RescueJob.perform_later("david")
end
end
end
@@ -390,7 +391,7 @@ class PerformedJobsTest < ActiveJob::TestCase
def test_assert_performed_jobs_with_only_option_and_too_few_sent
error = assert_raise ActiveSupport::TestCase::Assertion do
assert_performed_jobs 5, only: HelloJob do
- HelloJob.perform_later('jeremy')
+ HelloJob.perform_later("jeremy")
4.times { LoggingJob.perform_later }
end
end
@@ -401,7 +402,7 @@ class PerformedJobsTest < ActiveJob::TestCase
def test_assert_performed_jobs_with_only_option_and_too_many_sent
error = assert_raise ActiveSupport::TestCase::Assertion do
assert_performed_jobs 1, only: HelloJob do
- 2.times { HelloJob.perform_later('jeremy') }
+ 2.times { HelloJob.perform_later("jeremy") }
end
end
@@ -427,7 +428,7 @@ class PerformedJobsTest < ActiveJob::TestCase
def test_assert_no_performed_jobs_with_only_option_failure
error = assert_raise ActiveSupport::TestCase::Assertion do
assert_no_performed_jobs only: HelloJob do
- HelloJob.perform_later('jeremy')
+ HelloJob.perform_later("jeremy")
LoggingJob.perform_later
end
end
@@ -436,20 +437,20 @@ class PerformedJobsTest < ActiveJob::TestCase
end
def test_assert_performed_job
- assert_performed_with(job: NestedJob, queue: 'default') do
+ assert_performed_with(job: NestedJob, queue: "default") do
NestedJob.perform_later
end
end
def test_assert_performed_job_returns
- job = assert_performed_with(job: NestedJob, queue: 'default') do
+ job = assert_performed_with(job: NestedJob, queue: "default") do
NestedJob.perform_later
end
assert_instance_of NestedJob, job
assert_nil job.scheduled_at
assert_equal [], job.arguments
- assert_equal 'default', job.queue_name
+ assert_equal "default", job.queue_name
end
def test_assert_performed_job_failure
@@ -460,8 +461,8 @@ class PerformedJobsTest < ActiveJob::TestCase
end
assert_raise ActiveSupport::TestCase::Assertion do
- assert_performed_with(job: HelloJob, queue: 'low') do
- HelloJob.set(queue: 'important').perform_later
+ assert_performed_with(job: HelloJob, queue: "low") do
+ HelloJob.set(queue: "important").perform_later
end
end
end
@@ -509,3 +510,21 @@ class PerformedJobsTest < ActiveJob::TestCase
assert_equal 2, ActiveJob::Base.queue_adapter.performed_jobs.count
end
end
+
+class OverrideQueueAdapterTest < ActiveJob::TestCase
+ class CustomQueueAdapter < ActiveJob::QueueAdapters::TestAdapter; end
+
+ def queue_adapter_for_test
+ CustomQueueAdapter.new
+ end
+
+ def test_assert_job_has_custom_queue_adapter_set
+ assert_instance_of CustomQueueAdapter, HelloJob.queue_adapter
+ end
+end
+
+class InheritedJobTest < ActiveJob::TestCase
+ def test_queue_adapter_is_test_adapter
+ assert_instance_of ActiveJob::QueueAdapters::TestAdapter, InheritedJob.queue_adapter
+ end
+end
diff --git a/activejob/test/cases/translation_test.rb b/activejob/test/cases/translation_test.rb
index d5e3aaf9e3..27bfd50985 100644
--- a/activejob/test/cases/translation_test.rb
+++ b/activejob/test/cases/translation_test.rb
@@ -1,18 +1,18 @@
-require 'helper'
-require 'jobs/translated_hello_job'
+require "helper"
+require "jobs/translated_hello_job"
class TranslationTest < ActiveSupport::TestCase
setup do
JobBuffer.clear
I18n.available_locales = [:en, :de]
- @job = TranslatedHelloJob.new('Johannes')
+ @job = TranslatedHelloJob.new("Johannes")
end
teardown do
I18n.available_locales = [:en]
end
- test 'it performs the job in the given locale' do
+ test "it performs the job in the given locale" do
@job.locale = :de
@job.perform_now
assert_equal "Johannes says Guten Tag", JobBuffer.last_value
diff --git a/activejob/test/helper.rb b/activejob/test/helper.rb
index 54b6076f09..dbc7dad109 100644
--- a/activejob/test/helper.rb
+++ b/activejob/test/helper.rb
@@ -1,16 +1,16 @@
-require 'active_job'
-require 'support/job_buffer'
+require "active_job"
+require "support/job_buffer"
ActiveSupport.halt_callback_chains_on_return_false = false
-GlobalID.app = 'aj'
+GlobalID.app = "aj"
-@adapter = ENV['AJ_ADAPTER'] || 'inline'
+@adapter = ENV["AJ_ADAPTER"] || "inline"
-if ENV['AJ_INTEGRATION_TESTS']
- require 'support/integration/helper'
+if ENV["AJ_INTEGRATION_TESTS"]
+ require "support/integration/helper"
else
ActiveJob::Base.logger = Logger.new(nil)
require "adapters/#{@adapter}"
end
-require 'active_support/testing/autorun'
+require "active_support/testing/autorun"
diff --git a/activejob/test/integration/queuing_test.rb b/activejob/test/integration/queuing_test.rb
index 40f27500a5..2669c52a1c 100644
--- a/activejob/test/integration/queuing_test.rb
+++ b/activejob/test/integration/queuing_test.rb
@@ -1,16 +1,17 @@
-require 'helper'
-require 'jobs/logging_job'
-require 'jobs/hello_job'
-require 'active_support/core_ext/numeric/time'
+require "helper"
+require "jobs/logging_job"
+require "jobs/hello_job"
+require "jobs/provider_jid_job"
+require "active_support/core_ext/numeric/time"
class QueuingTest < ActiveSupport::TestCase
- test 'should run jobs enqueued on a listening queue' do
+ test "should run jobs enqueued on a listening queue" do
TestJob.perform_later @id
wait_for_jobs_to_finish_for(5.seconds)
assert job_executed
end
- test 'should not run jobs queued on a non-listening queue' do
+ test "should not run jobs queued on a non-listening queue" do
skip if adapter_is?(:inline, :async, :sucker_punch, :que)
old_queue = TestJob.queue_name
@@ -24,17 +25,32 @@ class QueuingTest < ActiveSupport::TestCase
end
end
- test 'should supply a wrapped class name to Sidekiq' do
+ test "should supply a wrapped class name to Sidekiq" do
skip unless adapter_is?(:sidekiq)
Sidekiq::Testing.fake! do
::HelloJob.perform_later
hash = ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper.jobs.first
- assert_equal "ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper", hash['class']
- assert_equal "HelloJob", hash['wrapped']
+ assert_equal "ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper", hash["class"]
+ assert_equal "HelloJob", hash["wrapped"]
end
end
- test 'should not run job enqueued in the future' do
+ test "should access provider_job_id inside Sidekiq job" do
+ skip unless adapter_is?(:sidekiq)
+ Sidekiq::Testing.inline! do
+ job = ::ProviderJidJob.perform_later
+ assert_equal "Provider Job ID: #{job.provider_job_id}", JobBuffer.last_value
+ end
+ end
+
+ test "resque JobWrapper should have instance variable queue" do
+ skip unless adapter_is?(:resque)
+ job = ::HelloJob.set(wait: 5.seconds).perform_later
+ hash = Resque.decode(Resque.find_delayed_selection { true }[0])
+ assert_equal hash["queue"], job.queue_name
+ end
+
+ test "should not run job enqueued in the future" do
begin
TestJob.set(wait: 10.minutes).perform_later @id
wait_for_jobs_to_finish_for(5.seconds)
@@ -44,7 +60,7 @@ class QueuingTest < ActiveSupport::TestCase
end
end
- test 'should run job enqueued in the future at the specified time' do
+ test "should run job enqueued in the future at the specified time" do
begin
TestJob.set(wait: 5.seconds).perform_later @id
wait_for_jobs_to_finish_for(2.seconds)
@@ -56,19 +72,19 @@ class QueuingTest < ActiveSupport::TestCase
end
end
- test 'should supply a provider_job_id when available for immediate jobs' do
+ test "should supply a provider_job_id when available for immediate jobs" do
skip unless adapter_is?(:async, :delayed_job, :sidekiq, :qu, :que, :queue_classic)
test_job = TestJob.perform_later @id
- assert test_job.provider_job_id, 'Provider job id should be set by provider'
+ assert test_job.provider_job_id, "Provider job id should be set by provider"
end
- test 'should supply a provider_job_id when available for delayed jobs' do
+ test "should supply a provider_job_id when available for delayed jobs" do
skip unless adapter_is?(:async, :delayed_job, :sidekiq, :que, :queue_classic)
delayed_test_job = TestJob.set(wait: 1.minute).perform_later @id
- assert delayed_test_job.provider_job_id, 'Provider job id should by set for delayed jobs by provider'
+ assert delayed_test_job.provider_job_id, "Provider job id should by set for delayed jobs by provider"
end
- test 'current locale is kept while running perform_later' do
+ test "current locale is kept while running perform_later" do
skip if adapter_is?(:inline)
begin
@@ -78,14 +94,14 @@ class QueuingTest < ActiveSupport::TestCase
TestJob.perform_later @id
wait_for_jobs_to_finish_for(5.seconds)
assert job_executed
- assert_equal 'de', job_executed_in_locale
+ assert_equal "de", job_executed_in_locale
ensure
I18n.available_locales = [:en]
I18n.locale = :en
end
end
- test 'should run job with higher priority first' do
+ test "should run job with higher priority first" do
skip unless adapter_is?(:delayed_job, :que)
wait_until = Time.now + 3.seconds
diff --git a/activejob/test/jobs/application_job.rb b/activejob/test/jobs/application_job.rb
new file mode 100644
index 0000000000..4a78b890ec
--- /dev/null
+++ b/activejob/test/jobs/application_job.rb
@@ -0,0 +1,4 @@
+require_relative "../support/job_buffer"
+
+class ApplicationJob < ActiveJob::Base
+end
diff --git a/activejob/test/jobs/callback_job.rb b/activejob/test/jobs/callback_job.rb
index 891ed9464e..ca2a8e031a 100644
--- a/activejob/test/jobs/callback_job.rb
+++ b/activejob/test/jobs/callback_job.rb
@@ -17,7 +17,6 @@ class CallbackJob < ActiveJob::Base
job.history << "CallbackJob ran around_enqueue_stop"
end
-
def perform(person = "david")
# NOTHING!
end
@@ -25,5 +24,4 @@ class CallbackJob < ActiveJob::Base
def history
@history ||= []
end
-
end
diff --git a/activejob/test/jobs/gid_job.rb b/activejob/test/jobs/gid_job.rb
index e485bfa2dd..c7cfa6e7a2 100644
--- a/activejob/test/jobs/gid_job.rb
+++ b/activejob/test/jobs/gid_job.rb
@@ -1,8 +1,7 @@
-require_relative '../support/job_buffer'
+require_relative "../support/job_buffer"
class GidJob < ActiveJob::Base
def perform(person)
JobBuffer.add("Person with ID: #{person.id}")
end
end
-
diff --git a/activejob/test/jobs/hello_job.rb b/activejob/test/jobs/hello_job.rb
index 022fa58e4a..126fefae00 100644
--- a/activejob/test/jobs/hello_job.rb
+++ b/activejob/test/jobs/hello_job.rb
@@ -1,4 +1,4 @@
-require_relative '../support/job_buffer'
+require_relative "../support/job_buffer"
class HelloJob < ActiveJob::Base
def perform(greeter = "David")
diff --git a/activejob/test/jobs/inherited_job.rb b/activejob/test/jobs/inherited_job.rb
new file mode 100644
index 0000000000..60fca66f88
--- /dev/null
+++ b/activejob/test/jobs/inherited_job.rb
@@ -0,0 +1,5 @@
+require_relative "application_job"
+
+class InheritedJob < ApplicationJob
+ self.queue_adapter = :inline
+end
diff --git a/activejob/test/jobs/kwargs_job.rb b/activejob/test/jobs/kwargs_job.rb
index 2df17d15ae..9f9d809673 100644
--- a/activejob/test/jobs/kwargs_job.rb
+++ b/activejob/test/jobs/kwargs_job.rb
@@ -1,4 +1,4 @@
-require_relative '../support/job_buffer'
+require_relative "../support/job_buffer"
class KwargsJob < ActiveJob::Base
def perform(argument: 1)
diff --git a/activejob/test/jobs/logging_job.rb b/activejob/test/jobs/logging_job.rb
index d84ed8589b..119b32fa67 100644
--- a/activejob/test/jobs/logging_job.rb
+++ b/activejob/test/jobs/logging_job.rb
@@ -7,4 +7,3 @@ class LoggingJob < ActiveJob::Base
"LOGGING-JOB-ID"
end
end
-
diff --git a/activejob/test/jobs/nested_job.rb b/activejob/test/jobs/nested_job.rb
index 8c4ec549a6..21b7692cd1 100644
--- a/activejob/test/jobs/nested_job.rb
+++ b/activejob/test/jobs/nested_job.rb
@@ -7,4 +7,3 @@ class NestedJob < ActiveJob::Base
"NESTED-JOB-ID"
end
end
-
diff --git a/activejob/test/jobs/overridden_logging_job.rb b/activejob/test/jobs/overridden_logging_job.rb
new file mode 100644
index 0000000000..2b17a65142
--- /dev/null
+++ b/activejob/test/jobs/overridden_logging_job.rb
@@ -0,0 +1,9 @@
+class OverriddenLoggingJob < ActiveJob::Base
+ def perform(dummy)
+ logger.info "Dummy, here is it: #{dummy}"
+ end
+
+ def logger
+ @logger ||= ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(nil))
+ end
+end
diff --git a/activejob/test/jobs/provider_jid_job.rb b/activejob/test/jobs/provider_jid_job.rb
new file mode 100644
index 0000000000..0c8ba040f5
--- /dev/null
+++ b/activejob/test/jobs/provider_jid_job.rb
@@ -0,0 +1,7 @@
+require_relative "../support/job_buffer"
+
+class ProviderJidJob < ActiveJob::Base
+ def perform
+ JobBuffer.add("Provider Job ID: #{provider_job_id}")
+ end
+end
diff --git a/activejob/test/jobs/queue_as_job.rb b/activejob/test/jobs/queue_as_job.rb
index 897aef52e5..7dc318e736 100644
--- a/activejob/test/jobs/queue_as_job.rb
+++ b/activejob/test/jobs/queue_as_job.rb
@@ -1,4 +1,4 @@
-require_relative '../support/job_buffer'
+require_relative "../support/job_buffer"
class QueueAsJob < ActiveJob::Base
MY_QUEUE = :low_priority
diff --git a/activejob/test/jobs/rescue_job.rb b/activejob/test/jobs/rescue_job.rb
index 4f6376c850..ef8f777437 100644
--- a/activejob/test/jobs/rescue_job.rb
+++ b/activejob/test/jobs/rescue_job.rb
@@ -1,16 +1,16 @@
-require_relative '../support/job_buffer'
+require_relative "../support/job_buffer"
class RescueJob < ActiveJob::Base
class OtherError < StandardError; end
rescue_from(ArgumentError) do
- JobBuffer.add('rescued from ArgumentError')
+ JobBuffer.add("rescued from ArgumentError")
arguments[0] = "DIFFERENT!"
retry_job
end
rescue_from(ActiveJob::DeserializationError) do |e|
- JobBuffer.add('rescued from DeserializationError')
+ JobBuffer.add("rescued from DeserializationError")
JobBuffer.add("DeserializationError original exception was #{e.cause.class.name}")
end
@@ -21,7 +21,7 @@ class RescueJob < ActiveJob::Base
when "other"
raise OtherError
else
- JobBuffer.add('performed beautifully')
+ JobBuffer.add("performed beautifully")
end
end
end
diff --git a/activejob/test/jobs/retry_job.rb b/activejob/test/jobs/retry_job.rb
new file mode 100644
index 0000000000..c02febc50c
--- /dev/null
+++ b/activejob/test/jobs/retry_job.rb
@@ -0,0 +1,29 @@
+require_relative "../support/job_buffer"
+require "active_support/core_ext/integer/inflections"
+
+class DefaultsError < StandardError; end
+class LongWaitError < StandardError; end
+class ShortWaitTenAttemptsError < StandardError; end
+class ExponentialWaitTenAttemptsError < StandardError; end
+class CustomWaitTenAttemptsError < StandardError; end
+class CustomCatchError < StandardError; end
+class DiscardableError < StandardError; end
+
+class RetryJob < ActiveJob::Base
+ retry_on DefaultsError
+ retry_on LongWaitError, wait: 1.hour, attempts: 10
+ retry_on ShortWaitTenAttemptsError, wait: 1.second, attempts: 10
+ retry_on ExponentialWaitTenAttemptsError, wait: :exponentially_longer, attempts: 10
+ retry_on CustomWaitTenAttemptsError, wait: ->(executions) { executions * 2 }, attempts: 10
+ retry_on(CustomCatchError) { |job, exception| JobBuffer.add("Dealt with a job that failed to retry in a custom way after #{job.arguments.second} attempts") }
+ discard_on DiscardableError
+
+ def perform(raising, attempts)
+ if executions < attempts
+ JobBuffer.add("Raised #{raising} for the #{executions.ordinalize} time")
+ raise raising.constantize
+ else
+ JobBuffer.add("Successfully completed job")
+ end
+ end
+end
diff --git a/activejob/test/jobs/translated_hello_job.rb b/activejob/test/jobs/translated_hello_job.rb
index 9657cd3f54..56e9f147b9 100644
--- a/activejob/test/jobs/translated_hello_job.rb
+++ b/activejob/test/jobs/translated_hello_job.rb
@@ -1,8 +1,8 @@
-require_relative '../support/job_buffer'
+require_relative "../support/job_buffer"
class TranslatedHelloJob < ActiveJob::Base
def perform(greeter = "David")
- translations = { en: 'Hello', de: 'Guten Tag' }
+ translations = { en: "Hello", de: "Guten Tag" }
hello = translations[I18n.locale]
JobBuffer.add("#{greeter} says #{hello}")
diff --git a/activejob/test/support/backburner/inline.rb b/activejob/test/support/backburner/inline.rb
index f761b53e27..647dbf317f 100644
--- a/activejob/test/support/backburner/inline.rb
+++ b/activejob/test/support/backburner/inline.rb
@@ -1,8 +1,8 @@
-require 'backburner'
+require "backburner"
Backburner::Worker.class_eval do
class << self; alias_method :original_enqueue, :enqueue; end
def self.enqueue(job_class, args=[], opts={})
job_class.perform(*args)
end
-end \ No newline at end of file
+end
diff --git a/activejob/test/support/delayed_job/delayed/backend/test.rb b/activejob/test/support/delayed_job/delayed/backend/test.rb
index f80ec3a5a6..a900b18e2a 100644
--- a/activejob/test/support/delayed_job/delayed/backend/test.rb
+++ b/activejob/test/support/delayed_job/delayed/backend/test.rb
@@ -1,5 +1,5 @@
#copied from https://github.com/collectiveidea/delayed_job/blob/master/spec/delayed/backend/test.rb
-require 'ostruct'
+require "ostruct"
# An in-memory backend suitable only for testing. Tries to behave as if it were an ORM.
module Delayed
@@ -26,7 +26,7 @@ module Delayed
self.attempts = 0
self.priority = 0
self.id = (self.class.id += 1)
- hash.each{|k,v| send(:"#{k}=", v)}
+ hash.each { |k,v| send(:"#{k}=", v) }
end
@jobs = []
@@ -49,7 +49,7 @@ module Delayed
def self.create!(*args); create(*args); end
def self.clear_locks!(worker_name)
- all.select{|j| j.locked_by == worker_name}.each {|j| j.locked_by = nil; j.locked_at = nil}
+ all.select { |j| j.locked_by == worker_name }.each { |j| j.locked_by = nil; j.locked_at = nil }
end
# Find a few candidate jobs to run (in case some immediately get locked by others).
@@ -60,10 +60,10 @@ module Delayed
!j.failed?
end
- jobs = jobs.select{|j| Worker.queues.include?(j.queue)} if Worker.queues.any?
- jobs = jobs.select{|j| j.priority >= Worker.min_priority} if Worker.min_priority
- jobs = jobs.select{|j| j.priority <= Worker.max_priority} if Worker.max_priority
- jobs.sort_by{|j| [j.priority, j.run_at]}[0..limit-1]
+ jobs = jobs.select { |j| Worker.queues.include?(j.queue) } if Worker.queues.any?
+ jobs = jobs.select { |j| j.priority >= Worker.min_priority } if Worker.min_priority
+ jobs = jobs.select { |j| j.priority <= Worker.max_priority } if Worker.max_priority
+ jobs.sort_by { |j| [j.priority, j.run_at] }[0..limit-1]
end
# Lock this job for this worker.
@@ -84,7 +84,7 @@ module Delayed
end
def update_attributes(attrs = {})
- attrs.each{|k,v| send(:"#{k}=", v)}
+ attrs.each { |k,v| send(:"#{k}=", v) }
save
end
diff --git a/activejob/test/support/integration/adapters/backburner.rb b/activejob/test/support/integration/adapters/backburner.rb
index 2e82562948..263097c792 100644
--- a/activejob/test/support/integration/adapters/backburner.rb
+++ b/activejob/test/support/integration/adapters/backburner.rb
@@ -35,4 +35,3 @@ module BackburnerJobsManager
true
end
end
-
diff --git a/activejob/test/support/integration/adapters/delayed_job.rb b/activejob/test/support/integration/adapters/delayed_job.rb
index 0b591964bc..2adbbcd88f 100644
--- a/activejob/test/support/integration/adapters/delayed_job.rb
+++ b/activejob/test/support/integration/adapters/delayed_job.rb
@@ -1,5 +1,5 @@
-require 'delayed_job'
-require 'delayed_job_active_record'
+require "delayed_job"
+require "delayed_job_active_record"
module DelayedJobJobsManager
def setup
diff --git a/activejob/test/support/integration/adapters/inline.rb b/activejob/test/support/integration/adapters/inline.rb
index 83c38f706f..e06b34c976 100644
--- a/activejob/test/support/integration/adapters/inline.rb
+++ b/activejob/test/support/integration/adapters/inline.rb
@@ -12,4 +12,3 @@ module InlineJobsManager
def stop_workers
end
end
-
diff --git a/activejob/test/support/integration/adapters/qu.rb b/activejob/test/support/integration/adapters/qu.rb
index 256ddb3cf3..71819f5a55 100644
--- a/activejob/test/support/integration/adapters/qu.rb
+++ b/activejob/test/support/integration/adapters/qu.rb
@@ -1,9 +1,9 @@
module QuJobsManager
def setup
- require 'qu-rails'
- require 'qu-redis'
+ require "qu-rails"
+ require "qu-redis"
ActiveJob::Base.queue_adapter = :qu
- ENV['REDISTOGO_URL'] = "redis://127.0.0.1:6379/12"
+ ENV["REDISTOGO_URL"] = "redis://127.0.0.1:6379/12"
backend = Qu::Backend::Redis.new
backend.namespace = "active_jobs_int_test"
Qu.backend = backend
diff --git a/activejob/test/support/integration/adapters/que.rb b/activejob/test/support/integration/adapters/que.rb
index 0cd8952a28..3d35a0439f 100644
--- a/activejob/test/support/integration/adapters/que.rb
+++ b/activejob/test/support/integration/adapters/que.rb
@@ -1,6 +1,6 @@
module QueJobsManager
def setup
- require 'sequel'
+ require "sequel"
ActiveJob::Base.queue_adapter = :que
Que.mode = :off
Que.worker_count = 1
@@ -11,9 +11,9 @@ module QueJobsManager
end
def start_workers
- que_url = ENV['QUE_DATABASE_URL'] || 'postgres:///active_jobs_que_int_test'
+ que_url = ENV["QUE_DATABASE_URL"] || "postgres:///active_jobs_que_int_test"
uri = URI.parse(que_url)
- user = uri.user||ENV['USER']
+ user = uri.user||ENV["USER"]
pass = uri.password
db = uri.path[1..-1]
%x{#{"PGPASSWORD=\"#{pass}\"" if pass} psql -c 'drop database if exists "#{db}"' -U #{user} -t template1}
diff --git a/activejob/test/support/integration/adapters/queue_classic.rb b/activejob/test/support/integration/adapters/queue_classic.rb
index 29c04bf625..b5d831428e 100644
--- a/activejob/test/support/integration/adapters/queue_classic.rb
+++ b/activejob/test/support/integration/adapters/queue_classic.rb
@@ -1,8 +1,8 @@
module QueueClassicJobsManager
def setup
- ENV['QC_DATABASE_URL'] ||= 'postgres:///active_jobs_qc_int_test'
- ENV['QC_RAILS_DATABASE'] = 'false'
- ENV['QC_LISTEN_TIME'] = "0.5"
+ ENV["QC_DATABASE_URL"] ||= "postgres:///active_jobs_qc_int_test"
+ ENV["QC_RAILS_DATABASE"] = "false"
+ ENV["QC_LISTEN_TIME"] = "0.5"
ActiveJob::Base.queue_adapter = :queue_classic
end
@@ -11,8 +11,8 @@ module QueueClassicJobsManager
end
def start_workers
- uri = URI.parse(ENV['QC_DATABASE_URL'])
- user = uri.user||ENV['USER']
+ uri = URI.parse(ENV["QC_DATABASE_URL"])
+ user = uri.user||ENV["USER"]
pass = uri.password
db = uri.path[1..-1]
%x{#{"PGPASSWORD=\"#{pass}\"" if pass} psql -c 'drop database if exists "#{db}"' -U #{user} -t template1}
@@ -22,7 +22,7 @@ module QueueClassicJobsManager
QC.default_conn_adapter.disconnect
QC.default_conn_adapter = nil
@pid = fork do
- worker = QC::Worker.new(q_name: 'integration_tests')
+ worker = QC::Worker.new(q_name: "integration_tests")
worker.start
end
@@ -32,6 +32,6 @@ module QueueClassicJobsManager
end
def stop_workers
- Process.kill 'HUP', @pid
+ Process.kill "HUP", @pid
end
end
diff --git a/activejob/test/support/integration/adapters/resque.rb b/activejob/test/support/integration/adapters/resque.rb
index 912f4bc387..a21a1786c9 100644
--- a/activejob/test/support/integration/adapters/resque.rb
+++ b/activejob/test/support/integration/adapters/resque.rb
@@ -1,7 +1,7 @@
module ResqueJobsManager
def setup
ActiveJob::Base.queue_adapter = :resque
- Resque.redis = Redis::Namespace.new 'active_jobs_int_test', redis: Redis.connect(url: "redis://127.0.0.1:6379/12", :thread_safe => true)
+ Resque.redis = Redis::Namespace.new "active_jobs_int_test", redis: Redis.connect(url: "redis://127.0.0.1:6379/12", thread_safe: true)
Resque.logger = Rails.logger
unless can_run?
puts "Cannot run integration tests for resque. To be able to run integration tests for resque you need to install and start redis.\n"
diff --git a/activejob/test/support/integration/adapters/sidekiq.rb b/activejob/test/support/integration/adapters/sidekiq.rb
index 2f19d7dacc..bbb575f6da 100644
--- a/activejob/test/support/integration/adapters/sidekiq.rb
+++ b/activejob/test/support/integration/adapters/sidekiq.rb
@@ -1,10 +1,9 @@
-require 'sidekiq/api'
+require "sidekiq/api"
-require 'sidekiq/testing'
+require "sidekiq/testing"
Sidekiq::Testing.disable!
module SidekiqJobsManager
-
def setup
ActiveJob::Base.queue_adapter = :sidekiq
unless can_run?
@@ -29,7 +28,7 @@ module SidekiqJobsManager
# Sidekiq is not warning-clean :(
$VERBOSE = false
- $stdin.reopen('/dev/null')
+ $stdin.reopen("/dev/null")
$stdout.sync = true
$stderr.sync = true
@@ -49,12 +48,11 @@ module SidekiqJobsManager
self_write.puts("TERM")
end
- require 'sidekiq/launcher'
- sidekiq = Sidekiq::Launcher.new({queues: ["integration_tests"],
+ require "sidekiq/launcher"
+ sidekiq = Sidekiq::Launcher.new(queues: ["integration_tests"],
environment: "test",
concurrency: 1,
- timeout: 1,
- })
+ timeout: 1)
Sidekiq.average_scheduled_poll_interval = 0.5
Sidekiq.options[:poll_interval_average] = 1
begin
@@ -79,7 +77,7 @@ module SidekiqJobsManager
def stop_workers
if @pid
- Process.kill 'TERM', @pid
+ Process.kill "TERM", @pid
Process.wait @pid
end
end
diff --git a/activejob/test/support/integration/adapters/sneakers.rb b/activejob/test/support/integration/adapters/sneakers.rb
index 875803a2d8..08743c1f05 100644
--- a/activejob/test/support/integration/adapters/sneakers.rb
+++ b/activejob/test/support/integration/adapters/sneakers.rb
@@ -1,6 +1,6 @@
-require 'sneakers/runner'
-require 'sneakers/publisher'
-require 'timeout'
+require "sneakers/runner"
+require "sneakers/publisher"
+require "timeout"
module Sneakers
class Publisher
@@ -12,20 +12,19 @@ module Sneakers
end
end
-
module SneakersJobsManager
def setup
ActiveJob::Base.queue_adapter = :sneakers
- Sneakers.configure :heartbeat => 2,
- :amqp => 'amqp://guest:guest@localhost:5672',
- :vhost => '/',
- :exchange => 'active_jobs_sneakers_int_test',
- :exchange_type => :direct,
- :daemonize => true,
- :threads => 1,
- :workers => 1,
- :pid_path => Rails.root.join("tmp/sneakers.pid").to_s,
- :log => Rails.root.join("log/sneakers.log").to_s
+ Sneakers.configure heartbeat: 2,
+ amqp: "amqp://guest:guest@localhost:5672",
+ vhost: "/",
+ exchange: "active_jobs_sneakers_int_test",
+ exchange_type: :direct,
+ daemonize: true,
+ threads: 1,
+ workers: 1,
+ pid_path: Rails.root.join("tmp/sneakers.pid").to_s,
+ log: Rails.root.join("log/sneakers.log").to_s
unless can_run?
puts "Cannot run integration tests for sneakers. To be able to run integration tests for sneakers you need to install and start rabbitmq.\n"
exit
@@ -60,8 +59,8 @@ module SneakersJobsManager
end
def stop_workers
- Process.kill 'TERM', @pid
- Process.kill 'TERM', File.open(Rails.root.join("tmp/sneakers.pid").to_s).read.to_i
+ Process.kill "TERM", @pid
+ Process.kill "TERM", File.open(Rails.root.join("tmp/sneakers.pid").to_s).read.to_i
rescue
end
@@ -86,5 +85,4 @@ module SneakersJobsManager
def bunny_queue
@queue ||= bunny_publisher.exchange.channel.queue "integration_tests", durable: true
end
-
end
diff --git a/activejob/test/support/integration/dummy_app_template.rb b/activejob/test/support/integration/dummy_app_template.rb
index a0ef38b0b2..62f6fa13f6 100644
--- a/activejob/test/support/integration/dummy_app_template.rb
+++ b/activejob/test/support/integration/dummy_app_template.rb
@@ -1,19 +1,19 @@
-if ENV['AJ_ADAPTER'] == 'delayed_job'
+if ENV["AJ_ADAPTER"] == "delayed_job"
generate "delayed_job:active_record", "--quiet"
end
rails_command("db:migrate")
-initializer 'activejob.rb', <<-CODE
+initializer "activejob.rb", <<-CODE
require "#{File.expand_path("../jobs_manager.rb", __FILE__)}"
JobsManager.current_manager.setup
CODE
-initializer 'i18n.rb', <<-CODE
+initializer "i18n.rb", <<-CODE
I18n.available_locales = [:en, :de]
CODE
-file 'app/jobs/test_job.rb', <<-CODE
+file "app/jobs/test_job.rb", <<-CODE
class TestJob < ActiveJob::Base
queue_as :integration_tests
diff --git a/activejob/test/support/integration/helper.rb b/activejob/test/support/integration/helper.rb
index 4a1b0bfbcb..1aaee2c809 100644
--- a/activejob/test/support/integration/helper.rb
+++ b/activejob/test/support/integration/helper.rb
@@ -3,7 +3,7 @@ puts "\n\n*** rake aj:integration:#{ENV['AJ_ADAPTER']} ***\n"
ENV["RAILS_ENV"] = "test"
ActiveJob::Base.queue_name_prefix = nil
-require 'rails/generators/rails/app/app_generator'
+require "rails/generators/rails/app/app_generator"
dummy_app_path = Dir.mktmpdir + "/dummy"
dummy_app_template = File.expand_path("../dummy_app_template.rb", __FILE__)
@@ -14,12 +14,12 @@ Rails::Generators::AppGenerator.start args
require "#{dummy_app_path}/config/environment.rb"
-ActiveRecord::Migrator.migrations_paths = [ Rails.root.join('db/migrate').to_s ]
-require 'rails/test_help'
+ActiveRecord::Migrator.migrations_paths = [ Rails.root.join("db/migrate").to_s ]
+require "rails/test_help"
Rails.backtrace_cleaner.remove_silencers!
-require_relative 'test_case_helpers'
+require_relative "test_case_helpers"
ActiveSupport::TestCase.include(TestCaseHelpers)
JobsManager.current_manager.start_workers
diff --git a/activejob/test/support/integration/jobs_manager.rb b/activejob/test/support/integration/jobs_manager.rb
index 78d48e8d9a..488756437b 100644
--- a/activejob/test/support/integration/jobs_manager.rb
+++ b/activejob/test/support/integration/jobs_manager.rb
@@ -3,7 +3,7 @@ class JobsManager
attr :adapter_name
def self.current_manager
- @@managers[ENV['AJ_ADAPTER']] ||= new(ENV['AJ_ADAPTER'])
+ @@managers[ENV["AJ_ADAPTER"]] ||= new(ENV["AJ_ADAPTER"])
end
def initialize(adapter_name)
diff --git a/activejob/test/support/integration/test_case_helpers.rb b/activejob/test/support/integration/test_case_helpers.rb
index fdf25c67a1..4c4c56c9da 100644
--- a/activejob/test/support/integration/test_case_helpers.rb
+++ b/activejob/test/support/integration/test_case_helpers.rb
@@ -1,6 +1,6 @@
-require 'active_support/concern'
-require 'active_support/core_ext/string/inflections'
-require 'support/integration/jobs_manager'
+require "active_support/concern"
+require "active_support/core_ext/string/inflections"
+require "support/integration/jobs_manager"
module TestCaseHelpers
extend ActiveSupport::Concern
@@ -29,7 +29,7 @@ module TestCaseHelpers
end
def adapter_is?(*adapter_class_symbols)
- adapter = ActiveJob::Base.queue_adapter.class.name.demodulize.chomp('Adapter').underscore
+ adapter = ActiveJob::Base.queue_adapter.class.name.demodulize.chomp("Adapter").underscore
adapter_class_symbols.map(&:to_s).include? adapter
end
diff --git a/activejob/test/support/que/inline.rb b/activejob/test/support/que/inline.rb
index 0950e52d28..55eb0d01ef 100644
--- a/activejob/test/support/que/inline.rb
+++ b/activejob/test/support/que/inline.rb
@@ -1,4 +1,4 @@
-require 'que'
+require "que"
Que::Job.class_eval do
class << self; alias_method :original_enqueue, :enqueue; end
@@ -9,6 +9,6 @@ Que::Job.class_eval do
options.delete(:priority)
args << options unless options.empty?
end
- self.run(*args)
+ run(*args)
end
end
diff --git a/activejob/test/support/queue_classic/inline.rb b/activejob/test/support/queue_classic/inline.rb
index 5743d5bbb5..dcd834ecce 100644
--- a/activejob/test/support/queue_classic/inline.rb
+++ b/activejob/test/support/queue_classic/inline.rb
@@ -1,21 +1,21 @@
-require 'queue_classic'
+require "queue_classic"
module QC
class Queue
def enqueue(method, *args)
- receiver_str, _, message = method.rpartition('.')
+ receiver_str, _, message = method.rpartition(".")
receiver = eval(receiver_str)
receiver.send(message, *args)
end
def enqueue_in(seconds, method, *args)
- receiver_str, _, message = method.rpartition('.')
+ receiver_str, _, message = method.rpartition(".")
receiver = eval(receiver_str)
receiver.send(message, *args)
end
def enqueue_at(not_before, method, *args)
- receiver_str, _, message = method.rpartition('.')
+ receiver_str, _, message = method.rpartition(".")
receiver = eval(receiver_str)
receiver.send(message, *args)
end
diff --git a/activejob/test/support/sneakers/inline.rb b/activejob/test/support/sneakers/inline.rb
index 16d9b830fa..3cdc54e6d5 100644
--- a/activejob/test/support/sneakers/inline.rb
+++ b/activejob/test/support/sneakers/inline.rb
@@ -1,4 +1,4 @@
-require 'sneakers'
+require "sneakers"
module Sneakers
module Worker