mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* test/webrick: Examine log and use assert_join_threads.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48318 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
8222432c9d
commit
742bbbb01b
6 changed files with 65 additions and 28 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
Sun Nov 9 00:37:44 2014 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* test/webrick: Examine log and use assert_join_threads.
|
||||||
|
|
||||||
Fri Nov 7 00:00:12 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Fri Nov 7 00:00:12 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* template/unicode_norm_gen.tmpl: expand kompatible_table so that
|
* template/unicode_norm_gen.tmpl: expand kompatible_table so that
|
||||||
|
|
|
@ -27,7 +27,7 @@ class TestWEBrickHTTPAuth < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_basic_auth2
|
def test_basic_auth2
|
||||||
TestWEBrick.start_httpserver{|server, addr, port, log|
|
log = TestWEBrick.start_httpserver{|server, addr, port, log|
|
||||||
realm = "WEBrick's realm"
|
realm = "WEBrick's realm"
|
||||||
path = "/basic_auth2"
|
path = "/basic_auth2"
|
||||||
|
|
||||||
|
@ -61,6 +61,11 @@ class TestWEBrickHTTPAuth < Test::Unit::TestCase
|
||||||
http.request(g){|res| assert_not_equal("hoge", res.body, log.call)}
|
http.request(g){|res| assert_not_equal("hoge", res.body, log.call)}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pat = /ERROR Basic WEBrick's realm: webrick: password unmatch\./
|
||||||
|
assert_match(pat, log); log.sub!(pat, '')
|
||||||
|
pat = /ERROR WEBrick::HTTPStatus::Unauthorized/
|
||||||
|
assert_match(pat, log); log.sub!(pat, '')
|
||||||
|
assert_not_match(/ERROR/, log)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_basic_auth3
|
def test_basic_auth3
|
||||||
|
@ -92,7 +97,7 @@ class TestWEBrickHTTPAuth < Test::Unit::TestCase
|
||||||
)/x
|
)/x
|
||||||
|
|
||||||
def test_digest_auth
|
def test_digest_auth
|
||||||
TestWEBrick.start_httpserver{|server, addr, port, log|
|
log = TestWEBrick.start_httpserver{|server, addr, port, log|
|
||||||
realm = "WEBrick's realm"
|
realm = "WEBrick's realm"
|
||||||
path = "/digest_auth"
|
path = "/digest_auth"
|
||||||
|
|
||||||
|
@ -143,6 +148,15 @@ class TestWEBrickHTTPAuth < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pat = /ERROR Digest WEBrick's realm: no credentials in the request\./
|
||||||
|
assert_match(pat, log); log.sub!(pat, '')
|
||||||
|
pat = /ERROR WEBrick::HTTPStatus::Unauthorized/
|
||||||
|
assert_match(pat, log); log.sub!(pat, '')
|
||||||
|
pat = /ERROR Digest WEBrick's realm: webrick: digest unmatch\./
|
||||||
|
assert_match(pat, log); log.sub!(pat, '')
|
||||||
|
pat = /ERROR WEBrick::HTTPStatus::Unauthorized/
|
||||||
|
assert_match(pat, log); log.sub!(pat, '')
|
||||||
|
assert_not_match(/ERROR/, log)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -63,6 +63,7 @@ module WEBrick
|
||||||
assert_equal 'hello', r.read
|
assert_equal 'hello', r.read
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
assert_equal 0, logger.messages.length
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_send_body_string
|
def test_send_body_string
|
||||||
|
@ -75,6 +76,7 @@ module WEBrick
|
||||||
|
|
||||||
assert_equal 'hello', r.read
|
assert_equal 'hello', r.read
|
||||||
}
|
}
|
||||||
|
assert_equal 0, logger.messages.length
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_send_body_string_io
|
def test_send_body_string_io
|
||||||
|
@ -87,6 +89,7 @@ module WEBrick
|
||||||
|
|
||||||
assert_equal 'hello', r.read
|
assert_equal 'hello', r.read
|
||||||
}
|
}
|
||||||
|
assert_equal 0, logger.messages.length
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_send_body_io_chunked
|
def test_send_body_io_chunked
|
||||||
|
@ -108,6 +111,7 @@ module WEBrick
|
||||||
assert_equal "5\r\nhello\r\n0\r\n\r\n", r.read
|
assert_equal "5\r\nhello\r\n0\r\n\r\n", r.read
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
assert_equal 0, logger.messages.length
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_send_body_string_chunked
|
def test_send_body_string_chunked
|
||||||
|
@ -123,6 +127,7 @@ module WEBrick
|
||||||
r.binmode
|
r.binmode
|
||||||
assert_equal "5\r\nhello\r\n0\r\n\r\n", r.read
|
assert_equal "5\r\nhello\r\n0\r\n\r\n", r.read
|
||||||
}
|
}
|
||||||
|
assert_equal 0, logger.messages.length
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_send_body_string_io_chunked
|
def test_send_body_string_io_chunked
|
||||||
|
@ -138,6 +143,7 @@ module WEBrick
|
||||||
r.binmode
|
r.binmode
|
||||||
assert_equal "5\r\nhello\r\n0\r\n\r\n", r.read
|
assert_equal "5\r\nhello\r\n0\r\n\r\n", r.read
|
||||||
}
|
}
|
||||||
|
assert_equal 0, logger.messages.length
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,9 +4,16 @@ require "webrick"
|
||||||
require_relative "utils"
|
require_relative "utils"
|
||||||
|
|
||||||
class TestWEBrickHTTPServer < Test::Unit::TestCase
|
class TestWEBrickHTTPServer < Test::Unit::TestCase
|
||||||
|
empty_log = Object.new
|
||||||
|
def empty_log.<<(str)
|
||||||
|
assert_equal('', str)
|
||||||
|
self
|
||||||
|
end
|
||||||
|
NoLog = WEBrick::Log.new(empty_log, WEBrick::BasicLog::WARN)
|
||||||
|
|
||||||
def test_mount
|
def test_mount
|
||||||
httpd = WEBrick::HTTPServer.new(
|
httpd = WEBrick::HTTPServer.new(
|
||||||
:Logger => WEBrick::Log.new(TestWEBrick::NullWriter),
|
:Logger => NoLog,
|
||||||
:DoNotListen=>true
|
:DoNotListen=>true
|
||||||
)
|
)
|
||||||
httpd.mount("/", :Root)
|
httpd.mount("/", :Root)
|
||||||
|
@ -75,7 +82,7 @@ class TestWEBrickHTTPServer < Test::Unit::TestCase
|
||||||
|
|
||||||
def httpd(addr, port, host, ali)
|
def httpd(addr, port, host, ali)
|
||||||
config ={
|
config ={
|
||||||
:Logger => WEBrick::Log.new(TestWEBrick::NullWriter),
|
:Logger => NoLog,
|
||||||
:DoNotListen => true,
|
:DoNotListen => true,
|
||||||
:BindAddress => addr,
|
:BindAddress => addr,
|
||||||
:Port => port,
|
:Port => port,
|
||||||
|
@ -229,7 +236,7 @@ class TestWEBrickHTTPServer < Test::Unit::TestCase
|
||||||
:BindAddress => addr,
|
:BindAddress => addr,
|
||||||
:Port => port,
|
:Port => port,
|
||||||
:DoNotListen => true,
|
:DoNotListen => true,
|
||||||
:Logger => WEBrick::Log.new(TestWEBrick::NullWriter),
|
:Logger => NoLog,
|
||||||
:AccessLog => [],
|
:AccessLog => [],
|
||||||
:RequestCallback => Proc.new{|req, res| requested1 += 1 },
|
:RequestCallback => Proc.new{|req, res| requested1 += 1 },
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,27 +25,29 @@ class TestWEBrickServer < Test::Unit::TestCase
|
||||||
|
|
||||||
def test_start_exception
|
def test_start_exception
|
||||||
stopped = 0
|
stopped = 0
|
||||||
config = {
|
|
||||||
:StopCallback => Proc.new{ stopped += 1 },
|
log = StringIO.new('')
|
||||||
}
|
logger = WEBrick::Log.new(log, WEBrick::BasicLog::WARN)
|
||||||
|
|
||||||
assert_raises(SignalException) do
|
assert_raises(SignalException) do
|
||||||
TestWEBrick.start_server(Echo, config) { |server, addr, port, log|
|
listener = Object.new
|
||||||
listener = server.listeners.first
|
def listener.to_io # IO.select invokes #to_io.
|
||||||
|
raise SignalException, 'SIGTERM' # simulate signal in main thread
|
||||||
|
end
|
||||||
|
|
||||||
def listener.accept
|
server = WEBrick::HTTPServer.new({
|
||||||
raise SignalException, 'SIGTERM' # simulate signal in main thread
|
:BindAddress => "127.0.0.1", :Port => 0,
|
||||||
end
|
:StopCallback => Proc.new{ stopped += 1 },
|
||||||
|
:Logger => logger,
|
||||||
|
})
|
||||||
|
server.listeners[0].close
|
||||||
|
server.listeners[0] = listener
|
||||||
|
|
||||||
Thread.pass while server.status != :Running
|
server.start
|
||||||
|
|
||||||
TCPSocket.open(addr, port) { |sock| sock << "foo\n" }
|
|
||||||
|
|
||||||
Thread.pass until server.status == :Stop
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_equal(stopped, 1)
|
assert_equal(stopped, 1)
|
||||||
|
assert_match(/FATAL SignalException: SIGTERM/, log.string)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_callbacks
|
def test_callbacks
|
||||||
|
|
|
@ -26,6 +26,9 @@ module TestWEBrick
|
||||||
RubyBin << " \"-I#{File.dirname(EnvUtil.rubybin)}/.ext/common\""
|
RubyBin << " \"-I#{File.dirname(EnvUtil.rubybin)}/.ext/common\""
|
||||||
RubyBin << " \"-I#{File.dirname(EnvUtil.rubybin)}/.ext/#{RUBY_PLATFORM}\""
|
RubyBin << " \"-I#{File.dirname(EnvUtil.rubybin)}/.ext/#{RUBY_PLATFORM}\""
|
||||||
|
|
||||||
|
include Test::Unit::Assertions
|
||||||
|
extend Test::Unit::Assertions
|
||||||
|
|
||||||
module_function
|
module_function
|
||||||
|
|
||||||
def start_server(klass, config={}, &block)
|
def start_server(klass, config={}, &block)
|
||||||
|
@ -41,15 +44,16 @@ module TestWEBrick
|
||||||
:Logger => WEBrick::Log.new(logger),
|
:Logger => WEBrick::Log.new(logger),
|
||||||
:AccessLog => [[logger, ""]]
|
:AccessLog => [[logger, ""]]
|
||||||
}.update(config))
|
}.update(config))
|
||||||
begin
|
server_thread = server.start
|
||||||
server_thread = server.start
|
addr = server.listeners[0].addr
|
||||||
addr = server.listeners[0].addr
|
client_thread = Thread.new {
|
||||||
block.yield([server, addr[3], addr[1], log])
|
begin
|
||||||
ensure
|
block.yield([server, addr[3], addr[1], log])
|
||||||
server.shutdown
|
ensure
|
||||||
|
server.shutdown
|
||||||
server_thread.join
|
end
|
||||||
end
|
}
|
||||||
|
assert_join_threads([client_thread, server_thread])
|
||||||
log_string
|
log_string
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue