From 3fe95c82bc108eee5a615698c6796389cdca6d51 Mon Sep 17 00:00:00 2001 From: Cristian Bica Date: Thu, 22 May 2014 14:19:48 +0300 Subject: [PATCH] Added tests for logging --- lib/active_job/enqueuing.rb | 2 +- lib/active_job/logging.rb | 4 +-- test/cases/logging_test.rb | 49 +++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 test/cases/logging_test.rb diff --git a/lib/active_job/enqueuing.rb b/lib/active_job/enqueuing.rb index dafa2399c8..652de5521b 100644 --- a/lib/active_job/enqueuing.rb +++ b/lib/active_job/enqueuing.rb @@ -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. diff --git a/lib/active_job/logging.rb b/lib/active_job/logging.rb index 22748e3d5f..dc432679f8 100644 --- a/lib/active_job/logging.rb +++ b/lib/active_job/logging.rb @@ -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 diff --git a/test/cases/logging_test.rb b/test/cases/logging_test.rb new file mode 100644 index 0000000000..95d3f1c6f1 --- /dev/null +++ b/test/cases/logging_test.rb @@ -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