mirror of
https://github.com/ruby/ruby.git
synced 2025-08-24 05:25:34 +02:00
* test/open-uri: Test server log in server thread.
* test/webrick: Ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48347 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
0d07bc203c
commit
ad58f04833
8 changed files with 203 additions and 169 deletions
|
@ -31,16 +31,25 @@ module TestWEBrick
|
|||
|
||||
module_function
|
||||
|
||||
def start_server(klass, config={}, &block)
|
||||
DefaultLogTester = lambda {|log, access_log| assert_equal([], log) }
|
||||
|
||||
def start_server(klass, config={}, log_tester=DefaultLogTester, &block)
|
||||
log_ary = []
|
||||
log = proc { "webrick log start:\n" + log_ary.join.gsub(/^/, " ").chomp + "\nwebrick log end" }
|
||||
access_log_ary = []
|
||||
log = proc { "webrick log start:\n" + (log_ary+access_log_ary).join.gsub(/^/, " ").chomp + "\nwebrick log end" }
|
||||
server = klass.new({
|
||||
:BindAddress => "127.0.0.1", :Port => 0,
|
||||
:ServerType => Thread,
|
||||
:Logger => WEBrick::Log.new(log_ary, WEBrick::BasicLog::WARN),
|
||||
:AccessLog => [[log_ary, ""]]
|
||||
:AccessLog => [[access_log_ary, ""]]
|
||||
}.update(config))
|
||||
server_thread = server.start
|
||||
server_thread2 = Thread.new {
|
||||
server_thread.join
|
||||
if log_tester
|
||||
log_tester.call(log_ary, access_log_ary)
|
||||
end
|
||||
}
|
||||
addr = server.listeners[0].addr
|
||||
client_thread = Thread.new {
|
||||
begin
|
||||
|
@ -49,15 +58,14 @@ module TestWEBrick
|
|||
server.shutdown
|
||||
end
|
||||
}
|
||||
assert_join_threads([client_thread, server_thread])
|
||||
log_ary
|
||||
assert_join_threads([client_thread, server_thread2])
|
||||
end
|
||||
|
||||
def start_httpserver(config={}, &block)
|
||||
start_server(WEBrick::HTTPServer, config, &block)
|
||||
def start_httpserver(config={}, log_tester=DefaultLogTester, &block)
|
||||
start_server(WEBrick::HTTPServer, config, log_tester, &block)
|
||||
end
|
||||
|
||||
def start_httpproxy(config={}, &block)
|
||||
start_server(WEBrick::HTTPProxyServer, config, &block)
|
||||
def start_httpproxy(config={}, log_tester=DefaultLogTester, &block)
|
||||
start_server(WEBrick::HTTPProxyServer, config, log_tester, &block)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue