Created
June 24, 2011 05:05
-
-
Save hedgehog/1044259 to your computer and use it in GitHub Desktop.
pause until timeout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| describe "with arguments" do | |
| before :all do | |
| @url_stub = "http://not.there.com:88/" | |
| end | |
| context 'the web server is not running' do | |
| it "should wait for the given URL to respond with the expected code" do | |
| pause_for_url_response( 3, @stub_url, '200', 1).should raise_error Timeout::Error | |
| end | |
| end | |
| context 'the web server is now running' do | |
| it "should wait for the given URL to respond with the expected code" do | |
| pause_for_url_response( 3, @stub_url, '200', 1).should_not raise_error Timeout::Error | |
| end | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def pause_for_url_response(seconds,url,code, interval = 60) | |
| begin | |
| Timeout::timeout(seconds) do | |
| response = nil | |
| while response.nil? || response.code != '200' do | |
| response = ::Faraday.get url rescue Faraday::Error::ConnectionFailed | |
| pp response | |
| sleep(interval) | |
| end | |
| end | |
| rescue Timeout::Error => e | |
| raise e | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment