BigW Consortium Gitlab

Commit 04908026 by Toon Claes

Use push events again to determine if repo needs checking

parent ca29aa11
......@@ -32,16 +32,8 @@ module RepositoryCheck
# array of ID's. This is OK because we do it only once an hour, because
# getting ID's from Postgres is not terribly slow, and because no user
# has to sit and wait for this query to finish.
def project_ids(batch_size = BATCH_SIZE)
project_ids = never_checked_project_ids(batch_size)
remaining_capacity = batch_size - project_ids.count
if remaining_capacity > 0
project_ids + old_checked_project_ids(remaining_capacity)
else
project_ids
end
def project_ids
never_checked_project_ids(BATCH_SIZE) + old_checked_project_ids(BATCH_SIZE)
end
def never_checked_project_ids(batch_size)
......
......@@ -24,18 +24,13 @@ module RepositoryCheck
end
def repo_healthy?(project)
return true if project.empty_repo?
return true unless has_changes?(project)
git_fsck(project.repository)
end
def wiki_repo_healthy?(project)
return true unless project.wiki_enabled?
# Historically some projects never had their wiki repos initialized;
# this happens on project creation now. Let's initialize an empty repo
# if it is not already there.
project.create_wiki
return true unless has_wiki_changes?(project)
git_fsck(project.wiki.repository)
end
......@@ -51,8 +46,19 @@ module RepositoryCheck
false
end
def has_pushes?(project)
def has_changes?(project)
Project.with_push.exists?(project.id)
end
def has_wiki_changes?(project)
return false unless project.wiki_enabled?
# Historically some projects never had their wiki repos initialized;
# this happens on project creation now. Let's initialize an empty repo
# if it is not already there.
return false unless project.create_wiki
has_changes?(project)
end
end
end
......@@ -4,8 +4,10 @@ require 'fileutils'
describe RepositoryCheck::SingleRepositoryWorker do
subject(:worker) { described_class.new }
it 'skips when the project repo is empty' do
project = create(:project, :wiki_disabled)
it 'skips when the project has no push events' do
project = create(:project, :repository, :wiki_disabled)
project.events.destroy_all
break_project(project)
expect(worker).not_to receive(:git_fsck)
......@@ -14,8 +16,19 @@ describe RepositoryCheck::SingleRepositoryWorker do
expect(project.reload.last_repository_check_failed).to eq(false)
end
it 'fails when the project has push events and a broken repository' do
project = create(:project, :repository)
create_push_event(project)
break_project(project)
worker.perform(project.id)
expect(project.reload.last_repository_check_failed).to eq(true)
end
it 'succeeds when the project repo is valid' do
project = create(:project, :repository, :wiki_disabled)
create_push_event(project)
expect(worker).to receive(:git_fsck).and_call_original
......@@ -26,18 +39,10 @@ describe RepositoryCheck::SingleRepositoryWorker do
expect(project.reload.last_repository_check_failed).to eq(false)
end
it 'fails when the project is not empty and a broken repository' do
project = create(:project, :repository)
break_project(project)
worker.perform(project.id)
expect(project.reload.last_repository_check_failed).to eq(true)
end
it 'fails if the wiki repository is broken' do
project = create(:project, :wiki_enabled)
project = create(:project, :repository, :wiki_enabled)
project.create_wiki
create_push_event(project)
# Test sanity: everything should be fine before the wiki repo is broken
worker.perform(project.id)
......@@ -78,6 +83,10 @@ describe RepositoryCheck::SingleRepositoryWorker do
expect(Gitlab::Shell.new.exists?(project.repository_storage, project.wiki.path)).to eq(false)
end
def create_push_event(project)
project.events.create(action: Event::PUSHED, author_id: create(:user).id)
end
def break_wiki(project)
break_repo(wiki_path(project))
end
......@@ -90,6 +99,7 @@ describe RepositoryCheck::SingleRepositoryWorker do
break_repo(project.repository.path_to_repo)
end
def break_repo(repo)
# Create or replace blob ffffffffffffffffffffffffffffffffffffffff with an empty file
# This will make the repo invalid, _and_ 'git init' cannot fix it.
......
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