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

monitor_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: 2933d26a387caaa083918b1dba1c906b9afba0e7 (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
# frozen_string_literal: true

require 'spec_helper'

describe Gitlab::SidekiqMiddleware::Monitor do
  let(:monitor) { described_class.new }

  describe '#call' do
    let(:worker) { double }
    let(:job) { { 'jid' => 'job-id' } }
    let(:queue) { 'my-queue' }

    it 'calls SidekiqMonitor' do
      expect(Gitlab::SidekiqMonitor.instance).to receive(:within_job)
        .with('job-id', 'my-queue')
        .and_call_original

      expect { |blk| monitor.call(worker, job, queue, &blk) }.to yield_control
    end

    it 'passthroughs the return value' do
      result = monitor.call(worker, job, queue) do
        'value'
      end

      expect(result).to eq('value')
    end

    context 'when cancel happens' do
      subject do
        monitor.call(worker, job, queue) do
          raise Gitlab::SidekiqMonitor::CancelledError
        end
      end

      it 'does skip this job' do
        expect { subject }.to raise_error(Sidekiq::JobRetry::Skip)
      end
    end
  end
end