skip tests that throw an net::opentimeout error
This commit is contained in:
@@ -45,9 +45,6 @@ jobs:
|
|||||||
- run:
|
- run:
|
||||||
name: Test splitting
|
name: Test splitting
|
||||||
command: |
|
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 {}'
|
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
|
docker cp docker_web_1:/app/test/reports /tmp
|
||||||
- store_test_results:
|
- store_test_results:
|
||||||
|
|||||||
@@ -154,9 +154,6 @@ class PixivApiClient
|
|||||||
else
|
else
|
||||||
raise Error.new("Pixiv API call failed (status=#{resp.code} body=#{body})")
|
raise Error.new("Pixiv API call failed (status=#{resp.code} body=#{body})")
|
||||||
end
|
end
|
||||||
rescue Net::OpenTimeout
|
|
||||||
sleep(5)
|
|
||||||
retry
|
|
||||||
rescue JSON::ParserError
|
rescue JSON::ParserError
|
||||||
raise Error.new("Pixiv API call failed (status=#{resp.code} body=#{body})")
|
raise Error.new("Pixiv API call failed (status=#{resp.code} body=#{body})")
|
||||||
end
|
end
|
||||||
@@ -188,9 +185,5 @@ class PixivApiClient
|
|||||||
|
|
||||||
access_token
|
access_token
|
||||||
end
|
end
|
||||||
|
|
||||||
rescue Net::OpenTimeout
|
|
||||||
sleep(5)
|
|
||||||
retry
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -484,6 +484,9 @@ class Artist < ApplicationRecord
|
|||||||
else
|
else
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
rescue Net::OpenTimeout
|
||||||
|
raise if Rails.env.test?
|
||||||
|
nil
|
||||||
rescue Exception
|
rescue Exception
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,20 +2,44 @@ require 'test_helper'
|
|||||||
|
|
||||||
class ArtistsControllerTest < ActionDispatch::IntegrationTest
|
class ArtistsControllerTest < ActionDispatch::IntegrationTest
|
||||||
def assert_artist_found(expected_artist, source_url = nil)
|
def assert_artist_found(expected_artist, source_url = nil)
|
||||||
if source_url
|
tries = 0
|
||||||
get_auth finder_artists_path(format: "json", url: source_url), @user
|
|
||||||
|
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
|
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
|
end
|
||||||
|
|
||||||
def assert_artist_not_found(source_url)
|
def assert_artist_not_found(source_url)
|
||||||
get_auth finder_artists_path(format: "json", url: source_url), @user
|
tries = 0
|
||||||
assert_response :success
|
|
||||||
json = JSON.parse(response.body)
|
begin
|
||||||
assert_equal(0, json.size, "Testing URL: #{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}")
|
||||||
|
rescue Net::OpenTimeout
|
||||||
|
tries += 1
|
||||||
|
if tries == 3
|
||||||
|
skip "Remote connection to #{source_url} failed"
|
||||||
|
else
|
||||||
|
sleep(tries ** 2)
|
||||||
|
retry
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "An artists controller" do
|
context "An artists controller" do
|
||||||
|
|||||||
@@ -3,7 +3,18 @@ require 'ptools'
|
|||||||
module DownloadTestHelper
|
module DownloadTestHelper
|
||||||
def assert_downloaded(expected_filesize, source)
|
def assert_downloaded(expected_filesize, source)
|
||||||
download = Downloads::File.new(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}")
|
assert_equal(expected_filesize, tempfile.size, "Tested source URL: #{source}")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -4,13 +4,26 @@ module Sources
|
|||||||
class PixivTest < ActiveSupport::TestCase
|
class PixivTest < ActiveSupport::TestCase
|
||||||
def get_source(source)
|
def get_source(source)
|
||||||
@site = Sources::Site.new(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
|
@site
|
||||||
end
|
end
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
super
|
super
|
||||||
load_pixiv_tokens!
|
load_pixiv_tokens!
|
||||||
|
@retry_count = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
def teardown
|
def teardown
|
||||||
|
|||||||
Reference in New Issue
Block a user