diff options
Diffstat (limited to 'test/webrick/utils.rb')
-rw-r--r-- | test/webrick/utils.rb | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/test/webrick/utils.rb b/test/webrick/utils.rb index e1c2344fb1..0e94ad34da 100644 --- a/test/webrick/utils.rb +++ b/test/webrick/utils.rb @@ -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 |