Module: Elastic::Beanstalk::SmokeTester

Extended by:
SmokeTester
Included in:
SmokeTester
Defined in:
lib/elastic/beanstalk/smoke_tester.rb

Defined Under Namespace

Classes: ResponseStub

Instance Method Summary collapse

Instance Method Details

#test_url(url, timeout, sleep_wait, expected_text) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/elastic/beanstalk/smoke_tester.rb', line 11

def test_url(url, timeout, sleep_wait, expected_text)

  puts '-------------------------------------------------------------------------------'
#    puts "Smoke Testing: \n\turl: #{url}\n\ttimeout: #{timeout}\n\tsleep_wait: #{sleep_wait}\n\texpected_text: #{expected_text}\n"
  puts "Smoke Testing: \n\turl: #{url}\n\ttimeout: #{timeout}\n\texpected_text: #{expected_text}\n"
  response = nil
  begin
    Timeout.timeout(timeout) do
      i = 0
      begin
        sleep sleep_wait.to_i unless (i == 0)
        i += 1
        begin
          response = Net::HTTP.get_response(URI(url))
        #rescue SocketError => e
        #  response = ResponseStub.new({code: e.message, body: ''})
        rescue => e
          response = ResponseStub.new({code: e.message, body: ''})
        end

        puts "\t\t[#{response.code}]"
        #puts "\t#{response.body}"
      end until (!response.nil? && response.code.to_i == 200 && response.body.include?(expected_text))
    end
  ensure
    puts "\nFinal response: \n\tcode: [#{response.code}] \n\texpectation met: #{response.body.include?(expected_text)}"
    puts '-------------------------------------------------------------------------------'
  end
end