Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #78 from radsaq/test_helper_fixes

Don't use the default server port number for running tests
  • Loading branch information...
commit 8af13667dd4ce6b44fbb6792d74923443b44be17 2 parents 1bdfbe0 + 43e74d4
@dj2 dj2 authored
View
28 lib/goliath/test_helper.rb
@@ -29,13 +29,13 @@ def self.included(mod)
end
# Launches an instance of a given API server. The server
- # will launch on the default settings of localhost port 9000.
+ # will launch on the specified port.
#
# @param api [Class] The API class to launch
# @param port [Integer] The port to run the server on
# @param options [Hash] The options hash to provide to the server
# @return [Goliath::Server] The executed server
- def server(api, port = 9000, options = {}, &blk)
+ def server(api, port, options = {}, &blk)
op = OptionParser.new
s = Goliath::Server.new
@@ -44,7 +44,7 @@ def server(api, port = 9000, options = {}, &blk)
s.app = Goliath::Rack::Builder.build(api, s.api)
s.api.options_parser(op, options)
s.options = options
- s.port = port
+ s.port = @test_server_port = port
s.start(&blk)
s
end
@@ -64,7 +64,7 @@ def stop
# @param blk [Proc] The code to execute after the server is launched.
# @note This will not return until stop is called.
def with_api(api, options = {}, &blk)
- server(api, 9000, options, &blk)
+ server(api, options.delete(:port) || 9900, options, &blk)
end
# Helper method to setup common callbacks for various request methods.
@@ -90,8 +90,7 @@ def hookup_request_callbacks(req, errback, &blk)
# @param errback [Proc] An error handler to attach
# @param blk [Proc] The callback block to execute
def head_request(request_data = {}, errback = nil, &blk)
- path = request_data.delete(:path) || ''
- req = EM::HttpRequest.new("http://localhost:9000#{path}").head(request_data)
+ req = test_request(request_data).head(request_data)
hookup_request_callbacks(req, errback, &blk)
end
@@ -101,8 +100,7 @@ def head_request(request_data = {}, errback = nil, &blk)
# @param errback [Proc] An error handler to attach
# @param blk [Proc] The callback block to execute
def get_request(request_data = {}, errback = nil, &blk)
- path = request_data.delete(:path) || ''
- req = EM::HttpRequest.new("http://localhost:9000#{path}").get(request_data)
+ req = test_request(request_data).get(request_data)
hookup_request_callbacks(req, errback, &blk)
end
@@ -112,8 +110,7 @@ def get_request(request_data = {}, errback = nil, &blk)
# @param errback [Proc] An error handler to attach
# @param blk [Proc] The callback block to execute
def post_request(request_data = {}, errback = nil, &blk)
- path = request_data.delete(:path) || ''
- req = EM::HttpRequest.new("http://localhost:9000#{path}").post(request_data)
+ req = test_request(request_data).post(request_data)
hookup_request_callbacks(req, errback, &blk)
end
@@ -123,8 +120,7 @@ def post_request(request_data = {}, errback = nil, &blk)
# @param errback [Proc] An error handler to attach
# @param blk [Proc] The callback block to execute
def put_request(request_data = {}, errback = nil, &blk)
- path = request_data.delete(:path) || ''
- req = EM::HttpRequest.new("http://localhost:9000#{path}").put(request_data)
+ req = test_request(request_data).put(request_data)
hookup_request_callbacks(req, errback, &blk)
end
@@ -134,9 +130,13 @@ def put_request(request_data = {}, errback = nil, &blk)
# @param errback [Proc] An error handler to attach
# @param blk [Proc] The callback block to execute
def delete_request(request_data = {}, errback = nil, &blk)
- path = request_data.delete(:path) || ''
- req = EM::HttpRequest.new("http://localhost:9000#{path}").delete(request_data)
+ req = test_request(request_data).delete(request_data)
hookup_request_callbacks(req, errback, &blk)
end
+
+ def test_request(request_data)
+ path = request_data.delete(:path) || ''
+ EM::HttpRequest.new("http://localhost:#{@test_server_port}#{path}")
+ end
end
end
View
4 spec/integration/keepalive_spec.rb
@@ -3,8 +3,8 @@
describe 'HTTP Keep-Alive support' do
it 'serves multiple requests via single connection' do
- with_api(Echo) do
- conn = EM::HttpRequest.new('http://localhost:9000')
+ with_api(Echo, :port => 9901) do
+ conn = EM::HttpRequest.new('http://localhost:9901')
r1 = conn.get(:query => {:echo => 'test'}, :keepalive => true)
r1.errback { fail }
View
4 spec/integration/pipelining_spec.rb
@@ -13,11 +13,11 @@ def response(env)
describe 'HTTP Pipelining support' do
it 'serves multiple requests via single connection' do
- with_api(Interleaving) do
+ with_api(Interleaving, :port => 9901) do
start = Time.now.to_f
res = []
- conn = EM::HttpRequest.new('http://localhost:9000')
+ conn = EM::HttpRequest.new('http://localhost:9901')
r1 = conn.aget :query => {:delay => 0.3}, :keepalive => true
r2 = conn.aget :query => {:delay => 0.2}
Please sign in to comment.
Something went wrong with that request. Please try again.