Commit a531a2d9 authored by Gabriel Mazetto's avatar Gabriel Mazetto

Improved BaseSyncService specs

parent 8311839f
...@@ -31,6 +31,10 @@ module Geo ...@@ -31,6 +31,10 @@ module Geo
private private
def sync_repository
raise NotImplementedError, 'This class should implement sync_repository method'
end
def registry def registry
@registry ||= Geo::ProjectRegistry.find_or_initialize_by(project_id: project.id) @registry ||= Geo::ProjectRegistry.find_or_initialize_by(project_id: project.id)
end end
......
require 'spec_helper' require 'spec_helper'
describe Geo::BaseSyncService, services: true do describe Geo::BaseSyncService, services: true do
let(:project) { double('project')} let(:project) { build('project')}
subject { described_class.new(project) } subject { described_class.new(project) }
describe '#execute' do
context 'when can acquire exclusive lease' do
before do
allow_any_instance_of(Gitlab::ExclusiveLease).to receive(:try_obtain) { 12345 }
end
it 'executes the synchronization' do
expect(subject).to receive(:sync_repository)
subject.execute
end
end
context 'when exclusive lease is not acquired' do
before do
allow_any_instance_of(Gitlab::ExclusiveLease).to receive(:try_obtain) { nil }
end
it 'is does not execute synchronization' do
expect(subject).not_to receive(:sync_repository)
subject.execute
end
end
end
describe '#lease_key' do
it 'returns a key in the correct pattern' do
described_class.type = :test
allow(project).to receive(:id) { 999 }
expect(subject.lease_key).to eq('geo_sync_service:test:999')
end
end
describe '#primary_ssh_path_prefix' do describe '#primary_ssh_path_prefix' do
let!(:primary_node) { create(:geo_node, :primary, host: 'primary-geo-node') } let!(:primary_node) { create(:geo_node, :primary, host: 'primary-geo-node') }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment