diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-09-24 12:06:04 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-09-24 12:06:04 +0300 |
commit | bc89882970d6a14b1f72eb9c715fae90b26d066c (patch) | |
tree | f5cb59d5130d7585980eb39437071e07ebc12f87 /spec/lib/gitlab/sidekiq_logging | |
parent | 4a45a787703cb78c6101750cfbdc9f656b934b42 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab/sidekiq_logging')
-rw-r--r-- | spec/lib/gitlab/sidekiq_logging/exception_handler_spec.rb | 44 | ||||
-rw-r--r-- | spec/lib/gitlab/sidekiq_logging/structured_logger_spec.rb | 3 |
2 files changed, 45 insertions, 2 deletions
diff --git a/spec/lib/gitlab/sidekiq_logging/exception_handler_spec.rb b/spec/lib/gitlab/sidekiq_logging/exception_handler_spec.rb new file mode 100644 index 00000000000..24b6090cb19 --- /dev/null +++ b/spec/lib/gitlab/sidekiq_logging/exception_handler_spec.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::SidekiqLogging::ExceptionHandler do + describe '#call' do + let(:job) do + { + "class" => "TestWorker", + "args" => [1234, 'hello'], + "retry" => false, + "queue" => "cronjob:test_queue", + "queue_namespace" => "cronjob", + "jid" => "da883554ee4fe414012f5f42", + "correlation_id" => 'cid' + } + end + + let(:exception_message) { 'An error was thrown' } + let(:backtrace) { caller } + let(:exception) { RuntimeError.new(exception_message) } + let(:logger) { double } + + before do + allow(Sidekiq).to receive(:logger).and_return(logger) + allow(exception).to receive(:backtrace).and_return(backtrace) + end + + subject { described_class.new.call(exception, { context: 'Test', job: job }) } + + it 'logs job data into root tree' do + expected_data = job.merge( + error_class: 'RuntimeError', + error_message: exception_message, + context: 'Test', + error_backtrace: Gitlab::Profiler.clean_backtrace(backtrace) + ) + + expect(logger).to receive(:warn).with(expected_data) + + subject + end + end +end diff --git a/spec/lib/gitlab/sidekiq_logging/structured_logger_spec.rb b/spec/lib/gitlab/sidekiq_logging/structured_logger_spec.rb index 1b89c094a6b..6e6a8e14fc9 100644 --- a/spec/lib/gitlab/sidekiq_logging/structured_logger_spec.rb +++ b/spec/lib/gitlab/sidekiq_logging/structured_logger_spec.rb @@ -47,7 +47,7 @@ describe Gitlab::SidekiqLogging::StructuredLogger do end_payload.merge( 'message' => 'TestWorker JID-da883554ee4fe414012f5f42: fail: 0.0 sec', 'job_status' => 'fail', - 'error' => ArgumentError, + 'error_class' => 'ArgumentError', 'error_message' => 'some exception' ) end @@ -86,7 +86,6 @@ describe Gitlab::SidekiqLogging::StructuredLogger do it 'logs an exception in job' do Timecop.freeze(timestamp) do expect(logger).to receive(:info).with(start_payload) - # This excludes the exception_backtrace expect(logger).to receive(:warn).with(hash_including(exception_payload)) expect(subject).to receive(:log_job_start).and_call_original expect(subject).to receive(:log_job_done).and_call_original |