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