Skip to content

Commit d64acfd

Browse files
committed
Fix Active Job skips
Similarly to Action Mailbox, these tests didn't pass because the skip patch was included before ActiveSupport::TestCase was defined. Moving the patch to the bottom of the file fixes the issue. Once the skip patch was fixed, all of the skips were due to differences in adapters which aren't really test skips as much as tests that should not ever run against those adapters.
1 parent ec3d392 commit d64acfd

File tree

3 files changed

+71
-80
lines changed

3 files changed

+71
-80
lines changed

activejob/test/cases/queuing_test.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ class QueuingTest < ActiveSupport::TestCase
2626
result = HelloJob.set(wait_until: 1.second.ago).perform_later "Jamie"
2727
assert result
2828
rescue NotImplementedError
29-
skip
3029
end
3130

3231
test "job returned by enqueue has the arguments available" do
@@ -38,7 +37,6 @@ class QueuingTest < ActiveSupport::TestCase
3837
job = HelloJob.set(wait_until: Time.utc(2014, 1, 1)).perform_later
3938
assert_equal Time.utc(2014, 1, 1), job.scheduled_at
4039
rescue NotImplementedError
41-
skip
4240
end
4341

4442
test "job is yielded to block after enqueue with successfully_enqueued property set" do
@@ -82,7 +80,6 @@ class QueuingTest < ActiveSupport::TestCase
8280
ActiveJob.perform_all_later(scheduled_job_1, scheduled_job_2)
8381
assert_equal ["Scheduled 2014 says hello", "Scheduled 2015 says hello"], JobBuffer.values.sort
8482
rescue NotImplementedError
85-
skip
8683
end
8784

8885
test "perform_all_later instrumentation" do

activejob/test/helper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# frozen_string_literal: true
22

3-
require_relative "../../tools/test_common"
4-
53
require "active_support/testing/strict_warnings"
64
require "active_job"
75
require "support/job_buffer"
@@ -23,3 +21,5 @@
2321
def adapter_is?(*adapter_class_symbols)
2422
adapter_class_symbols.map(&:to_s).include? ActiveJob::Base.queue_adapter_name
2523
end
24+
25+
require_relative "../../tools/test_common"

activejob/test/integration/queuing_test.rb

Lines changed: 69 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -13,58 +13,60 @@ class QueuingTest < ActiveSupport::TestCase
1313
assert_job_executed
1414
end
1515

16-
test "should not run jobs queued on a non-listening queue" do
17-
skip if adapter_is?(:inline, :async, :sucker_punch)
18-
old_queue = TestJob.queue_name
19-
20-
begin
21-
TestJob.queue_as :some_other_queue
22-
TestJob.perform_later @id
23-
wait_for_jobs_to_finish_for(2.seconds)
24-
assert_job_not_executed
25-
ensure
26-
TestJob.queue_name = old_queue
16+
unless adapter_is?(:inline, :async, :sucker_punch)
17+
test "should not run jobs queued on a non-listening queue" do
18+
old_queue = TestJob.queue_name
19+
20+
begin
21+
TestJob.queue_as :some_other_queue
22+
TestJob.perform_later @id
23+
wait_for_jobs_to_finish_for(2.seconds)
24+
assert_job_not_executed
25+
ensure
26+
TestJob.queue_name = old_queue
27+
end
2728
end
2829
end
2930

30-
test "should supply a wrapped class name to Sidekiq" do
31-
skip unless adapter_is?(:sidekiq)
32-
Sidekiq::Testing.fake! do
33-
::HelloJob.perform_later
34-
hash = ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper.jobs.first
35-
assert_equal "ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper", hash["class"]
36-
assert_equal "HelloJob", hash["wrapped"]
31+
if adapter_is?(:sidekiq)
32+
test "should supply a wrapped class name to Sidekiq" do
33+
Sidekiq::Testing.fake! do
34+
::HelloJob.perform_later
35+
hash = ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper.jobs.first
36+
assert_equal "ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper", hash["class"]
37+
assert_equal "HelloJob", hash["wrapped"]
38+
end
3739
end
38-
end
3940

40-
test "should access provider_job_id inside Sidekiq job" do
41-
skip unless adapter_is?(:sidekiq)
42-
Sidekiq::Testing.inline! do
43-
job = ::ProviderJidJob.perform_later
44-
assert_equal "Provider Job ID: #{job.provider_job_id}", JobBuffer.last_value
41+
test "should access provider_job_id inside Sidekiq job" do
42+
Sidekiq::Testing.inline! do
43+
job = ::ProviderJidJob.perform_later
44+
assert_equal "Provider Job ID: #{job.provider_job_id}", JobBuffer.last_value
45+
end
4546
end
4647
end
4748

48-
test "should supply a wrapped class name to DelayedJob" do
49-
skip unless adapter_is?(:delayed_job)
50-
::HelloJob.perform_later
51-
job = Delayed::Job.first
52-
assert_match(/HelloJob \[[0-9a-f-]+\] from DelayedJob\(default\) with arguments: \[\]/, job.name)
49+
if adapter_is?(:delayed_job)
50+
test "should supply a wrapped class name to DelayedJob" do
51+
::HelloJob.perform_later
52+
job = Delayed::Job.first
53+
assert_match(/HelloJob \[[0-9a-f-]+\] from DelayedJob\(default\) with arguments: \[\]/, job.name)
54+
end
5355
end
5456

55-
test "resque JobWrapper should have instance variable queue" do
56-
skip unless adapter_is?(:resque)
57-
job = ::HelloJob.set(wait: 5.seconds).perform_later
58-
hash = Resque.decode(Resque.find_delayed_selection { true }[0])
59-
assert_equal hash["queue"], job.queue_name
57+
if adapter_is?(:resque)
58+
test "resque JobWrapper should have instance variable queue" do
59+
job = ::HelloJob.set(wait: 5.seconds).perform_later
60+
hash = Resque.decode(Resque.find_delayed_selection { true }[0])
61+
assert_equal hash["queue"], job.queue_name
62+
end
6063
end
6164

6265
test "should not run job enqueued in the future" do
6366
TestJob.set(wait: 10.minutes).perform_later @id
6467
wait_for_jobs_to_finish_for(5.seconds)
6568
assert_job_not_executed
6669
rescue NotImplementedError
67-
skip
6870
end
6971

7072
test "should run job enqueued in the future at the specified time" do
@@ -74,7 +76,6 @@ class QueuingTest < ActiveSupport::TestCase
7476
wait_for_jobs_to_finish_for(10.seconds)
7577
assert_job_executed
7678
rescue NotImplementedError
77-
skip
7879
end
7980

8081
test "should run job bulk enqueued in the future at the specified time" do
@@ -84,25 +85,22 @@ class QueuingTest < ActiveSupport::TestCase
8485
wait_for_jobs_to_finish_for(10.seconds)
8586
assert_job_executed
8687
rescue NotImplementedError
87-
skip
8888
end
8989

90-
test "should supply a provider_job_id when available for immediate jobs" do
91-
skip unless adapter_is?(:async, :delayed_job, :sidekiq, :queue_classic)
92-
test_job = TestJob.perform_later @id
93-
assert test_job.provider_job_id, "Provider job id should be set by provider"
94-
end
90+
if adapter_is?(:async, :delayed_job, :sidekiq, :queue_classic)
91+
test "should supply a provider_job_id when available for immediate jobs" do
92+
test_job = TestJob.perform_later @id
93+
assert test_job.provider_job_id, "Provider job id should be set by provider"
94+
end
9595

96-
test "should supply a provider_job_id when available for delayed jobs" do
97-
skip unless adapter_is?(:async, :delayed_job, :sidekiq, :queue_classic)
98-
delayed_test_job = TestJob.set(wait: 1.minute).perform_later @id
99-
assert delayed_test_job.provider_job_id, "Provider job id should by set for delayed jobs by provider"
96+
test "should supply a provider_job_id when available for delayed jobs" do
97+
delayed_test_job = TestJob.set(wait: 1.minute).perform_later @id
98+
assert delayed_test_job.provider_job_id, "Provider job id should by set for delayed jobs by provider"
99+
end
100100
end
101101

102-
test "current locale is kept while running perform_later" do
103-
skip if adapter_is?(:inline)
104-
105-
begin
102+
unless adapter_is?(:inline)
103+
test "current locale is kept while running perform_later" do
106104
I18n.available_locales = [:en, :de]
107105
I18n.locale = :de
108106

@@ -114,12 +112,8 @@ class QueuingTest < ActiveSupport::TestCase
114112
I18n.available_locales = [:en]
115113
I18n.locale = :en
116114
end
117-
end
118115

119-
test "current timezone is kept while running perform_later" do
120-
skip if adapter_is?(:inline)
121-
122-
begin
116+
test "current timezone is kept while running perform_later" do
123117
current_zone = Time.zone
124118
Time.zone = "Hawaii"
125119

@@ -132,28 +126,28 @@ class QueuingTest < ActiveSupport::TestCase
132126
end
133127
end
134128

135-
test "should run job with higher priority first" do
136-
skip unless adapter_is?(:delayed_job)
137-
138-
wait_until = Time.now + 3.seconds
139-
TestJob.set(wait_until: wait_until, priority: 20).perform_later "#{@id}.1"
140-
TestJob.set(wait_until: wait_until, priority: 10).perform_later "#{@id}.2"
141-
wait_for_jobs_to_finish_for(10.seconds)
142-
assert_job_executed "#{@id}.1"
143-
assert_job_executed "#{@id}.2"
144-
assert_job_executed_before("#{@id}.2", "#{@id}.1")
129+
if adapter_is?(:delayed_job)
130+
test "should run job with higher priority first" do
131+
wait_until = Time.now + 3.seconds
132+
TestJob.set(wait_until: wait_until, priority: 20).perform_later "#{@id}.1"
133+
TestJob.set(wait_until: wait_until, priority: 10).perform_later "#{@id}.2"
134+
wait_for_jobs_to_finish_for(10.seconds)
135+
assert_job_executed "#{@id}.1"
136+
assert_job_executed "#{@id}.2"
137+
assert_job_executed_before("#{@id}.2", "#{@id}.1")
138+
end
145139
end
146140

147-
test "should run job with higher priority first in Backburner" do
148-
skip unless adapter_is?(:backburner)
149-
150-
jobs_manager.tube.pause(3)
151-
TestJob.set(priority: 20).perform_later "#{@id}.1"
152-
TestJob.set(priority: 10).perform_later "#{@id}.2"
153-
wait_for_jobs_to_finish_for(10.seconds)
154-
assert_job_executed "#{@id}.1"
155-
assert_job_executed "#{@id}.2"
156-
assert_job_executed_before("#{@id}.2", "#{@id}.1")
141+
if adapter_is?(:backburner)
142+
test "should run job with higher priority first in Backburner" do
143+
jobs_manager.tube.pause(3)
144+
TestJob.set(priority: 20).perform_later "#{@id}.1"
145+
TestJob.set(priority: 10).perform_later "#{@id}.2"
146+
wait_for_jobs_to_finish_for(10.seconds)
147+
assert_job_executed "#{@id}.1"
148+
assert_job_executed "#{@id}.2"
149+
assert_job_executed_before("#{@id}.2", "#{@id}.1")
150+
end
157151
end
158152

159153
private

0 commit comments

Comments
 (0)