mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Moved AR testing from using global variable to thread variable
This commit is contained in:
parent
c2f1eca194
commit
788aee5acf
7 changed files with 15 additions and 15 deletions
|
@ -4,12 +4,12 @@ require 'models/person'
|
|||
|
||||
class JobSerializationTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
$BUFFER = []
|
||||
Thread.current[:ajbuffer] = []
|
||||
@person = Person.find(5)
|
||||
end
|
||||
|
||||
test 'serialize job with gid' do
|
||||
GidJob.enqueue @person
|
||||
assert_equal "Person with ID: 5", $BUFFER.pop
|
||||
assert_equal "Person with ID: 5", Thread.current[:ajbuffer].pop
|
||||
end
|
||||
end
|
||||
|
|
|
@ -23,7 +23,7 @@ class AdapterTest < ActiveSupport::TestCase
|
|||
|
||||
def setup
|
||||
super
|
||||
$BUFFER = []
|
||||
Thread.current[:ajbuffer] = []
|
||||
@old_logger = ActiveJob::Base.logger
|
||||
@logger = ActiveSupport::TaggedLogging.new(TestLogger.new)
|
||||
set_logger @logger
|
||||
|
|
|
@ -5,17 +5,17 @@ require 'active_support/core_ext/numeric/time'
|
|||
|
||||
class QueuingTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
$BUFFER = []
|
||||
Thread.current[:ajbuffer] = []
|
||||
end
|
||||
|
||||
test 'run queued job' do
|
||||
HelloJob.enqueue
|
||||
assert_equal "David says hello", $BUFFER.pop
|
||||
assert_equal "David says hello", Thread.current[:ajbuffer].pop
|
||||
end
|
||||
|
||||
test 'run queued job with arguments' do
|
||||
HelloJob.enqueue "Jamie"
|
||||
assert_equal "Jamie says hello", $BUFFER.pop
|
||||
assert_equal "Jamie says hello", Thread.current[:ajbuffer].pop
|
||||
end
|
||||
|
||||
test 'run queued job later' do
|
||||
|
|
|
@ -5,13 +5,13 @@ require 'active_support/core_ext/object/inclusion'
|
|||
|
||||
class RescueTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
$BUFFER = []
|
||||
Thread.current[:ajbuffer] = []
|
||||
end
|
||||
|
||||
test 'rescue perform exception with retry' do
|
||||
job = RescueJob.new
|
||||
job.execute(SecureRandom.uuid, "david")
|
||||
assert_equal [ "rescued from ArgumentError", "performed beautifully" ], $BUFFER
|
||||
assert_equal [ "rescued from ArgumentError", "performed beautifully" ], Thread.current[:ajbuffer]
|
||||
end
|
||||
|
||||
test 'let through unhandled perform exception' do
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
class GidJob < ActiveJob::Base
|
||||
def perform(person)
|
||||
$BUFFER << "Person with ID: #{person.id}"
|
||||
Thread.current[:ajbuffer] << "Person with ID: #{person.id}"
|
||||
end
|
||||
end
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
class HelloJob < ActiveJob::Base
|
||||
def perform(greeter = "David")
|
||||
$BUFFER << "#{greeter} says hello"
|
||||
Thread.current[:ajbuffer] << "#{greeter} says hello"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@ class RescueJob < ActiveJob::Base
|
|||
class OtherError < StandardError; end
|
||||
|
||||
rescue_from(ArgumentError) do
|
||||
$BUFFER << "rescued from ArgumentError"
|
||||
Thread.current[:ajbuffer] << "rescued from ArgumentError"
|
||||
arguments[0] = "DIFFERENT!"
|
||||
retry_now
|
||||
end
|
||||
|
@ -14,7 +14,7 @@ class RescueJob < ActiveJob::Base
|
|||
when "other"
|
||||
raise OtherError
|
||||
else
|
||||
$BUFFER << "performed beautifully"
|
||||
Thread.current[:ajbuffer] << "performed beautifully"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue