Permalink
Browse files

retry connecting to the w3c validator if it fails ( usually a 502 res…

…ponse )
  • Loading branch information...
1 parent af6a0bc commit 462861a96468c3f971f056ce951fa488d146a566 Egor Philippov committed Feb 27, 2012
Showing with 18 additions and 1 deletion.
  1. +18 −1 lib/assert_valid_markup.rb
View
@@ -13,7 +13,9 @@ class Test::Unit::TestCase
:catalog_path => File.expand_path("~/.xml-catalogs"),
:validation_service => system("xmllint --version > /dev/null 2>&1") ? :local : :w3c,
:dtd_validate => true,
- :ignore_no_doctype => false
+ :ignore_no_doctype => false,
+ :sleep_time => 3,
+ :w3c_max_retries => 3
}
# Assert that markup (html/xhtml) is valid according the W3C validator web service.
@@ -177,6 +179,21 @@ def w3c_validate(fragment, dtd_validate)
end
begin
response = Net::HTTP.start('validator.w3.org').post2('/check', "fragment=#{CGI.escape(fragment)}&output=json")
+
+ # Try to get a good ( 200 OK ) response from the validator
+ # Be warned, W3C validator returns 502 often
+ if response.code != "200"
+ for i in 1..@@default_avm_options[:w3c_max_retries]
+ puts "WARNING: W3C validator returned HTTP code " + response.code
+ sleep @@default_avm_options[:sleep_time]
+ response = Net::HTTP.start('validator.w3.org').post2('/check', "fragment=#{CGI.escape(fragment)}&output=json")
+
+ if response.code == "200"
+ break
+ end
+ end
+ end
+
ensure
if defined?(FakeWeb)
FakeWeb.allow_net_connect = old_net_connect

0 comments on commit 462861a

Please sign in to comment.