aboutsummaryrefslogtreecommitdiffstats
path: root/test/cases/logging_test.rb
diff options
context:
space:
mode:
authorCristian Bica <cristian.bica@gmail.com>2014-05-22 23:38:01 +0300
committerCristian Bica <cristian.bica@gmail.com>2014-05-29 00:05:33 +0300
commit6eb163a706635c0ab5ede9056a0720f1a5f18f22 (patch)
tree0d451047a6f4e6b375b96e145fe185b92b1c8453 /test/cases/logging_test.rb
parente597867bb3abcb9fdd95044e0b557549f6922746 (diff)
downloadrails-6eb163a706635c0ab5ede9056a0720f1a5f18f22.tar.gz
rails-6eb163a706635c0ab5ede9056a0720f1a5f18f22.tar.bz2
rails-6eb163a706635c0ab5ede9056a0720f1a5f18f22.zip
Tagged logging
Diffstat (limited to 'test/cases/logging_test.rb')
-rw-r--r--test/cases/logging_test.rb57
1 files changed, 51 insertions, 6 deletions
diff --git a/test/cases/logging_test.rb b/test/cases/logging_test.rb
index fa9430436d..194944db11 100644
--- a/test/cases/logging_test.rb
+++ b/test/cases/logging_test.rb
@@ -1,15 +1,30 @@
require 'helper'
require "active_support/log_subscriber/test_helper"
+require 'jobs/logging_job'
+require 'jobs/nested_job'
class AdapterTest < ActiveSupport::TestCase
include ActiveSupport::LogSubscriber::TestHelper
include ActiveSupport::Logger::Severity
+ class TestLogger < ActiveSupport::Logger
+ def initialize
+ @file = StringIO.new
+ super(@file)
+ end
+
+ def messages
+ @file.rewind
+ @file.read
+ end
+ end
+
def setup
super
$BUFFER = []
@old_logger = ActiveJob::Base.logger
- ActiveJob::Base.logger = @logger
+ @logger = ActiveSupport::TaggedLogging.new(TestLogger.new)
+ set_logger @logger
ActiveJob::Logging::LogSubscriber.attach_to :active_job
end
@@ -23,26 +38,56 @@ class AdapterTest < ActiveSupport::TestCase
ActiveJob::Base.logger = logger
end
+
+ def test_uses_active_job_as_tag
+ HelloJob.enqueue "Cristian"
+ assert_match(/\[ActiveJob\]/, @logger.messages)
+ end
+
def test_enqueue_job_logging
HelloJob.enqueue "Cristian"
- assert_match(/Enqueued HelloJob to .*?:.*Cristian/, @logger.logged(:info).join)
+ assert_match(/Enqueued HelloJob to .*?:.*Cristian/, @logger.messages)
end
def test_perform_job_logging
- HelloJob.enqueue "Cristian"
- assert_match(/Performed HelloJob from .*?:.*Cristian/, @logger.logged(:info).join)
+ LoggingJob.enqueue "Dummy"
+ assert_match(/Performing LoggingJob from .*? with arguments:.*Dummy/, @logger.messages)
+ assert_match(/Dummy, here is it: Dummy/, @logger.messages)
+ assert_match(/Performed LoggingJob from .*? in .*ms/, @logger.messages)
+ end
+
+ def test_perform_uses_job_name_job_logging
+ LoggingJob.enqueue "Dummy"
+ assert_match(/\[LoggingJob\]/, @logger.messages)
+ end
+
+ def test_perform_uses_job_id_job_logging
+ LoggingJob.enqueue "Dummy"
+ assert_match(/\[LOGGING-JOB-ID\]/, @logger.messages)
+ end
+
+ def test_perform_nested_jobs_logging
+ NestedJob.enqueue
+ assert_match(/\[LoggingJob\] \[.*?\]/, @logger.messages)
+ assert_match(/\[ActiveJob\] Enqueued NestedJob to/, @logger.messages)
+ assert_match(/\[ActiveJob\] \[NestedJob\] \[NESTED-JOB-ID\] Performing NestedJob from/, @logger.messages)
+ assert_match(/\[ActiveJob\] \[NestedJob\] \[NESTED-JOB-ID\] Enqueued LoggingJob to .* with arguments: "NestedJob"/, @logger.messages)
+ assert_match(/\[ActiveJob\].*\[LoggingJob\] \[LOGGING-JOB-ID\] Performing LoggingJob from .* with arguments: "NestedJob"/, @logger.messages)
+ assert_match(/\[ActiveJob\].*\[LoggingJob\] \[LOGGING-JOB-ID\] Dummy, here is it: NestedJob/, @logger.messages)
+ assert_match(/\[ActiveJob\].*\[LoggingJob\] \[LOGGING-JOB-ID\] Performed LoggingJob from .* in/, @logger.messages)
+ assert_match(/\[ActiveJob\] \[NestedJob\] \[NESTED-JOB-ID\] Performed NestedJob from .* in/, @logger.messages)
end
def test_enqueue_at_job_logging
HelloJob.enqueue_at 1, "Cristian"
- assert_match(/Enqueued HelloJob to .*? at.*Cristian/, @logger.logged(:info).join)
+ assert_match(/Enqueued HelloJob to .*? at.*Cristian/, @logger.messages)
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)
+ assert_match(/Enqueued HelloJob to .*? at.*Cristian/, @logger.messages)
rescue NotImplementedError
skip
end