Skip to content

Commit 8af1366

Browse files
committed
Merge pull request postrank-labs#78 from radsaq/test_helper_fixes
Don't use the default server port number for running tests
2 parents 1bdfbe0 + 43e74d4 commit 8af1366

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

‎lib/goliath/test_helper.rb‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ def self.included(mod)
2929
end
3030

3131
# Launches an instance of a given API server. The server
32-
# will launch on the default settings of localhost port 9000.
32+
# will launch on the specified port.
3333
#
3434
# @param api [Class] The API class to launch
3535
# @param port [Integer] The port to run the server on
3636
# @param options [Hash] The options hash to provide to the server
3737
# @return [Goliath::Server] The executed server
38-
defserver(api,port=9000,options={}, &blk)
38+
defserver(api,port,options={}, &blk)
3939
op=OptionParser.new
4040

4141
s=Goliath::Server.new
@@ -44,7 +44,7 @@ def server(api, port = 9000, options ={}, &blk)
4444
s.app=Goliath::Rack::Builder.build(api,s.api)
4545
s.api.options_parser(op,options)
4646
s.options=options
47-
s.port=port
47+
s.port=@test_server_port=port
4848
s.start(&blk)
4949
s
5050
end
@@ -64,7 +64,7 @@ def stop
6464
# @param blk [Proc] The code to execute after the server is launched.
6565
# @note This will not return until stop is called.
6666
defwith_api(api,options={}, &blk)
67-
server(api,9000,options, &blk)
67+
server(api,options.delete(:port) || 9900,options, &blk)
6868
end
6969

7070
# Helper method to setup common callbacks for various request methods.
@@ -90,8 +90,7 @@ def hookup_request_callbacks(req, errback, &blk)
9090
# @param errback [Proc] An error handler to attach
9191
# @param blk [Proc] The callback block to execute
9292
defhead_request(request_data={},errback=nil, &blk)
93-
path=request_data.delete(:path) || ''
94-
req=EM::HttpRequest.new("http://localhost:9000#{path}").head(request_data)
93+
req=test_request(request_data).head(request_data)
9594
hookup_request_callbacks(req,errback, &blk)
9695
end
9796

@@ -101,8 +100,7 @@ def head_request(request_data ={}, errback = nil, &blk)
101100
# @param errback [Proc] An error handler to attach
102101
# @param blk [Proc] The callback block to execute
103102
defget_request(request_data={},errback=nil, &blk)
104-
path=request_data.delete(:path) || ''
105-
req=EM::HttpRequest.new("http://localhost:9000#{path}").get(request_data)
103+
req=test_request(request_data).get(request_data)
106104
hookup_request_callbacks(req,errback, &blk)
107105
end
108106

@@ -112,8 +110,7 @@ def get_request(request_data ={}, errback = nil, &blk)
112110
# @param errback [Proc] An error handler to attach
113111
# @param blk [Proc] The callback block to execute
114112
defpost_request(request_data={},errback=nil, &blk)
115-
path=request_data.delete(:path) || ''
116-
req=EM::HttpRequest.new("http://localhost:9000#{path}").post(request_data)
113+
req=test_request(request_data).post(request_data)
117114
hookup_request_callbacks(req,errback, &blk)
118115
end
119116

@@ -123,8 +120,7 @@ def post_request(request_data ={}, errback = nil, &blk)
123120
# @param errback [Proc] An error handler to attach
124121
# @param blk [Proc] The callback block to execute
125122
defput_request(request_data={},errback=nil, &blk)
126-
path=request_data.delete(:path) || ''
127-
req=EM::HttpRequest.new("http://localhost:9000#{path}").put(request_data)
123+
req=test_request(request_data).put(request_data)
128124
hookup_request_callbacks(req,errback, &blk)
129125
end
130126

@@ -134,9 +130,13 @@ def put_request(request_data ={}, errback = nil, &blk)
134130
# @param errback [Proc] An error handler to attach
135131
# @param blk [Proc] The callback block to execute
136132
defdelete_request(request_data={},errback=nil, &blk)
137-
path=request_data.delete(:path) || ''
138-
req=EM::HttpRequest.new("http://localhost:9000#{path}").delete(request_data)
133+
req=test_request(request_data).delete(request_data)
139134
hookup_request_callbacks(req,errback, &blk)
140135
end
136+
137+
deftest_request(request_data)
138+
path=request_data.delete(:path) || ''
139+
EM::HttpRequest.new("http://localhost:#{@test_server_port}#{path}")
140+
end
141141
end
142142
end

‎spec/integration/keepalive_spec.rb‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
describe'HTTP Keep-Alive support'do
55
it'serves multiple requests via single connection'do
6-
with_api(Echo)do
7-
conn=EM::HttpRequest.new('http://localhost:9000')
6+
with_api(Echo,:port=>9901)do
7+
conn=EM::HttpRequest.new('http://localhost:9901')
88
r1=conn.get(:query=>{:echo=>'test'},:keepalive=>true)
99

1010
r1.errback{fail}

‎spec/integration/pipelining_spec.rb‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ def response(env)
1313

1414
describe'HTTP Pipelining support'do
1515
it'serves multiple requests via single connection'do
16-
with_api(Interleaving)do
16+
with_api(Interleaving,:port=>9901)do
1717
start=Time.now.to_f
1818
res=[]
1919

20-
conn=EM::HttpRequest.new('http://localhost:9000')
20+
conn=EM::HttpRequest.new('http://localhost:9901')
2121
r1=conn.aget:query=>{:delay=>0.3},:keepalive=>true
2222
r2=conn.aget:query=>{:delay=>0.2}
2323

0 commit comments

Comments
(0)