Add an event store for hashed migration events

parent 8d2fa510
module Geo
class HashedStorageMigratedEventStore < EventStore
self.event_type = :hashed_storage_migrated_event
private
def build_event
Geo::HashedStorageMigratedEvent.new(
project: project,
old_storage_version: old_storage_version,
new_storage_version: project.storage_version,
repository_storage_name: project.repository.storage,
repository_storage_path: project.repository_storage_path,
old_disk_path: old_disk_path,
new_disk_path: project.disk_path,
old_wiki_disk_path: old_wiki_disk_path,
new_wiki_disk_path: project.wiki.disk_path
)
end
def old_storage_version
params.fetch(:old_storage_version)
end
def old_disk_path
params.fetch(:old_disk_path)
end
def old_wiki_disk_path
"#{old_disk_path}.wiki"
end
end
end
require 'spec_helper'
describe Geo::HashedStorageMigratedEventStore do
set(:project) { create(:project, :hashed, path: 'bar') }
set(:secondary_node) { create(:geo_node) }
let(:old_disk_path) { "#{project.namespace.full_path}/foo" }
let(:old_wiki_disk_path) { "#{old_disk_path}.wiki" }
subject(:event_store) { described_class.new(project, old_storage_version: nil, old_disk_path: old_disk_path, old_wiki_disk_path: old_wiki_disk_path) }
describe '#create' do
it 'does not create an event when not running on a primary node' do
allow(Gitlab::Geo).to receive(:primary?) { false }
expect { event_store.create }.not_to change(Geo::HashedStorageMigratedEvent, :count)
end
context 'when running on a primary node' do
before do
allow(Gitlab::Geo).to receive(:primary?) { true }
end
it 'does not create an event when there are no secondary nodes' do
allow(Gitlab::Geo).to receive(:secondary_nodes) { [] }
expect { subject.create }.not_to change(Geo::HashedStorageMigratedEvent, :count)
end
it 'creates a hashed migration event' do
expect { event_store.create }.to change(Geo::HashedStorageMigratedEvent, :count).by(1)
end
it 'tracks project attributes' do
event_store.create
event = Geo::HashedStorageMigratedEvent.last
expect(event).to have_attributes(
repository_storage_name: project.repository_storage,
repository_storage_path: project.repository_storage_path,
old_storage_version: nil,
new_storage_version: project.storage_version,
old_disk_path: old_disk_path,
new_disk_path: project.disk_path,
old_wiki_disk_path: old_wiki_disk_path,
new_wiki_disk_path: project.wiki.disk_path
)
end
end
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