ruby-changes:2815
From: ko1@a...
Date: 18 Dec 2007 23:50:01 +0900
Subject: [ruby-changes:2815] gotoyuzo - Ruby:r14307 (trunk): * test/net/http/utils.rb: split TestNetHTTPUtils module from
gotoyuzo 2007-12-18 23:46:52 +0900 (Tue, 18 Dec 2007)
New Revision: 14307
Added files:
trunk/test/net/http/utils.rb
Modified files:
trunk/ChangeLog
trunk/test/net/http/test_http.rb
Log:
* test/net/http/utils.rb: split TestNetHTTPUtils module from
test/net/http/test_http.rb. and start HTTP server in each test case.
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/net/http/utils.rb?revision=14307&view=markup
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=14307&r2=14306
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/net/http/test_http.rb?r1=14307&r2=14306
Index: ChangeLog
===================================================================
--- ChangeLog (revision 14306)
+++ ChangeLog (revision 14307)
@@ -1,3 +1,8 @@
+Tue Dec 18 23:44:32 2007 GOTOU Yuuzou <gotoyuzo@n...>
+
+ * test/net/http/utils.rb: split TestNetHTTPUtils module from
+ test/net/http/test_http.rb. and start HTTP server in each test case.
+
Tue Dec 18 23:27:51 2007 GOTOU Yuuzou <gotoyuzo@n...>
* lib/webrick/server.rb (WEBrick::GenericServer#accept_client):
Index: test/net/http/test_http.rb
===================================================================
--- test/net/http/test_http.rb (revision 14306)
+++ test/net/http/test_http.rb (revision 14307)
@@ -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 @@
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',
Index: test/net/http/utils.rb
===================================================================
--- test/net/http/utils.rb (revision 0)
+++ test/net/http/utils.rb (revision 14307)
@@ -0,0 +1,82 @@
+require 'webrick'
+require 'webrick/httpservlet/abstract'
+
+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
+ @server.shutdown
+ until @server.status == :Stop
+ sleep 0.1
+ end
+ # resume global state
+ Net::HTTP.version_1_2
+ end
+
+ def spawn_server
+ @server = WEBrick::HTTPServer.new(
+ :BindAddress => config('host'),
+ :Port => config('port'),
+ :Logger => WEBrick::Log.new(NullWriter.new),
+ :AccessLog => [],
+ :ShutdownSocketWithoutClose => true,
+ :ServerType => Thread
+ )
+ @server.mount('/', Servlet)
+ @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
+ 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
--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml