summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/sidekiq_death_handler_spec.rb
blob: 96fef88de4e3657b9b20e29266b95131acf37e3c (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
44
45
46
47
48
49
50
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::SidekiqDeathHandler, :clean_gitlab_redis_queues do
  describe '.handler' do
    context 'when the job class has worker attributes' do
      let(:test_worker) do
        Class.new do
          include WorkerAttributes

          urgency :low
          worker_has_external_dependencies!
          worker_resource_boundary :cpu
          feature_category :users
        end
      end

      before do
        stub_const('TestWorker', test_worker)
      end

      it 'uses the attributes from the worker' do
        expect(described_class.counter)
          .to receive(:increment)
                .with(queue: 'test_queue', worker: 'TestWorker',
                      urgency: 'low', external_dependencies: 'yes',
                      feature_category: 'users', boundary: 'cpu')

        described_class.handler({ 'class' => 'TestWorker', 'queue' => 'test_queue' }, nil)
      end
    end

    context 'when the job class does not have worker attributes' do
      before do
        stub_const('TestWorker', Class.new)
      end

      it 'uses blank attributes' do
        expect(described_class.counter)
          .to receive(:increment)
                .with(queue: 'test_queue', worker: 'TestWorker',
                      urgency: '', external_dependencies: 'no',
                      feature_category: '', boundary: '')

        described_class.handler({ 'class' => 'TestWorker', 'queue' => 'test_queue' }, nil)
      end
    end
  end
end