diff --git a/.circleci/config.yml b/.circleci/config.yml index 080e5b329..cabbd2605 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -45,9 +45,6 @@ jobs: - run: name: Test splitting command: | - curl -I public-api.secure.pixiv.net - curl -I oauth.secure.pixiv.net - curl -I www.pixiv.net circleci tests glob test/**/*_test.rb | circleci tests split | xargs -I{} docker-compose -f config/docker/compose.yml exec -T web bash -l -c 'cd /app ; bin/rails test {}' docker cp docker_web_1:/app/test/reports /tmp - store_test_results: diff --git a/app/logical/pixiv_api_client.rb b/app/logical/pixiv_api_client.rb index a4f0fcabe..00ba4b90a 100644 --- a/app/logical/pixiv_api_client.rb +++ b/app/logical/pixiv_api_client.rb @@ -154,9 +154,6 @@ class PixivApiClient else raise Error.new("Pixiv API call failed (status=#{resp.code} body=#{body})") end - rescue Net::OpenTimeout - sleep(5) - retry rescue JSON::ParserError raise Error.new("Pixiv API call failed (status=#{resp.code} body=#{body})") end @@ -188,9 +185,5 @@ class PixivApiClient access_token end - - rescue Net::OpenTimeout - sleep(5) - retry end end diff --git a/app/models/artist.rb b/app/models/artist.rb index 8dbb59e51..4d1d9754f 100644 --- a/app/models/artist.rb +++ b/app/models/artist.rb @@ -484,6 +484,9 @@ class Artist < ApplicationRecord else nil end + rescue Net::OpenTimeout + raise if Rails.env.test? + nil rescue Exception nil end diff --git a/test/functional/artists_controller_test.rb b/test/functional/artists_controller_test.rb index b49794fe2..904740fa8 100644 --- a/test/functional/artists_controller_test.rb +++ b/test/functional/artists_controller_test.rb @@ -2,20 +2,44 @@ require 'test_helper' class ArtistsControllerTest < ActionDispatch::IntegrationTest def assert_artist_found(expected_artist, source_url = nil) - if source_url - get_auth finder_artists_path(format: "json", url: source_url), @user + tries = 0 + + begin + if source_url + get_auth finder_artists_path(format: "json", url: source_url), @user + end + assert_response :success + json = JSON.parse(response.body) + assert_equal(1, json.size, "Testing URL: #{source_url}") + assert_equal(expected_artist, json[0]["name"]) + rescue Net::OpenTimeout + tries += 1 + if tries == 3 + skip "Remote connection to #{source_url} failed" + else + sleep(tries ** 2) + retry + end end - assert_response :success - json = JSON.parse(response.body) - assert_equal(1, json.size, "Testing URL: #{source_url}") - assert_equal(expected_artist, json[0]["name"]) end def assert_artist_not_found(source_url) - get_auth finder_artists_path(format: "json", url: source_url), @user - assert_response :success - json = JSON.parse(response.body) - assert_equal(0, json.size, "Testing URL: #{source_url}") + tries = 0 + + begin + get_auth finder_artists_path(format: "json", url: source_url), @user + assert_response :success + json = JSON.parse(response.body) + assert_equal(0, json.size, "Testing URL: #{source_url}") + rescue Net::OpenTimeout + tries += 1 + if tries == 3 + skip "Remote connection to #{source_url} failed" + else + sleep(tries ** 2) + retry + end + end end context "An artists controller" do diff --git a/test/test_helpers/download_test_helper.rb b/test/test_helpers/download_test_helper.rb index dcdadc641..2552e91ce 100644 --- a/test/test_helpers/download_test_helper.rb +++ b/test/test_helpers/download_test_helper.rb @@ -3,7 +3,18 @@ require 'ptools' module DownloadTestHelper def assert_downloaded(expected_filesize, source) download = Downloads::File.new(source) - tempfile = download.download! + @retry_count = 0 + begin + tempfile = download.download! + rescue Net::OpenTimeout + @retry_count += 1 + if @retry_count == 3 + skip "Remote connection to #{source} failed" + else + sleep(@retry_count ** 2) + retry + end + end assert_equal(expected_filesize, tempfile.size, "Tested source URL: #{source}") end diff --git a/test/unit/sources/pixiv_test.rb b/test/unit/sources/pixiv_test.rb index e9e61ee3a..173d3e778 100644 --- a/test/unit/sources/pixiv_test.rb +++ b/test/unit/sources/pixiv_test.rb @@ -4,13 +4,26 @@ module Sources class PixivTest < ActiveSupport::TestCase def get_source(source) @site = Sources::Site.new(source) - @site.get + + begin + @site.get + rescue Net::OpenTimeout + @retry_count += 1 + if @retry_count == 3 + skip "Could not connect to Pixiv" + else + sleep(@retry_count ** 2) + retry + end + end + @site end def setup super load_pixiv_tokens! + @retry_count = 0 end def teardown