Commit b2d21327 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Merge branch 'fj-6630-extract-ee-code-project-cache-worker-spec' into 'master'

Extract EE code from project_cache_worker_spec.rb

See merge request gitlab-org/gitlab-ee!10785
parents a6f1515d e9f42701
......@@ -51,4 +51,4 @@ class ProjectCacheWorker
end
end
ProjectCacheWorker.prepend(EE::Workers::ProjectCacheWorker)
ProjectCacheWorker.prepend(EE::ProjectCacheWorker)
# frozen_string_literal: true
module EE
# Geo specific code for cache re-generation
#
# This module is intended to encapsulate EE-specific methods
# and be **prepended** in the `ProjectCacheWorker` class.
module ProjectCacheWorker
def perform(*args)
if ::Gitlab::Geo.secondary?
perform_geo_secondary(*args)
else
super
end
end
private
# Geo should only update Redis based cache, as data store in the database
# will be updated on primary and replicated to the secondaries.
# rubocop: disable CodeReuse/ActiveRecord
def perform_geo_secondary(project_id, refresh = [], _statistics = [])
project = ::Project.find_by(id: project_id)
return unless project && project.repository.exists?
project.repository.refresh_method_caches(refresh.map(&:to_sym))
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
# frozen_string_literal: true
module EE
module Workers
# Geo specific code for cache re-generation
#
# This module is intended to encapsulate EE-specific methods
# and be **prepended** in the `ProjectCacheWorker` class.
module ProjectCacheWorker
def perform(*args)
if ::Gitlab::Geo.secondary?
perform_geo_secondary(*args)
else
super
end
end
private
# Geo should only update Redis based cache, as data store in the database
# will be updated on primary and replicated to the secondaries.
# rubocop: disable CodeReuse/ActiveRecord
def perform_geo_secondary(project_id, refresh = [], _statistics = [])
project = ::Project.find_by(id: project_id)
return unless project && project.repository.exists?
project.repository.refresh_method_caches(refresh.map(&:to_sym))
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe ProjectCacheWorker do
let(:worker) { described_class.new }
let(:project) { create(:project, :repository) }
describe '#perform' do
context 'with an existing project' do
context 'when in Geo secondary node' do
before do
allow(Gitlab::Geo).to receive(:secondary?).and_return(true)
end
it 'updates only non database cache' do
expect(worker).to receive(:perform_geo_secondary).and_call_original
expect_any_instance_of(Repository).to receive(:refresh_method_caches)
.and_call_original
expect_any_instance_of(Project).not_to receive(:update_repository_size)
expect_any_instance_of(Project).not_to receive(:update_commit_count)
worker.perform(project.id, %w(readme))
end
end
end
end
end
......@@ -43,22 +43,6 @@ describe ProjectCacheWorker do
worker.perform(project.id, %w(readme))
end
context 'when in Geo secondary node' do
before do
allow(Gitlab::Geo).to receive(:secondary?).and_return(true)
end
it 'updates only non database cache' do
expect_any_instance_of(Repository).to receive(:refresh_method_caches)
.and_call_original
expect_any_instance_of(Project).not_to receive(:update_repository_size)
expect_any_instance_of(Project).not_to receive(:update_commit_count)
worker.perform(project.id, %w(readme))
end
end
context 'with statistics' do
let(:statistics) { %w(repository_size) }
......
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