skip tests that throw an net::opentimeout error

This commit is contained in:
Albert Yi
2018-05-14 10:00:52 -07:00
parent ca61985bd9
commit 8d5db3723b
6 changed files with 63 additions and 22 deletions

View File

@@ -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:

View File

@@ -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

View File

@@ -484,6 +484,9 @@ class Artist < ApplicationRecord
else
nil
end
rescue Net::OpenTimeout
raise if Rails.env.test?
nil
rescue Exception
nil
end

View File

@@ -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

View File

@@ -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

View File

@@ -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