ruby-changes:36256
From: akr <ko1@a...>
Date: Sun, 9 Nov 2014 18:07:54 +0900 (JST)
Subject: [ruby-changes:36256] akr:r48337 (trunk): * test/xmlrpc: Use assert_join_threads.
akr 2014-11-09 18:07:41 +0900 (Sun, 09 Nov 2014) New Revision: 48337 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=48337 Log: * test/xmlrpc: Use assert_join_threads. Modified files: trunk/ChangeLog trunk/test/xmlrpc/test_cookie.rb trunk/test/xmlrpc/test_webrick_server.rb trunk/test/xmlrpc/webrick_testing.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 48336) +++ ChangeLog (revision 48337) @@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sun Nov 9 18:07:00 2014 Tanaka Akira <akr@f...> + + * test/xmlrpc: Use assert_join_threads. + Sun Nov 9 14:06:13 2014 Tanaka Akira <akr@f...> * test/xmlrpc: Test webrick error log is empty. Index: test/xmlrpc/webrick_testing.rb =================================================================== --- test/xmlrpc/webrick_testing.rb (revision 48336) +++ test/xmlrpc/webrick_testing.rb (revision 48337) @@ -37,14 +37,20 @@ module WEBrick_Testing https://github.com/ruby/ruby/blob/trunk/test/xmlrpc/webrick_testing.rb#L37 addr end - def stop_server - return if !defined?(@__server) || !@__server - Timeout.timeout(5) { - @__server.shutdown - Thread.pass while @__started # wait until the server is down - } - @__server_thread.join - @__server = nil + def with_server(config, servlet) + addr = start_server(config) {|w| w.mount('/RPC2', create_servlet) } + client_thread = Thread.new { + begin + yield addr + ensure + @__server.shutdown + end + } + server_thread = Thread.new { + @__server_thread.join + @__server = nil + } + assert_join_threads([client_thread, server_thread]) end end end Index: test/xmlrpc/test_cookie.rb =================================================================== --- test/xmlrpc/test_cookie.rb (revision 48336) +++ test/xmlrpc/test_cookie.rb (revision 48337) @@ -66,22 +66,20 @@ class TestCookie < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/xmlrpc/test_cookie.rb#L66 s end - def setup_http_server + def setup_http_server_option option = {:Port => 0} - - addr = start_server(option) {|w| w.mount('/RPC2', create_servlet) } - - @s = XMLRPC::Client.new3(:host => addr.ip_address, :port => addr.ip_port) end def test_cookie - begin - setup_http_server - do_test - ensure - @s.http.finish - stop_server - end + option = setup_http_server_option + with_server(option, create_servlet) {|addr| + begin + @s = XMLRPC::Client.new3(:host => addr.ip_address, :port => addr.ip_port) + do_test + ensure + @s.http.finish + end + } end def do_test Index: test/xmlrpc/test_webrick_server.rb =================================================================== --- test/xmlrpc/test_webrick_server.rb (revision 48336) +++ test/xmlrpc/test_webrick_server.rb (revision 48337) @@ -47,7 +47,7 @@ class Test_Webrick < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/xmlrpc/test_webrick_server.rb#L47 return s end - def setup_http_server(use_ssl) + def setup_http_server_option(use_ssl) option = { :BindAddress => "localhost", :Port => 0, @@ -61,14 +61,14 @@ class Test_Webrick < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/xmlrpc/test_webrick_server.rb#L61 ) end - start_server(option) {|w| w.mount('/RPC2', create_servlet) } + option end def test_client_server # NOTE: I don't enable SSL testing as this hangs [false].each do |use_ssl| - begin - addr = setup_http_server(use_ssl) + option = setup_http_server_option(use_ssl) + with_server(option, create_servlet) {|addr| @s = XMLRPC::Client.new3(:host => addr.ip_address, :port => addr.ip_port, :use_ssl => use_ssl) @s.user = 'admin' @s.password = 'admin' @@ -83,9 +83,7 @@ class Test_Webrick < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/xmlrpc/test_webrick_server.rb#L83 do_test end @s.http.finish - ensure - stop_server - end + } end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/