[ActiveJob] Fix tests for sucker_punch

This commit is contained in:
Abdelkader Boudih 2014-08-17 13:23:24 +00:00
parent 2f7b239fca
commit 931cfc4079
8 changed files with 32 additions and 12 deletions

View File

@ -4,12 +4,12 @@ require 'models/person'
class JobSerializationTest < ActiveSupport::TestCase
setup do
Thread.current[:ajbuffer] = []
JobBuffer.clear
@person = Person.find(5)
end
test 'serialize job with gid' do
GidJob.enqueue @person
assert_equal "Person with ID: 5", Thread.current[:ajbuffer].pop
assert_equal "Person with ID: 5", JobBuffer.last_value
end
end

View File

@ -23,7 +23,7 @@ class AdapterTest < ActiveSupport::TestCase
def setup
super
Thread.current[:ajbuffer] = []
JobBuffer.clear
@old_logger = ActiveJob::Base.logger
@logger = ActiveSupport::TaggedLogging.new(TestLogger.new)
set_logger @logger

View File

@ -5,17 +5,17 @@ require 'active_support/core_ext/numeric/time'
class QueuingTest < ActiveSupport::TestCase
setup do
Thread.current[:ajbuffer] = []
JobBuffer.clear
end
test 'run queued job' do
HelloJob.enqueue
assert_equal "David says hello", Thread.current[:ajbuffer].pop
assert_equal "David says hello", JobBuffer.last_value
end
test 'run queued job with arguments' do
HelloJob.enqueue "Jamie"
assert_equal "Jamie says hello", Thread.current[:ajbuffer].pop
assert_equal "Jamie says hello", JobBuffer.last_value
end
test 'run queued job later' do

View File

@ -5,13 +5,13 @@ require 'active_support/core_ext/object/inclusion'
class RescueTest < ActiveSupport::TestCase
setup do
Thread.current[:ajbuffer] = []
JobBuffer.clear
end
test 'rescue perform exception with retry' do
job = RescueJob.new
job.execute(SecureRandom.uuid, "david")
assert_equal [ "rescued from ArgumentError", "performed beautifully" ], Thread.current[:ajbuffer]
assert_equal [ "rescued from ArgumentError", "performed beautifully" ], JobBuffer.values
end
test 'let through unhandled perform exception' do

View File

@ -28,3 +28,23 @@ require "adapters/#{@adapter}"
require 'active_support/testing/autorun'
ActiveJob::Base.logger.level = Logger::DEBUG
module JobBuffer
class << self
def clear
@buffer = []
end
def add(value)
@buffer << value
end
def values
@buffer
end
def last_value
@buffer.last
end
end
end

View File

@ -1,6 +1,6 @@
class GidJob < ActiveJob::Base
def perform(person)
Thread.current[:ajbuffer] << "Person with ID: #{person.id}"
JobBuffer.add("Person with ID: #{person.id}")
end
end

View File

@ -1,5 +1,5 @@
class HelloJob < ActiveJob::Base
def perform(greeter = "David")
Thread.current[:ajbuffer] << "#{greeter} says hello"
JobBuffer.add("#{greeter} says hello")
end
end

View File

@ -2,7 +2,7 @@ class RescueJob < ActiveJob::Base
class OtherError < StandardError; end
rescue_from(ArgumentError) do
Thread.current[:ajbuffer] << "rescued from ArgumentError"
JobBuffer.add('rescued from ArgumentError')
arguments[0] = "DIFFERENT!"
retry_now
end
@ -14,7 +14,7 @@ class RescueJob < ActiveJob::Base
when "other"
raise OtherError
else
Thread.current[:ajbuffer] << "performed beautifully"
JobBuffer.add('performed beautifully')
end
end
end