Commit 10b803c2 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'mk/refactor-verify' into 'master'

Geo: Minor adjustments to verification logic

See merge request gitlab-org/gitlab!49292
parents f5aaf89a 30e6a4d8
...@@ -126,8 +126,7 @@ module Geo ...@@ -126,8 +126,7 @@ module Geo
# Calculates checksum and asks the model/registry to update verification # Calculates checksum and asks the model/registry to update verification
# state. # state.
def verify def verify
# Deduplicate verification job model_record.verification_started! unless model_record.verification_started?
return unless model_record.verification_started?
calculation_started_at = Time.current calculation_started_at = Time.current
checksum = model_record.calculate_checksum checksum = model_record.calculate_checksum
......
...@@ -81,7 +81,7 @@ module Gitlab ...@@ -81,7 +81,7 @@ module Gitlab
end end
event :verification_failed do event :verification_failed do
transition verification_started: :verification_failed transition [:verification_pending, :verification_started, :verification_succeeded, :verification_failed] => :verification_failed
end end
event :verification_pending do event :verification_pending do
......
...@@ -299,37 +299,23 @@ RSpec.shared_examples 'a verifiable replicator' do ...@@ -299,37 +299,23 @@ RSpec.shared_examples 'a verifiable replicator' do
stub_primary_node stub_primary_node
end end
context 'when verification was started' do context 'when the checksum succeeds' do
before do it 'delegates checksum calculation and the state change to model_record' do
model_record.verification_started! expect(model_record).to receive(:calculate_checksum).and_return('abc123')
end expect(model_record).to receive(:verification_succeeded_with_checksum!).with('abc123', kind_of(Time))
context 'when the checksum succeeds' do
it 'delegates checksum calculation and the state change to model_record' do
expect(model_record).to receive(:calculate_checksum).and_return('abc123')
expect(model_record).to receive(:verification_succeeded_with_checksum!).with('abc123', kind_of(Time))
replicator.verify replicator.verify
end
end end
end
context 'when an error is raised during calculate_checksum' do context 'when an error is raised during calculate_checksum' do
it 'passes the error message' do it 'passes the error message' do
error = StandardError.new('Some exception') error = StandardError.new('Some exception')
allow(model_record).to receive(:calculate_checksum) do allow(model_record).to receive(:calculate_checksum) do
raise error raise error
end
expect(model_record).to receive(:verification_failed_with_message!).with('Error calculating the checksum', error)
replicator.verify
end end
end
end
context 'when verification was not started' do expect(model_record).to receive(:verification_failed_with_message!).with('Error calculating the checksum', error)
it 'does not call calculate_checksum!' do
expect(model_record).not_to receive(:calculate_checksum)
replicator.verify replicator.verify
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