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



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
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/elastic/beanstalk/smoke_tester.rb', line 13

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 Test: \n\turl: #{url}\n\ttimeout: #{timeout}\n\texpected_text: #{expected_text}"
  response = nil
  begin
    Timeout.timeout(timeout) do
      i = 0
      print "\nRunning..."
      Spinner.show {
        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}"

          #
          # Let's try to get out quickly when the deploy has gone wrong.
          #
          break if received_fatal_error?(response)

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