Skip to content

Commit

Permalink
Handle missing specs in backfill (#4101)
Browse files Browse the repository at this point in the history
Some specs are missing, allow the backfill to continue & log errors for the missing specs
  • Loading branch information
segiddins committed Sep 29, 2023
1 parent 0523170 commit 6d657b3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
5 changes: 4 additions & 1 deletion app/tasks/maintenance/backfill_spec_sha256_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ def process(version)
spec_path = "quick/Marshal.4.8/#{version.full_name}.gemspec.rz"
spec_contents = RubygemFs.instance.get(spec_path)

raise "#{spec_path} is missing" if spec_contents.nil?
if spec_contents.nil?
logger.error "Could not find #{spec_path}"
return
end

spec_sha256 = Digest::SHA2.base64digest(spec_contents)

Expand Down
18 changes: 15 additions & 3 deletions test/tasks/maintenance/backfill_spec_sha256_task_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class Maintenance::BackfillSpecSha256TaskTest < ActiveSupport::TestCase
end

context "#process" do
include SemanticLogger::Test::Minitest

setup do
@rubygem = create(:rubygem, name: "rubygem")
end
Expand All @@ -31,11 +33,21 @@ class Maintenance::BackfillSpecSha256TaskTest < ActiveSupport::TestCase
assert_equal "Ry6N90Xp7Or9qGoWziaaTotD1K7vOAonnRAAPjXCzic=", v.reload.spec_sha256
end

should "error if spec is missing" do
should "log if spec is missing" do
v = create(:version, rubygem: @rubygem, number: "1", platform: "ruby", spec_sha256: nil)
e = assert_raise { Maintenance::BackfillSpecSha256Task.process(v) }
logger = SemanticLogger::Test::CaptureLogEvents.new
Maintenance::BackfillSpecSha256Task.stubs(:logger).returns(logger)

assert_no_changes "v.reload.spec_sha256" do
Maintenance::BackfillSpecSha256Task.process(v)
end

assert_equal "quick/Marshal.4.8/rubygem-1.gemspec.rz is missing", e.message
assert_semantic_logger_event(
logger.events[1],
level: :error,
message_includes: "Could not find quick/Marshal.4.8/rubygem-1.gemspec.rz"
)
assert_equal 2, logger.events.size
end

should "not update the spec sha256 if it is already set" do
Expand Down

0 comments on commit 6d657b3

Please sign in to comment.