mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Added tests for logging
This commit is contained in:
parent
53410c9b40
commit
3fe95c82bc
3 changed files with 52 additions and 3 deletions
|
@ -21,7 +21,7 @@ module ActiveJob
|
|||
#
|
||||
# Returns truthy if a job was scheduled.
|
||||
def enqueue_in(interval, *args)
|
||||
enqueue_at(interval.from_now, *args)
|
||||
enqueue_at(interval.seconds.from_now, *args)
|
||||
end
|
||||
|
||||
# Enqueue a job to be performed at an explicit point in time.
|
||||
|
|
|
@ -12,7 +12,7 @@ module ActiveJob
|
|||
def enqueue_at(event)
|
||||
info "Enqueued #{event.payload[:job].name} to #{queue_name(event)} at #{enqueued_at(event)}" + args_info(event)
|
||||
end
|
||||
|
||||
|
||||
def perform(event)
|
||||
info "Performed #{event.payload[:job].name} to #{queue_name(event)}" + args_info(event)
|
||||
end
|
||||
|
@ -25,7 +25,7 @@ module ActiveJob
|
|||
def args_info(event)
|
||||
event.payload[:args].any? ? ": #{event.payload[:args].inspect}" : ""
|
||||
end
|
||||
|
||||
|
||||
def enqueued_at(event)
|
||||
Time.at(event.payload[:timestamp]).utc
|
||||
end
|
||||
|
|
49
test/cases/logging_test.rb
Normal file
49
test/cases/logging_test.rb
Normal file
|
@ -0,0 +1,49 @@
|
|||
require 'helper'
|
||||
require "active_support/log_subscriber/test_helper"
|
||||
|
||||
class AdapterTest < ActiveSupport::TestCase
|
||||
include ActiveSupport::LogSubscriber::TestHelper
|
||||
include ActiveSupport::Logger::Severity
|
||||
|
||||
def setup
|
||||
super
|
||||
$BUFFER = []
|
||||
@old_logger = ActiveJob::Base.logger
|
||||
ActiveJob::Base.logger = @logger
|
||||
ActiveJob::Logging::LogSubscriber.attach_to :active_job
|
||||
end
|
||||
|
||||
def teardown
|
||||
super
|
||||
ActiveJob::Logging::LogSubscriber.log_subscribers.pop
|
||||
ActiveJob::Base.logger = @old_logger
|
||||
end
|
||||
|
||||
def set_logger(logger)
|
||||
ActiveJob::Base.logger = logger
|
||||
end
|
||||
|
||||
def test_enqueue_job_logging
|
||||
HelloJob.enqueue "Cristian"
|
||||
assert_match(/Enqueued HelloJob to .*?:.*Cristian/, @logger.logged(:info).join)
|
||||
end
|
||||
|
||||
def test_perform_job_logging
|
||||
HelloJob.enqueue "Cristian"
|
||||
assert_match(/Performed HelloJob to .*?:.*Cristian/, @logger.logged(:info).join)
|
||||
end
|
||||
|
||||
def test_enqueue_at_job_logging
|
||||
HelloJob.enqueue_at 1, "Cristian"
|
||||
assert_match(/Enqueued HelloJob to .*? at.*Cristian/, @logger.logged(:info).join)
|
||||
rescue NotImplementedError
|
||||
skip
|
||||
end
|
||||
|
||||
def test_enqueue_in_job_logging
|
||||
HelloJob.enqueue_in 2, "Cristian"
|
||||
assert_match(/Enqueued HelloJob to .*? at.*Cristian/, @logger.logged(:info).join)
|
||||
rescue NotImplementedError
|
||||
skip
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue