Skip to content

Instantly share code, notes, and snippets.

@pauldix
Created August 27, 2009 18:13
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 pauldix/176455 to your computer and use it in GitHub Desktop.
Save pauldix/176455 to your computer and use it in GitHub Desktop.
hydra = Typhoeus::Hydra.new(3)
@responses = []
start_time = Time.now
request = Typhoeus::Request.new(:method => :get, :host => "localhost:3000", :path => "/first", :query_string => "delay=1")
request.when_complete do
@responses << request.response
YAML.load(request.response.body)[:path_info].should == "/first"
second_request = Typhoeus::Request.new(:method => :get, :host => "localhost:3000", :path => "/second", :query_string => "delay=2")
second_request.when_complete do
@responses << second_request.response
YAML.load(second_request.response.body)[:path_info].should == "/second"
end
hydra.queue_request(second_request)
end
hydra.queue_request(request)
third_request = Typhoeus::Request.new(:method => :get, :host => "localhost:3000", :path => "/third", :query_string => "delay=3")
third_request.when_complete do
@responses << third_request.response
YAML.load(third_request.response.body)[:path_info].should == "/third"
end
hydra.queue_request(third_request)
hydra.run
puts @responses.map {|r| r.body}.inspect
@responses.size.should == 3
(Time.now - start_time).should < 3.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment