skip earlier on failed pixiv tests

This commit is contained in:
Albert Yi
2018-05-15 16:15:59 -07:00
parent d047d04de6
commit f3364b9892
3 changed files with 15 additions and 55 deletions

View File

@@ -3,19 +3,10 @@ require 'ptools'
module DownloadTestHelper
def assert_downloaded(expected_filesize, source)
download = Downloads::File.new(source)
@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
tempfile = download.download!
assert_equal(expected_filesize, tempfile.size, "Tested source URL: #{source}")
rescue Net::OpenTimeout
skip "Remote connection to #{source} failed"
end
def assert_rewritten(expected_source, test_source)

View File

@@ -2,39 +2,19 @@ require 'test_helper'
class ArtistTest < ActiveSupport::TestCase
def assert_artist_found(expected_name, source_url)
tries = 0
artists = Artist.url_matches(source_url).to_a
begin
artists = Artist.url_matches(source_url).to_a
assert_equal(1, artists.size)
assert_equal(expected_name, artists.first.name, "Testing URL: #{source_url}")
rescue Net::OpenTimeout, PixivApiClient::Error
tries += 1
if tries == 3
skip "Remote connection failed for #{source_url}"
else
sleep(tries ** 2)
retry
end
end
assert_equal(1, artists.size)
assert_equal(expected_name, artists.first.name, "Testing URL: #{source_url}")
rescue Net::OpenTimeout, PixivApiClient::Error
skip "Remote connection failed for #{source_url}"
end
def assert_artist_not_found(source_url)
tries = 0
begin
artists = Artist.url_matches(source_url).to_a
assert_equal(0, artists.size, "Testing URL: #{source_url}")
rescue Net::OpenTimeout
tries += 1
if tries == 3
skip "Remote connection failed for #{source_url}"
else
sleep(tries ** 2)
retry
end
end
artists = Artist.url_matches(source_url).to_a
assert_equal(0, artists.size, "Testing URL: #{source_url}")
rescue Net::OpenTimeout
skip "Remote connection failed for #{source_url}"
end
context "An artist" do

View File

@@ -4,26 +4,15 @@ module Sources
class PixivTest < ActiveSupport::TestCase
def get_source(source)
@site = Sources::Site.new(source)
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.get
@site
rescue Net::OpenTimeout
skip "Remote connection to #{source} failed"
end
def setup
super
load_pixiv_tokens!
@retry_count = 0
end
def teardown