1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* test/webrick: Store log in an array.

* test/net/http: Ditto.

* test/open-uri: Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48341 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2014-11-09 11:51:06 +00:00
parent 9b559f194c
commit 070c310e87
9 changed files with 45 additions and 33 deletions

View file

@ -1,3 +1,11 @@
Sun Nov 9 20:29:01 2014 Tanaka Akira <akr@fsij.org>
* test/webrick: Store log in an array.
* test/net/http: Ditto.
* test/open-uri: Ditto.
Sun Nov 9 18:35:36 2014 Tanaka Akira <akr@fsij.org>
* test/xmlrpc: Refine log test.

View file

@ -277,7 +277,7 @@ module TestNetHTTP_version_1_1_methods
end
}
assert_equal 1, i
@log_pattern = nil # server may encount ECONNRESET
@log_tester = nil # server may encount ECONNRESET
end
def test_get__implicit_start

View file

@ -117,7 +117,10 @@ class TestNetHTTPS < Test::Unit::TestCase
end
}
assert_match(/certificate verify failed/, ex.message)
@log_pattern = /ERROR OpenSSL::SSL::SSLError:/
@log_tester = lambda {|log|
assert_equal(1, log.length)
assert_match(/ERROR OpenSSL::SSL::SSLError:/, log[0])
}
end
def test_identity_verify_failure

View file

@ -36,14 +36,14 @@ module TestNetHTTPUtils
@server.shutdown
@server_thread.join
end
assert_match(@log_pattern, @log.string) if @log_pattern
@log_tester.call(@log) if @log_tester
# resume global state
Net::HTTP.version_1_2
end
def spawn_server
@log = StringIO.new('')
@log_pattern = /\A\z/
@log = []
@log_tester = lambda {|log| assert_equal([], log ) }
@config = self.class::CONFIG
server_config = {
:BindAddress => config('host'),

View file

@ -14,7 +14,7 @@ class TestOpenURI < Test::Unit::TestCase
end
def with_http(log_is_empty=true)
log = StringIO.new('')
log = []
logger = WEBrick::Log.new(log, WEBrick::BasicLog::WARN)
Dir.mktmpdir {|dr|
srv = WEBrick::HTTPServer.new({
@ -34,7 +34,7 @@ class TestOpenURI < Test::Unit::TestCase
end
}
if log_is_empty
assert_equal("", log.string)
assert_equal([], log)
end
end
@ -92,7 +92,8 @@ class TestOpenURI < Test::Unit::TestCase
}
server_thread2 = Thread.new {
server_thread.join
assert_match(%r{ERROR `/not-exist' not found}, server_log.string)
assert_equal(1, server_log.length)
assert_match(%r{ERROR `/not-exist' not found}, server_log[0])
}
assert_join_threads([client_thread, server_thread2])
}
@ -486,7 +487,8 @@ class TestOpenURI < Test::Unit::TestCase
}
server_thread2 = Thread.new {
server_thread.join
assert_match(/ERROR WEBrick::HTTPStatus::Unauthorized/, server_log.string)
assert_equal(1, server_log.length)
assert_match(/ERROR WEBrick::HTTPStatus::Unauthorized/, server_log[0])
}
assert_join_threads([client_thread, server_thread2])
}
@ -505,7 +507,8 @@ class TestOpenURI < Test::Unit::TestCase
}
server_thread2 = Thread.new {
server_thread.join
assert_match(/ERROR WEBrick::HTTPStatus::Unauthorized/, server_log.string)
assert_equal(1, server_log.length)
assert_match(/ERROR WEBrick::HTTPStatus::Unauthorized/, server_log[0])
}
assert_join_threads([client_thread, server_thread2])
}

View file

@ -19,7 +19,7 @@ class TestOpenURISSL
end
def with_https(log_is_empty=true)
log = StringIO.new('')
log = []
logger = WEBrick::Log.new(log, WEBrick::BasicLog::WARN)
Dir.mktmpdir {|dr|
srv = WEBrick::HTTPServer.new({
@ -42,7 +42,7 @@ class TestOpenURISSL
th.join
end
if log_is_empty
assert_equal("", log.string)
assert_equal([], log)
end
}
end
@ -96,14 +96,15 @@ class TestOpenURISSL
}
server_thread2 = Thread.new {
server_thread.join
assert_match(/ERROR OpenSSL::SSL::SSLError:/, server_log.string)
assert_equal(1, server_log.length)
assert_match(/ERROR OpenSSL::SSL::SSLError:/, server_log[0])
}
assert_join_threads([client_thread, server_thread2])
}
end
def with_https_proxy
proxy_log = StringIO.new('')
proxy_log = []
proxy_logger = WEBrick::Log.new(proxy_log, WEBrick::BasicLog::WARN)
with_https {|srv, dr, url, server_thread, server_log|
srv.mount_proc("/proxy", lambda { |req, res| res.body = "proxy" } )
@ -116,7 +117,7 @@ class TestOpenURISSL
proxy = WEBrick::HTTPProxyServer.new({
:ServerType => Thread,
:Logger => proxy_logger,
:AccessLog => [[proxy_access_log=StringIO.new, WEBrick::AccessLog::COMMON_LOG_FORMAT]],
:AccessLog => [[proxy_access_log=[], WEBrick::AccessLog::COMMON_LOG_FORMAT]],
:BindAddress => '127.0.0.1',
:Port => 0})
_, proxy_port, _, proxy_host = proxy.listeners[0].addr
@ -128,7 +129,7 @@ class TestOpenURISSL
proxy_thread.join
end
}
assert_equal('', proxy_log.string)
assert_equal([], proxy_log)
end
def test_proxy_cacert_file
@ -146,8 +147,9 @@ class TestOpenURISSL
}
proxy_thread2 = Thread.new {
proxy_thread.join
assert_match(%r[CONNECT #{url.sub(%r{\Ahttps://}, '')} ], proxy_access_log.string)
assert_equal('', proxy_log.string)
assert_equal(1, proxy_access_log.length)
assert_match(%r[CONNECT #{url.sub(%r{\Ahttps://}, '')} ], proxy_access_log[0])
assert_equal([], proxy_log)
}
assert_join_threads([client_thread, proxy_thread2, server_thread])
}
@ -168,8 +170,9 @@ class TestOpenURISSL
}
proxy_thread2 = Thread.new {
proxy_thread.join
assert_match(%r[CONNECT #{url.sub(%r{\Ahttps://}, '')} ], proxy_access_log.string)
assert_equal('', proxy_log.string)
assert_equal(1, proxy_access_log.length)
assert_match(%r[CONNECT #{url.sub(%r{\Ahttps://}, '')} ], proxy_access_log[0])
assert_equal([], proxy_log)
}
assert_join_threads([client_thread, proxy_thread2, server_thread])
}

View file

@ -61,7 +61,6 @@ class TestWEBrickHTTPAuth < Test::Unit::TestCase
http.request(g){|res| assert_not_equal("hoge", res.body, log.call)}
}
}
log = log.lines.to_a
log.reject! {|line| /\A\s*\z/ =~ line }
pats = [
/ERROR Basic WEBrick's realm: webrick: password unmatch\./,
@ -154,7 +153,6 @@ class TestWEBrickHTTPAuth < Test::Unit::TestCase
end
}
}
log = log.lines.to_a
log.reject! {|line| /\A\s*\z/ =~ line }
pats = [
/ERROR Digest WEBrick's realm: no credentials in the request\./,

View file

@ -26,7 +26,7 @@ class TestWEBrickServer < Test::Unit::TestCase
def test_start_exception
stopped = 0
log = StringIO.new('')
log = []
logger = WEBrick::Log.new(log, WEBrick::BasicLog::WARN)
assert_raises(SignalException) do
@ -47,7 +47,8 @@ class TestWEBrickServer < Test::Unit::TestCase
end
assert_equal(stopped, 1)
assert_match(/FATAL SignalException: SIGTERM/, log.string)
assert_equal(1, log.length)
assert_match(/FATAL SignalException: SIGTERM/, log[0])
end
def test_callbacks

View file

@ -32,17 +32,13 @@ module TestWEBrick
module_function
def start_server(klass, config={}, &block)
log_string = ""
logger = Object.new
logger.instance_eval do
define_singleton_method(:<<) {|msg| log_string << msg }
end
log = proc { "webrick log start:\n" + log_string.gsub(/^/, " ").chomp + "\nwebrick log end" }
log_ary = []
log = proc { "webrick log start:\n" + log_ary.join.gsub(/^/, " ").chomp + "\nwebrick log end" }
server = klass.new({
:BindAddress => "127.0.0.1", :Port => 0,
:ServerType => Thread,
:Logger => WEBrick::Log.new(logger, WEBrick::BasicLog::WARN),
:AccessLog => [[logger, ""]]
:Logger => WEBrick::Log.new(log_ary, WEBrick::BasicLog::WARN),
:AccessLog => [[log_ary, ""]]
}.update(config))
server_thread = server.start
addr = server.listeners[0].addr
@ -54,7 +50,7 @@ module TestWEBrick
end
}
assert_join_threads([client_thread, server_thread])
log_string
log_ary
end
def start_httpserver(config={}, &block)