summaryrefslogtreecommitdiff
path: root/test/webrick/utils.rb
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-11-09 14:01:20 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-11-09 14:01:20 +0000
commitad58f04833b6d9f6b0d01c5fc8adc61df6d088cc (patch)
treef2484838869a97b049adf8b1f487513f5554569c /test/webrick/utils.rb
parent0d07bc203c421e9ebda8ef3ae50230f6b1866a71 (diff)
* 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
Diffstat (limited to 'test/webrick/utils.rb')
-rw-r--r--test/webrick/utils.rb26
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