File: process_sync_events_worker_spec.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (46 lines) | stat: -rw-r--r-- 1,450 bytes parent folder | download
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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Projects::ProcessSyncEventsWorker, feature_category: :cell do
  let!(:group) { create(:group) }
  let!(:project) { create(:project) }

  subject(:worker) { described_class.new }

  it_behaves_like 'an idempotent worker'

  it 'has the `until_executed` deduplicate strategy' do
    expect(described_class.get_deduplicate_strategy).to eq(:until_executed)
  end

  it 'has the option to reschedule once if deduplicated and a TTL of 1 minute' do
    expect(described_class.get_deduplication_options).to include({ if_deduplicated: :reschedule_once, ttl: 1.minute })
  end

  describe '#perform' do
    subject(:perform) { worker.perform }

    before do
      project.update!(namespace: group)
    end

    it 'consumes all sync events' do
      expect { perform }.to change { Projects::SyncEvent.count }.from(2).to(0)
    end

    it 'syncs project namespace id' do
      expect { perform }.to change { Ci::ProjectMirror.all }.to contain_exactly(
        an_object_having_attributes(namespace_id: group.id)
      )
    end

    it 'logs the service result', :aggregate_failures do
      expect(worker).to receive(:log_extra_metadata_on_done).with(:estimated_total_events, 2)
      expect(worker).to receive(:log_extra_metadata_on_done).with(:consumable_events, 2)
      expect(worker).to receive(:log_extra_metadata_on_done).with(:processed_events, 2)

      perform
    end
  end
end