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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2017-05-31 07:30:51 +0300
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2017-05-31 07:30:51 +0300
commit643ca9aaa98254cc7164af178830a5cd3be3f67b (patch)
treef2f5d0e037db214b259c0ec90389e0784b9721b1 /spec/workers/geo_repository_sync_worker_spec.rb
parenta18607e42eb57bf3b57d625274f29e86b1cd43b3 (diff)
Fix GeoRepositorySyncWorker spec
Diffstat (limited to 'spec/workers/geo_repository_sync_worker_spec.rb')
-rw-r--r--spec/workers/geo_repository_sync_worker_spec.rb87
1 files changed, 87 insertions, 0 deletions
diff --git a/spec/workers/geo_repository_sync_worker_spec.rb b/spec/workers/geo_repository_sync_worker_spec.rb
new file mode 100644
index 00000000000..1fa7cfb99e2
--- /dev/null
+++ b/spec/workers/geo_repository_sync_worker_spec.rb
@@ -0,0 +1,87 @@
+require 'spec_helper'
+
+describe GeoRepositorySyncWorker do
+ let!(:primary) { create(:geo_node, :primary, host: 'primary-geo-node') }
+ let!(:secondary) { create(:geo_node, :current) }
+ let!(:project_1) { create(:empty_project) }
+ let!(:project_2) { create(:empty_project) }
+
+ subject { described_class.new }
+
+ describe '#perform' do
+ before do
+ allow_any_instance_of(Gitlab::ExclusiveLease).to receive(:try_obtain) { true }
+ end
+
+ it 'performs Geo::RepositorySyncService for each project' do
+ expect(Geo::RepositorySyncService).to receive(:new).twice.and_return(spy)
+
+ subject.perform
+ end
+
+ it 'performs Geo::RepositorySyncService for projects where last attempt to sync failed' do
+ Geo::ProjectRegistry.create(
+ project: project_1,
+ last_repository_synced_at: DateTime.now,
+ last_repository_successful_sync_at: nil
+ )
+
+ expect(Geo::RepositorySyncService).to receive(:new).twice.and_return(spy)
+
+ subject.perform
+ end
+
+ it 'performs Geo::RepositorySyncService for synced projects updated recently' do
+ Geo::ProjectRegistry.create(
+ project: project_1,
+ last_repository_synced_at: 2.days.ago,
+ last_repository_successful_sync_at: 2.days.ago
+ )
+
+ Geo::ProjectRegistry.create(
+ project: project_2,
+ last_repository_synced_at: 2.days.ago,
+ last_repository_successful_sync_at: 2.days.ago
+ )
+
+ project_1.update_attribute(:last_repository_updated_at, 2.days.ago)
+ project_2.update_attribute(:last_repository_updated_at, 10.minutes.ago)
+
+ expect(Geo::RepositorySyncService).to receive(:new).once.and_return(spy)
+
+ subject.perform
+ end
+
+ it 'does not perform Geo::RepositorySyncService when tracking DB is not available' do
+ allow(Rails.configuration).to receive(:respond_to?).with(:geo_database) { false }
+
+ expect(Geo::RepositorySyncService).not_to receive(:new)
+
+ subject.perform
+ end
+
+ it 'does not perform Geo::RepositorySyncService when primary node does not exists' do
+ allow(Gitlab::Geo).to receive(:primary_node) { nil }
+
+ expect(Geo::RepositorySyncService).not_to receive(:new)
+
+ subject.perform
+ end
+
+ it 'does not perform Geo::RepositorySyncService when node is disabled' do
+ allow_any_instance_of(GeoNode).to receive(:enabled?) { false }
+
+ expect(Geo::RepositorySyncService).not_to receive(:new)
+
+ subject.perform
+ end
+
+ it 'does not perform Geo::RepositorySyncService when can not obtain a lease' do
+ allow_any_instance_of(Gitlab::ExclusiveLease).to receive(:try_obtain) { false }
+
+ expect(Geo::RepositorySyncService).not_to receive(:new)
+
+ subject.perform
+ end
+ end
+end