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