Commit 650b4e4f authored by Mike Kozono's avatar Mike Kozono

Rename calculate_checksum! to calculate_checksum

Because side effects are no longer expected.
parent fa4069e8
......@@ -51,7 +51,7 @@ module Geo
end
def verify
checksum = model_record.calculate_checksum!
checksum = model_record.calculate_checksum
update_verification_state!(checksum: checksum)
rescue => e
log_error('Error calculating the checksum', e)
......
......@@ -36,7 +36,7 @@ module Geo
end
def verify_checksum
checksum = model_record.calculate_checksum!
checksum = model_record.calculate_checksum
if mismatch?(checksum)
update_registry!(mismatch: checksum, failure: 'checksum mismatch')
......
......@@ -49,7 +49,7 @@ module Gitlab
# Returns a checksum of the file (assumed to be a "blob" type)
#
# @return [String] SHA256 hash of the carrierwave file
def calculate_checksum!
def calculate_checksum
return unless checksummable?
self.class.hexdigest(replicator.carrierwave_uploader.path)
......
......@@ -4,19 +4,19 @@ require 'spec_helper'
RSpec.describe Packages::PackageFile, type: :model do
include ::EE::GeoHelpers
describe '#calculate_checksum!' do
describe '#calculate_checksum' do
let(:package_file) { create(:conan_package_file, :conan_recipe_file) }
it 'returns SHA256 sum of the file' do
expected = Digest::SHA256.file(package_file.file.path).hexdigest
expect(package_file.calculate_checksum!).to eq(expected)
expect(package_file.calculate_checksum).to eq(expected)
end
it 'returns nil for a non-existent file' do
allow(package_file).to receive(:file_exist?).and_return(false)
expect(package_file.calculate_checksum!).to eq(nil)
expect(package_file.calculate_checksum).to eq(nil)
end
end
......
......@@ -21,7 +21,7 @@ RSpec.describe Geo::BlobVerificationSecondaryService, :geo do
it 'does not calculate the checksum when not running on a secondary' do
stub_primary_node
expect(package_file).not_to receive(:calculate_checksum!)
expect(package_file).not_to receive(:calculate_checksum)
service.execute
end
......@@ -29,7 +29,7 @@ RSpec.describe Geo::BlobVerificationSecondaryService, :geo do
it 'does not verify the checksum if resync is needed' do
registry.resync
expect(package_file).not_to receive(:calculate_checksum!)
expect(package_file).not_to receive(:calculate_checksum)
service.execute
end
......@@ -37,7 +37,7 @@ RSpec.describe Geo::BlobVerificationSecondaryService, :geo do
it 'does not verify the checksum if sync is started' do
registry.start!
expect(package_file).not_to receive(:calculate_checksum!)
expect(package_file).not_to receive(:calculate_checksum)
service.execute
end
......@@ -45,7 +45,7 @@ RSpec.describe Geo::BlobVerificationSecondaryService, :geo do
it 'does not verify the checksum if primary was never verified' do
package_file.assign_attributes(verification_checksum: nil)
expect(package_file).not_to receive(:calculate_checksum!)
expect(package_file).not_to receive(:calculate_checksum)
service.execute
end
......@@ -54,13 +54,13 @@ RSpec.describe Geo::BlobVerificationSecondaryService, :geo do
package_file.assign_attributes(verification_checksum: '62fc1ec4ce60')
registry.update(verification_checksum: '62fc1ec4ce60')
expect(package_file).not_to receive(:calculate_checksum!)
expect(package_file).not_to receive(:calculate_checksum)
service.execute
end
it 'sets checksum when the checksum matches' do
allow(package_file).to receive(:calculate_checksum!).and_return('62fc1ec4ce60')
allow(package_file).to receive(:calculate_checksum).and_return('62fc1ec4ce60')
service.execute
......@@ -77,7 +77,7 @@ RSpec.describe Geo::BlobVerificationSecondaryService, :geo do
context 'when the checksum mismatch' do
before do
allow(package_file).to receive(:calculate_checksum!).and_return('99fc1ec4ce60')
allow(package_file).to receive(:calculate_checksum).and_return('99fc1ec4ce60')
end
it 'keeps track of failures' do
......@@ -109,7 +109,7 @@ RSpec.describe Geo::BlobVerificationSecondaryService, :geo do
context 'when checksum calculation fails' do
before do
allow(package_file).to receive(:calculate_checksum!).and_raise('Error calculating checksum')
allow(package_file).to receive(:calculate_checksum).and_raise('Error calculating checksum')
end
it 'keeps track of failures' do
......
......@@ -54,7 +54,7 @@ RSpec.shared_examples 'a verifiable replicator' do
end
it 'calculates the checksum' do
expect(model_record).to receive(:calculate_checksum!).and_return('abc123')
expect(model_record).to receive(:calculate_checksum).and_return('abc123')
replicator.verify
......@@ -63,7 +63,7 @@ RSpec.shared_examples 'a verifiable replicator' do
end
it 'saves the error message and increments retry counter' do
allow(model_record).to receive(:calculate_checksum!) do
allow(model_record).to receive(:calculate_checksum) do
raise StandardError.new('Failure to calculate checksum')
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