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

client_spec.rb « duplicate_jobs « sidekiq_middleware « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4d12e4b3f6f770a7d71b57c63a3db44fa8351230 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::SidekiqMiddleware::DuplicateJobs::Client, :clean_gitlab_redis_queues do
  shared_context 'deduplication worker class' do |strategy, including_scheduled|
    let(:worker_class) do
      Class.new do
        def self.name
          'TestDeduplicationWorker'
        end

        include ApplicationWorker

        deduplicate strategy, including_scheduled: including_scheduled

        include ApplicationWorker

        def perform(*args)
        end
      end
    end

    before do
      stub_const('TestDeduplicationWorker', worker_class)
    end
  end

  shared_examples 'client duplicate job' do |strategy|
    describe '#call' do
      include_context 'deduplication worker class', strategy, false

      it 'adds a correct duplicate tag to the jobs', :aggregate_failures do
        TestDeduplicationWorker.bulk_perform_async([['args1'], ['args2'], ['args1']])

        job1, job2, job3 = TestDeduplicationWorker.jobs

        expect(job1['duplicate-of']).to be_nil
        expect(job2['duplicate-of']).to be_nil
        expect(job3['duplicate-of']).to eq(job1['jid'])
      end

      context 'without scheduled deduplication' do
        it "does not mark a job that's scheduled in the future as a duplicate" do
          TestDeduplicationWorker.perform_async('args1')
          TestDeduplicationWorker.perform_at(1.day.from_now, 'args1')
          TestDeduplicationWorker.perform_in(3.hours, 'args1')

          duplicates = TestDeduplicationWorker.jobs.map { |job| job['duplicate-of'] }

          expect(duplicates).to all(be_nil)
        end
      end

      context 'with scheduled deduplication' do
        include_context 'deduplication worker class', strategy, true

        before do
          stub_const('TestDeduplicationWorker', worker_class)
        end

        it 'adds a correct duplicate tag to the jobs', :aggregate_failures do
          TestDeduplicationWorker.perform_async('args1')
          TestDeduplicationWorker.perform_at(1.day.from_now, 'args1')
          TestDeduplicationWorker.perform_in(3.hours, 'args1')
          TestDeduplicationWorker.perform_in(3.hours, 'args2')

          job1, job2, job3, job4 = TestDeduplicationWorker.jobs

          expect(job1['duplicate-of']).to be_nil
          expect(job2['duplicate-of']).to eq(job1['jid'])
          expect(job3['duplicate-of']).to eq(job1['jid'])
          expect(job4['duplicate-of']).to be_nil
        end
      end
    end
  end

  context 'with until_executing strategy' do
    it_behaves_like 'client duplicate job', :until_executing
  end

  context 'with until_executed strategy' do
    it_behaves_like 'client duplicate job', :until_executed
  end
end