Commit 33ed8a64 authored by Michael Kozono's avatar Michael Kozono

Merge branch...

Merge branch '211990-geo-self-service-framework-does-not-associate-geo_event_log-row-to-geo_event' into 'master'

Geo: Fix geo_event_log and geo_event association

Closes #211990

See merge request gitlab-org/gitlab!28457
parents 853193be a156f018
...@@ -72,10 +72,10 @@ module Geo ...@@ -72,10 +72,10 @@ module Geo
class_name: 'Geo::ContainerRepositoryUpdatedEvent', class_name: 'Geo::ContainerRepositoryUpdatedEvent',
foreign_key: :container_repository_updated_event_id foreign_key: :container_repository_updated_event_id
belongs_to :event, belongs_to :geo_event,
class_name: 'Geo::Event', class_name: 'Geo::Event',
foreign_key: :geo_event_id foreign_key: :geo_event_id,
inverse_of: :geo_event_log
def self.latest_event def self.latest_event
order(id: :desc).first order(id: :desc).first
end end
...@@ -95,6 +95,7 @@ module Geo ...@@ -95,6 +95,7 @@ module Geo
includes(reflections.keys) includes(reflections.keys)
end end
# rubocop:disable Metrics/CyclomaticComplexity
def event def event
repository_created_event || repository_created_event ||
repository_updated_event || repository_updated_event ||
...@@ -108,8 +109,10 @@ module Geo ...@@ -108,8 +109,10 @@ module Geo
upload_deleted_event || upload_deleted_event ||
reset_checksum_event || reset_checksum_event ||
cache_invalidation_event || cache_invalidation_event ||
container_repository_updated_event container_repository_updated_event ||
geo_event
end end
# rubocop:enable Metrics/CyclomaticComplexity
def project_id def project_id
event.try(:project_id) event.try(:project_id)
......
---
title: 'Geo: Self-service framework does not associate geo_event_log row to geo_event'
merge_request: 28457
author:
type: fixed
...@@ -135,7 +135,7 @@ module Gitlab ...@@ -135,7 +135,7 @@ module Gitlab
# Only works with the new geo_events at the moment because we need to # Only works with the new geo_events at the moment because we need to
# know which foreign key to use # know which foreign key to use
::Geo::EventLog.create!(geo_event_id: event) ::Geo::EventLog.create!(geo_event: event)
event event
rescue ActiveRecord::RecordInvalid, NoMethodError => e rescue ActiveRecord::RecordInvalid, NoMethodError => e
......
...@@ -54,7 +54,7 @@ FactoryBot.define do ...@@ -54,7 +54,7 @@ FactoryBot.define do
repository_updated_event factory: :geo_design_repository_updated_event repository_updated_event factory: :geo_design_repository_updated_event
end end
trait :event do trait :geo_event do
event factory: :geo_event event factory: :geo_event
end end
end end
......
...@@ -5,7 +5,7 @@ require "spec_helper" ...@@ -5,7 +5,7 @@ require "spec_helper"
describe Gitlab::Geo::LogCursor::Events::Event, :clean_gitlab_redis_shared_state do describe Gitlab::Geo::LogCursor::Events::Event, :clean_gitlab_redis_shared_state do
let(:logger) { Gitlab::Geo::LogCursor::Logger.new(described_class, Logger::INFO) } let(:logger) { Gitlab::Geo::LogCursor::Logger.new(described_class, Logger::INFO) }
let(:event) { create(:geo_event, :package_file, event_name: "created" ) } let(:event) { create(:geo_event, :package_file, event_name: "created" ) }
let(:event_log) { create(:geo_event_log, event: event) } let(:event_log) { create(:geo_event_log, geo_event: event) }
let(:replicable) { Packages::PackageFile.find(event.payload["model_record_id"]) } let(:replicable) { Packages::PackageFile.find(event.payload["model_record_id"]) }
let!(:event_log_state) { create(:geo_event_log_state, event_id: event_log.id - 1) } let!(:event_log_state) { create(:geo_event_log_state, event_id: event_log.id - 1) }
......
...@@ -3,6 +3,11 @@ ...@@ -3,6 +3,11 @@
require 'spec_helper' require 'spec_helper'
describe Gitlab::Geo::Replicator do describe Gitlab::Geo::Replicator do
include ::EE::GeoHelpers
let_it_be(:primary_node) { create(:geo_node, :primary) }
let_it_be(:secondary_node) { create(:geo_node) }
context 'with defined events' do context 'with defined events' do
before do before do
stub_const('DummyReplicator', Class.new(Gitlab::Geo::Replicator)) stub_const('DummyReplicator', Class.new(Gitlab::Geo::Replicator))
...@@ -86,8 +91,12 @@ describe Gitlab::Geo::Replicator do ...@@ -86,8 +91,12 @@ describe Gitlab::Geo::Replicator do
end end
context 'when publishing a supported events with required params' do context 'when publishing a supported events with required params' do
it 'does not raise errors' do it 'creates event with associated event log record' do
expect { subject.publish(:test, other: true) }.not_to raise_error stub_current_geo_node(primary_node)
expect { subject.publish(:test, other: true) }.to change { ::Geo::EventLog.count }.from(0).to(1)
expect(::Geo::EventLog.last.event).to be_a(::Geo::Event)
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