Skip to content

Instantly share code, notes, and snippets.

@jordansissel
Created November 20, 2010 07:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jordansissel/707691 to your computer and use it in GitHub Desktop.
Save jordansissel/707691 to your computer and use it in GitHub Desktop.
cucumber for production tests
Feature: solrserver remote health
In order to remotely ensure a healthy solrserver
As a client talking to the solrserver
I want to ensure solrserver is responsive
Scenario: Check the status of solrserver
Given a dns name of "solr"
And requests timeout after 2 seconds
When I fetch "http://solr:8983/solr/admin/cores?action=status" for each dns entry
Then there should be no timeouts
And each response code should be '200'
require "rubygems"
require "test/unit"
require "json"
require "timeout"
include Test::Unit::Assertions
Given /^a dns name of "([^"]*)"$/ do |hostname|
require "socket"
name, aliases, family, *addresses = Socket.gethostbyname("solr")
@hostname = hostname
@addresses = addresses.collect { |a| a.unpack("C*").join(".") }
end
Given /^requests timeout after ([0-9.]+) seconds/ do |timeout|
@timeout = timeout.to_f
end
When /^I fetch "([^"]+)" for each dns entry/ do |url|
require "net/http"
require "uri"
@url = URI.parse(url)
@responses = {}
@timeouts = []
@addresses.each do |address|
request = Net::HTTP::Get.new(@url.path)
request.add_field("Host", @hostname)
begin
Timeout.timeout(@timeout) do
start = Time.now
response = Net::HTTP.start(address, @url.port) do |http|
http.request(request)
end # Net::HTTP.start
@responses[address] = {
:response => response,
:duration => Time.now - start
}
end
rescue Timeout::Error => e
@timeouts << address
rescue => e
assert(false, "An unhandled exception when querying #{address}: #{e}")
end
end
end
Then /^there should be no timeouts$/ do
assert_equal(@timeouts.length, 0, "Timeouts from (> #{@timeout} secs): #{@timeouts.join(", ")}")
end
Then /^each response code should be '(\d+)'$/ do |arg1|
assert_equal(@addresses.length, @responses.length,
"Should have #{@addresses.length} responses, got #{@responses.length}." \
" Missing #{(@addresses - @responses.keys).join(", ")}")
@responses.each do |address, info|
code = info[:response].code
assert_equal("200", code, "Expected response to be 200, was #{code} for #{address} / http://#{@hostname}:#{@port}#{@path}")
end
puts "Got #{@responses.length} good responses"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment