Welcome to mirror list, hosted at ThFree Co, Russian Federation.

extra_done_log_metadata_spec.rb « sidekiq_middleware « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5569bc01a6ad63d105b020b1b51da44b13702db9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::SidekiqMiddleware::ExtraDoneLogMetadata do
  # Cannot use Class.new for this as ApplicationWorker will need the class to
  # have a name during `included do`.
  let(:worker) { AdminEmailWorker.new }

  let(:worker_without_application_worker) do
    Class.new do
    end.new
  end

  subject { described_class.new }

  let(:job) { { 'jid' => 123 } }
  let(:queue) { 'test_queue' }

  describe '#call' do
    it 'merges Application#logging_extras in to job' do
      worker.log_extra_metadata_on_done(:key1, 15)
      worker.log_extra_metadata_on_done(:key2, 16)
      expect { |b| subject.call(worker, job, queue, &b) }.to yield_control

      expect(job).to eq({ 'jid' => 123, 'extra.admin_email_worker.key1' => 15, 'extra.admin_email_worker.key2' => 16 })
    end

    it 'does not raise when the worker does not respond to #logging_extras' do
      expect { |b| subject.call(worker_without_application_worker, job, queue, &b) }.to yield_control

      expect(job).to eq({ 'jid' => 123 })
    end

    it 'still merges logging_extras even when an error is raised during job execution' do
      worker.log_extra_metadata_on_done(:key1, 15)
      worker.log_extra_metadata_on_done(:key2, 16)
      expect { subject.call(worker, job, queue) { raise 'an error' } }.to raise_error(StandardError, 'an error')

      expect(job).to eq({ 'jid' => 123, 'extra.admin_email_worker.key1' => 15, 'extra.admin_email_worker.key2' => 16 })
    end
  end
end