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

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