From ad58f04833b6d9f6b0d01c5fc8adc61df6d088cc Mon Sep 17 00:00:00 2001 From: akr Date: Sun, 9 Nov 2014 14:01:20 +0000 Subject: * 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 --- test/webrick/utils.rb | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'test/webrick/utils.rb') 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 -- cgit v1.2.3