diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-29 03:07:44 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-29 03:07:44 +0300 |
commit | e56fd471503e00167ca96e7792f75a0d1f3b7891 (patch) | |
tree | 87b8b69ea03c78beb5be85c5080c73f601ecc718 /spec/lib/gitlab/sidekiq_logging | |
parent | 8831c2df7fa3f1bb567e284e4b8c0a4f441e74b3 (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/structured_logger_spec.rb | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/spec/lib/gitlab/sidekiq_logging/structured_logger_spec.rb b/spec/lib/gitlab/sidekiq_logging/structured_logger_spec.rb index f294d7f7fcd..4b012f4f83d 100644 --- a/spec/lib/gitlab/sidekiq_logging/structured_logger_spec.rb +++ b/spec/lib/gitlab/sidekiq_logging/structured_logger_spec.rb @@ -30,6 +30,7 @@ describe Gitlab::SidekiqLogging::StructuredLogger do let(:clock_thread_cputime_end) { 1.333333799 } let(:start_payload) do job.except('error_backtrace', 'error_class', 'error_message').merge( + 'args' => job['args'].map(&:to_s), 'message' => 'TestWorker JID-da883554ee4fe414012f5f42: start', 'job_status' => 'start', 'pid' => Process.pid, @@ -99,13 +100,29 @@ describe Gitlab::SidekiqLogging::StructuredLogger do end end + context 'when the job args contain non-string objects' do + it 'converts them to strings' do + Timecop.freeze(timestamp) do + job['args'] = [2, true, 'foo', { "foo" => "bar" }] + expected_args = ['2', 'true', 'foo', '{"foo"=>"bar"}'] + + expect(logger).to receive(:info).with(start_payload.merge('args' => expected_args)).ordered + expect(logger).to receive(:info).with(end_payload.merge('args' => expected_args)).ordered + expect(subject).to receive(:log_job_start).and_call_original + expect(subject).to receive(:log_job_done).and_call_original + + subject.call(job, 'test_queue') { } + end + end + end + context 'when the job args are bigger than the maximum allowed' do it 'keeps args from the front until they exceed the limit' do Timecop.freeze(timestamp) do half_limit = Gitlab::Utils::LogLimitedArray::MAXIMUM_ARRAY_LENGTH / 2 job['args'] = [1, 2, 'a' * half_limit, 'b' * half_limit, 3] - expected_args = job['args'].take(3) + ['...'] + expected_args = job['args'].map(&:to_s).take(3) + ['...'] expect(logger).to receive(:info).with(start_payload.merge('args' => expected_args)).ordered expect(logger).to receive(:info).with(end_payload.merge('args' => expected_args)).ordered |