debian-mirror-gitlab/spec/lib/gitlab/sidekiq_logging/deduplication_logger_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

61 lines
1.8 KiB
Ruby
Raw Normal View History

2020-04-08 14:13:33 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::SidekiqLogging::DeduplicationLogger do
2020-04-08 14:13:33 +05:30
describe '#log_deduplication' do
let(:job) do
{
'class' => 'TestWorker',
'args' => [1234, 'hello', { 'key' => 'value' }],
'jid' => 'da883554ee4fe414012f5f42',
'correlation_id' => 'cid',
'duplicate-of' => 'other_jid'
}
end
it 'logs a deduplication message to the sidekiq logger' do
expected_payload = {
'job_status' => 'deduplicated',
'message' => "#{job['class']} JID-#{job['jid']}: deduplicated: a fancy strategy",
2020-07-28 23:09:34 +05:30
'deduplication.type' => 'a fancy strategy',
'deduplication.options.foo' => :bar
2020-04-08 14:13:33 +05:30
}
expect(Sidekiq.logger).to receive(:info).with(a_hash_including(expected_payload)).and_call_original
2021-12-11 22:18:48 +05:30
described_class.instance.deduplicated_log(job, "a fancy strategy", { foo: :bar })
2020-04-08 14:13:33 +05:30
end
it "does not modify the job" do
2021-12-11 22:18:48 +05:30
expect { described_class.instance.deduplicated_log(job, "a fancy strategy") }
.not_to change { job }
end
end
describe '#rescheduled_log' do
let(:job) do
{
'class' => 'TestWorker',
'args' => [1234, 'hello', { 'key' => 'value' }],
'jid' => 'da883554ee4fe414012f5f42',
'correlation_id' => 'cid'
}
end
it 'logs a rescheduled message to the sidekiq logger' do
expected_payload = {
'job_status' => 'rescheduled',
'message' => "#{job['class']} JID-#{job['jid']}: rescheduled"
}
expect(Sidekiq.logger).to receive(:info).with(a_hash_including(expected_payload)).and_call_original
described_class.instance.rescheduled_log(job)
end
it 'does not modify the job' do
expect { described_class.instance.rescheduled_log(job) }
2020-04-08 14:13:33 +05:30
.not_to change { job }
end
end
end