From 6acaf999a1e96b1349f949fff68158f224d25ac2 Mon Sep 17 00:00:00 2001 From: Albert Yi Date: Tue, 15 May 2018 17:25:55 -0700 Subject: [PATCH] additional error handling in tests --- app/models/artist.rb | 2 +- app/models/artist_url.rb | 2 +- test/unit/upload_test.rb | 10 +++++++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/models/artist.rb b/app/models/artist.rb index 4d1d9754f..b9e999c1d 100644 --- a/app/models/artist.rb +++ b/app/models/artist.rb @@ -484,7 +484,7 @@ class Artist < ApplicationRecord else nil end - rescue Net::OpenTimeout + rescue Net::OpenTimeout, PixivApiClient::Error raise if Rails.env.test? nil rescue Exception diff --git a/app/models/artist_url.rb b/app/models/artist_url.rb index 8a76cecef..fa450c34c 100644 --- a/app/models/artist_url.rb +++ b/app/models/artist_url.rb @@ -21,7 +21,7 @@ class ArtistUrl < ApplicationRecord begin url = Sources::Site.new(url).normalize_for_artist_finder! - rescue PixivApiClient::Error + rescue Net::OpenTimeout, PixivApiClient::Error raise if Rails.env.test? rescue Sources::Site::NoStrategyError end diff --git a/test/unit/upload_test.rb b/test/unit/upload_test.rb index 047dfce2d..ef81946a5 100644 --- a/test/unit/upload_test.rb +++ b/test/unit/upload_test.rb @@ -87,9 +87,13 @@ class UploadTest < ActiveSupport::TestCase end should "process successfully" do - _, _, output_file = @upload.download_from_source(@url, "") - assert_operator(output_file.size, :>, 1_000) - assert_equal("zip", @upload.file_header_to_file_ext(output_file)) + begin + _, _, output_file = @upload.download_from_source(@url, "") + assert_operator(output_file.size, :>, 1_000) + assert_equal("zip", @upload.file_header_to_file_ext(output_file)) + rescue Net::OpenTimeout + skip "Remote connection to #{@url} failed" + end end end end