Commit fd0b838b authored by Robert Speicher's avatar Robert Speicher

Merge branch 'geo-fix-node-status' into 'master'

Fix `Geo::ProjectRegistry.failed` scope to count projects where wiki sync failed.

See merge request !2747
parents 56b8d24a cdeab4be
......@@ -4,7 +4,16 @@ class Geo::ProjectRegistry < Geo::BaseRegistry
validates :project, presence: true
scope :dirty, -> { where(arel_table[:resync_repository].eq(true).or(arel_table[:resync_wiki].eq(true))) }
scope :failed, -> { where.not(last_repository_synced_at: nil).where(last_repository_successful_sync_at: nil) }
def self.failed
repository_sync_failed = arel_table[:last_repository_synced_at].not_eq(nil)
.and(arel_table[:last_repository_successful_sync_at].eq(nil))
wiki_sync_failed = arel_table[:last_wiki_synced_at].not_eq(nil)
.and(arel_table[:last_wiki_successful_sync_at].eq(nil))
where(repository_sync_failed.or(wiki_sync_failed))
end
def self.synced
where.not(last_repository_synced_at: nil, last_repository_successful_sync_at: nil)
......
---
title: Geo - Count projects where wiki sync failed in node status page
merge_request:
author:
type: fixed
......@@ -40,5 +40,23 @@ FactoryGirl.define do
resync_repository true
resync_wiki true
end
trait :repository_sync_failed do
last_repository_synced_at { 5.days.ago }
last_repository_successful_sync_at nil
last_wiki_synced_at { 5.days.ago }
last_wiki_successful_sync_at { 5.days.ago }
resync_repository true
resync_wiki false
end
trait :wiki_sync_failed do
last_repository_synced_at { 5.days.ago }
last_repository_successful_sync_at { 5.days.ago }
last_wiki_synced_at { 5.days.ago }
last_wiki_successful_sync_at nil
resync_repository false
resync_wiki true
end
end
end
......@@ -9,26 +9,26 @@ describe Geo::ProjectRegistry do
it { is_expected.to validate_presence_of(:project) }
end
describe '.synced' do
let(:project) { create(:project) }
let(:synced_at) { Time.now }
it 'does not return dirty projects' do
describe '.failed' do
it 'returns projects where last attempt to sync failed' do
project = create(:project)
create(:geo_project_registry, :synced, project: project)
create(:geo_project_registry, :synced, :dirty, project: project)
repository_sync_failed = create(:geo_project_registry, :repository_sync_failed, project: project)
wiki_sync_failed = create(:geo_project_registry, :wiki_sync_failed, project: project)
expect(described_class.synced).to be_empty
end
it 'does not return projects where last attempt to sync failed' do
create(:geo_project_registry, :sync_failed, project: project)
expect(described_class.synced).to be_empty
expect(described_class.failed).to match_array([repository_sync_failed, wiki_sync_failed])
end
end
describe '.synced' do
it 'returns synced projects' do
registry = create(:geo_project_registry, :synced, project: project)
project = create(:project)
create(:geo_project_registry, :synced, :dirty, project: project)
create(:geo_project_registry, :sync_failed, project: project)
synced_project = create(:geo_project_registry, :synced, project: project)
expect(described_class.synced).to match_array([registry])
expect(described_class.synced).to match_array([synced_project])
end
end
......
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