Skip to content

Commit

Permalink
Fixup attempts logging add coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
svevang committed Oct 7, 2024
1 parent 6e0f6ab commit f71a7bc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
5 changes: 3 additions & 2 deletions app/models/apple/publisher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,9 @@ def wait_for_asset_state(eps)

(waiting_timed_out, _) = Apple::Episode.wait_for_asset_state(api, eps)
if waiting_timed_out
attempts = eps.max { |ep| ep.apple_episode_delivery_status.asset_processing_attempts }
raise "Timed out waiting for asset state. #{attempts} attempts so far"
attempts = eps.map { |ep| ep.apple_episode_delivery_status.asset_processing_attempts }.max
Rails.logger.info("Timed out waiting for asset state", {attempts: attempts, episode_count: eps.length})
raise "Timed out waiting for asset state"
end
end
end
Expand Down
30 changes: 28 additions & 2 deletions test/models/apple/publisher_test.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# frozen_string_literal: true

require "test_helper"

describe Apple::Publisher do
Expand All @@ -13,6 +11,8 @@
Apple::Publisher.new(api: apple_api, public_feed: public_feed, private_feed: private_feed)
end

let(:publisher) { apple_publisher }

before do
stub_request(:get, "https://api.podcastsconnect.apple.com/v1/countriesAndRegions?limit=200")
.to_return(status: 200, body: json_file(:apple_countries_and_regions), headers: {})
Expand Down Expand Up @@ -404,6 +404,32 @@
end
end

it "logs a timeout message with correct information" do
eps = [
OpenStruct.new(
podcast_delivery_files: [OpenStruct.new(api_marked_as_uploaded?: true)],
apple_episode_delivery_status: OpenStruct.new(
increment_asset_wait: nil,
asset_processing_attempts: 3
)
)
] * 2 # Create two identical episode structures

log_message = nil
Rails.logger.stub :tagged, nil do
Rails.logger.stub :info, ->(msg, data) { log_message = [msg, data] } do
Apple::Episode.stub :wait_for_asset_state, [true, nil] do
publisher.wait_for_asset_state(eps)
rescue RuntimeError
# Ignore the exception for this test
end
end
end

assert_equal "Timed out waiting for asset state", log_message[0]
assert_equal({attempts: 3, episode_count: 2}, log_message[1])
end

it "should raise an error when wait times out" do
episode1.apple_episode_delivery_status.update!(asset_processing_attempts: 3)

Expand Down

0 comments on commit f71a7bc

Please sign in to comment.