Commit 60ff0a7e authored by Michael Kozono's avatar Michael Kozono Committed by Douglas Barbosa Alexandre

Geo: Improve missing on primary failure reason

parent 0dc65764
......@@ -162,7 +162,7 @@ module Gitlab
# Check for failures
unless response.status.success?
return failure_result(primary_missing_file: primary_missing_file?(response), reason: "Non-success HTTP response status code #{response.status.code}", extra_details: { status_code: response.status.code, reason: response.status.reason, url: url })
return non_success_response_result(response, url)
end
# Stream to temporary file on disk
......@@ -237,6 +237,25 @@ module Gitlab
def actual_checksum(file_path)
@actual_checksum = Digest::SHA256.file(file_path).hexdigest
end
def non_success_response_result(response, url)
primary_missing_file = primary_missing_file?(response)
reason = if primary_missing_file
"The file is missing on the Geo primary site"
else
"Non-success HTTP response status code #{response.status.code}"
end
failure_result(
primary_missing_file: primary_missing_file,
reason: reason,
extra_details: {
status_code: response.status.code,
reason: response.status.reason,
url: url
}
)
end
end
end
end
......
......@@ -170,7 +170,7 @@ RSpec.describe Gitlab::Geo::Replication::BlobDownloader do
result = subject.execute
expect_blob_downloader_result(result, success: false, bytes_downloaded: 0, primary_missing_file: true)
expect_blob_downloader_result(result, success: false, bytes_downloaded: 0, primary_missing_file: true, reason: 'The file is missing on the Geo primary site')
end
end
......@@ -183,7 +183,7 @@ RSpec.describe Gitlab::Geo::Replication::BlobDownloader do
result = subject.execute
expect_blob_downloader_result(result, success: false, bytes_downloaded: 0, primary_missing_file: false)
expect_blob_downloader_result(result, success: false, bytes_downloaded: 0, primary_missing_file: false, reason: 'Non-success HTTP response status code 404')
end
end
end
......@@ -232,11 +232,15 @@ RSpec.describe Gitlab::Geo::Replication::BlobDownloader do
end
end
def expect_blob_downloader_result(result, success:, bytes_downloaded:, primary_missing_file:, extra_details: nil)
def expect_blob_downloader_result(result, success:, bytes_downloaded:, primary_missing_file:, reason: nil)
expect(result.success).to eq(success)
expect(result.bytes_downloaded).to eq(bytes_downloaded)
expect(result.primary_missing_file).to eq(primary_missing_file)
if reason
expect(result.reason).to eq(reason)
end
# Sanity check to help ensure a valid test
expect(success).not_to be_nil
expect(primary_missing_file).not_to be_nil
......
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