Commit 648504fa authored by Michael Kozono's avatar Michael Kozono

Merge branch '250315-fix-create-repository-updated-events' into 'master'

Geo - Create repository updated events only if the repository exists

Closes #250315

See merge request gitlab-org/gitlab!42519
parents ddfe5919 cad600ad
...@@ -9,11 +9,12 @@ module Geo ...@@ -9,11 +9,12 @@ module Geo
RepositoryUpdateError = Class.new(StandardError) RepositoryUpdateError = Class.new(StandardError)
def initialize(repository, params = {}) def initialize(repository, params = {})
@project = repository.project @project = repository.project
@params = params @repository = repository
@refs = params.fetch(:refs, []) @params = params
@changes = params.fetch(:changes, []) @refs = params.fetch(:refs, [])
@source = Geo::RepositoryUpdatedEvent.source_for(repository) @changes = params.fetch(:changes, [])
@source = Geo::RepositoryUpdatedEvent.source_for(repository)
end end
def execute def execute
...@@ -27,11 +28,13 @@ module Geo ...@@ -27,11 +28,13 @@ module Geo
private private
attr_reader :project, :refs, :changes, :source attr_reader :project, :repository, :refs, :changes, :source
delegate :repository_state, to: :project delegate :repository_state, to: :project
def create_repository_updated_event! def create_repository_updated_event!
return unless repository.exists?
Geo::RepositoryUpdatedEventStore.new( Geo::RepositoryUpdatedEventStore.new(
project, refs: refs, changes: changes, source: source project, refs: refs, changes: changes, source: source
).create! ).create!
......
---
title: Geo - Create repository updated events only if the repository exists
merge_request: 42519
author:
type: fixed
...@@ -37,10 +37,18 @@ RSpec.describe Geo::RepositoryUpdatedService do ...@@ -37,10 +37,18 @@ RSpec.describe Geo::RepositoryUpdatedService do
end end
context 'when running on a primary node' do context 'when running on a primary node' do
it 'creates a repository updated event' do it 'creates a repository updated event when repository exists' do
allow(repository).to receive(:exists?).and_return(true)
expect { subject.execute }.to change(Geo::RepositoryUpdatedEvent, :count).by(1) expect { subject.execute }.to change(Geo::RepositoryUpdatedEvent, :count).by(1)
end end
it 'does not create a repository updated event when repository does not exist' do
allow(repository).to receive(:exists?).and_return(false)
expect { subject.execute }.not_to change(Geo::RepositoryUpdatedEvent, :count)
end
it 'resets the repository verification checksum' do it 'resets the repository verification checksum' do
expect { subject.execute }.to change { repository_state.reload.public_send("#{method_prefix}_verification_checksum") }.to(nil) expect { subject.execute }.to change { repository_state.reload.public_send("#{method_prefix}_verification_checksum") }.to(nil)
end end
...@@ -91,9 +99,17 @@ RSpec.describe Geo::RepositoryUpdatedService do ...@@ -91,9 +99,17 @@ RSpec.describe Geo::RepositoryUpdatedService do
context 'when design repository is being updated' do context 'when design repository is being updated' do
let(:repository) { project.design_repository } let(:repository) { project.design_repository }
it 'creates a design repository updated event' do it 'creates a design repository updated event when repository exists' do
allow(repository).to receive(:exists?).and_return(true)
expect { subject.execute }.to change(Geo::RepositoryUpdatedEvent, :count).by(1) expect { subject.execute }.to change(Geo::RepositoryUpdatedEvent, :count).by(1)
end end
it 'does not create a repository updated event when repository does not exist' do
allow(repository).to receive(:exists?).and_return(false)
expect { subject.execute }.not_to change(Geo::RepositoryUpdatedEvent, :count)
end
end end
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