* test/xmlrpc: Refine log test.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48339 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2014-11-09 09:36:33 +00:00
Родитель 62b511b6aa
Коммит 5ab3fe5fb5
3 изменённых файлов: 24 добавлений и 21 удалений

Просмотреть файл

@ -1,3 +1,7 @@
Sun Nov 9 18:35:36 2014 Tanaka Akira <akr@fsij.org>
* test/xmlrpc: Refine log test.
Sun Nov 9 18:33:33 2014 Martin Duerst <duerst@it.aoyama.ac.jp>
* lib/unicode_normalize/normalize.rb: Replaced if-else by

Просмотреть файл

@ -11,19 +11,19 @@ module TestXMLRPC
class Test_Webrick < Test::Unit::TestCase
include WEBrick_Testing
@@basic_auth = WEBrick::HTTPAuth::BasicAuth.new(
:Realm => 'auth',
:UserDB => WEBrick::HTTPAuth::Htpasswd.new(File.expand_path('./htpasswd', File.dirname(__FILE__))),
:Logger => NoLog,
)
def create_servlet
def create_servlet(server)
s = XMLRPC::WEBrickServlet.new
def s.service(req, res)
@@basic_auth.authenticate(req, res)
basic_auth = WEBrick::HTTPAuth::BasicAuth.new(
:Realm => 'auth',
:UserDB => WEBrick::HTTPAuth::Htpasswd.new(File.expand_path('./htpasswd', File.dirname(__FILE__))),
:Logger => server.logger,
)
class << s; self end.send(:define_method, :service) {|req, res|
basic_auth.authenticate(req, res)
super(req, res)
end
}
s.add_handler("test.add") do |a,b|
a + b
@ -68,7 +68,7 @@ class Test_Webrick < Test::Unit::TestCase
# NOTE: I don't enable SSL testing as this hangs
[false].each do |use_ssl|
option = setup_http_server_option(use_ssl)
with_server(option, create_servlet) {|addr|
with_server(option, method(:create_servlet)) {|addr|
@s = XMLRPC::Client.new3(:host => addr.ip_address, :port => addr.ip_port, :use_ssl => use_ssl)
@s.user = 'admin'
@s.password = 'admin'

Просмотреть файл

@ -2,21 +2,14 @@ require 'timeout'
module TestXMLRPC
module WEBrick_Testing
empty_log = Object.new
def empty_log.<<(str)
assert_equal('', str)
self
end
NoLog = WEBrick::Log.new(empty_log, WEBrick::BasicLog::WARN)
def start_server(config={})
def start_server(logger, config={})
raise "already started" if defined?(@__server) && @__server
@__started = false
@__server = WEBrick::HTTPServer.new(
{
:BindAddress => "localhost",
:Logger => NoLog,
:Logger => logger,
:AccessLog => [],
}.update(config))
yield @__server
@ -38,7 +31,12 @@ module WEBrick_Testing
end
def with_server(config, servlet)
addr = start_server(config) {|w| w.mount('/RPC2', create_servlet) }
log = []
logger = WEBrick::Log.new(log, WEBrick::BasicLog::WARN)
addr = start_server(logger, config) {|w|
servlet = servlet.call(w) if servlet.respond_to? :call
w.mount('/RPC2', servlet)
}
client_thread = Thread.new {
begin
yield addr
@ -49,6 +47,7 @@ module WEBrick_Testing
server_thread = Thread.new {
@__server_thread.join
@__server = nil
assert_equal([], log)
}
assert_join_threads([client_thread, server_thread])
end