summaryrefslogtreecommitdiff
path: root/test/net/http/test_http.rb
diff options
context:
space:
mode:
authorgotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-12-18 14:46:52 +0000
committergotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-12-18 14:46:52 +0000
commitf2266fe471e77fb972fa0668b6345fc4940904e2 (patch)
tree0ece7ebb572f6a0b0523d3551058ee383a6710af /test/net/http/test_http.rb
parenta04281ff0e3f1dc0f6584102b94f88403ff35520 (diff)
* test/net/http/utils.rb: split TestNetHTTPUtils module from
test/net/http/test_http.rb. and start HTTP server in each test case. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14307 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/net/http/test_http.rb')
-rw-r--r--test/net/http/test_http.rb85
1 files changed, 1 insertions, 84 deletions
diff --git a/test/net/http/test_http.rb b/test/net/http/test_http.rb
index eeb046b54ba..97eed02b074 100644
--- a/test/net/http/test_http.rb
+++ b/test/net/http/test_http.rb
@@ -2,9 +2,8 @@
require 'test/unit'
require 'net/http'
-require 'webrick'
-require 'webrick/httpservlet/abstract'
require 'stringio'
+require File.expand_path("utils", File.dirname(__FILE__))
module TestNetHTTP_version_1_1_methods
@@ -264,88 +263,6 @@ module TestNetHTTP_version_1_2_methods
end
end
-
-module TestNetHTTPUtils
- def start(&block)
- new().start(&block)
- end
-
- def new
- klass = Net::HTTP::Proxy(config('proxy_host'), config('proxy_port'))
- http = klass.new(config('host'), config('port'))
- http.set_debug_output logfile()
- http
- end
-
- def config(key)
- self.class::CONFIG[key]
- end
-
- def logfile
- $DEBUG ? $stderr : NullWriter.new
- end
-
- def setup
- spawn_server
- end
-
- def teardown
- # resume global state
- Net::HTTP.version_1_2
- end
-
- def spawn_server
- return if $test_net_http_server_running
- server = WEBrick::HTTPServer.new(
- :BindAddress => config('host'),
- :Port => config('port'),
- :Logger => WEBrick::Log.new(NullWriter.new),
- :AccessLog => []
- )
- server.mount '/', Servlet
- Signal.trap(:INT) {
- server.shutdown
- }
- Thread.fork {
- server.start
- }
- n_try_max = 5
- begin
- TCPSocket.open(config('host'), config('port')).close
- rescue Errno::ECONNREFUSED
- sleep 0.2
- n_try_max -= 1
- raise 'cannot spawn server; give up' if n_try_max < 0
- retry
- end
- $test_net_http_server_running = true
- end
-
- $test_net_http = nil
- $test_net_http_data = (0...256).to_a.map {|i| i.chr }.join('') * 64
- $test_net_http_data_type = 'application/octet-stream'
-
- class Servlet < WEBrick::HTTPServlet::AbstractServlet
- def do_GET(req, res)
- res['Content-Type'] = $test_net_http_data_type
- res.body = $test_net_http_data
- end
-
- # echo server
- def do_POST(req, res)
- res['Content-Type'] = req['Content-Type']
- res.body = req.body
- end
- end
-
- class NullWriter
- def <<(s) end
- def puts(*args) end
- def print(*args) end
- def printf(*args) end
- end
-end
-
class TestNetHTTP_version_1_1 < Test::Unit::TestCase
CONFIG = {
'host' => '127.0.0.1',