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

forbid_sidekiq_in_transactions_spec.rb « initializers « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6cd15d37ad4606439e24147219c3c64c7607089b (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Sidekiq::Worker' do
  let(:worker_class) do
    Class.new do
      include Sidekiq::Worker

      def perform
      end
    end
  end

  it 'allows sidekiq worker outside of a transaction' do
    expect { worker_class.perform_async }.not_to raise_error
  end

  it 'forbids queue sidekiq worker in a transaction' do
    Project.transaction do
      expect { worker_class.perform_async }.to raise_error(Sidekiq::Worker::EnqueueFromTransactionError)
    end
  end

  it 'allows sidekiq worker in a transaction if skipped' do
    Sidekiq::Worker.skipping_transaction_check do
      Project.transaction do
        expect { worker_class.perform_async }.not_to raise_error
      end
    end
  end

  it 'forbids queue sidekiq worker in a Ci::ApplicationRecord transaction' do
    Ci::Pipeline.transaction do
      expect { worker_class.perform_async }.to raise_error(Sidekiq::Worker::EnqueueFromTransactionError)
    end
  end
end