diff options
author | David Heinemeier Hansson <david@basecamp.com> | 2014-05-29 16:14:28 +0200 |
---|---|---|
committer | David Heinemeier Hansson <david@basecamp.com> | 2014-05-29 16:14:28 +0200 |
commit | 79d0adef3869c1c4d9c203a4ca9e96875295fdea (patch) | |
tree | 170a585c28b1da538aa4aabe893c0e84d9f92398 /test/cases/logging_test.rb | |
parent | 895f06a2e16bb5da2d56f5bccc304d90c13836c4 (diff) | |
parent | 6eb163a706635c0ab5ede9056a0720f1a5f18f22 (diff) | |
download | rails-79d0adef3869c1c4d9c203a4ca9e96875295fdea.tar.gz rails-79d0adef3869c1c4d9c203a4ca9e96875295fdea.tar.bz2 rails-79d0adef3869c1c4d9c203a4ca9e96875295fdea.zip |
Merge pull request #61 from cristianbica/tagged-logging
Tagged logging
Diffstat (limited to 'test/cases/logging_test.rb')
-rw-r--r-- | test/cases/logging_test.rb | 57 |
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 |