skip tests that throw an net::opentimeout error
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user