summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-11-09 09:07:41 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-11-09 09:07:41 +0000
commitb30ff6839db848efafc4b7b61abed0e2708d2627 (patch)
tree49c5d6117186319a90b65773b221904882029dfb /test
parenta4b5982b4c95b0c6779748bf010aa7445714f343 (diff)
* test/xmlrpc: Use assert_join_threads.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48337 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/xmlrpc/test_cookie.rb22
-rw-r--r--test/xmlrpc/test_webrick_server.rb12
-rw-r--r--test/xmlrpc/webrick_testing.rb22
3 files changed, 29 insertions, 27 deletions
diff --git a/test/xmlrpc/test_cookie.rb b/test/xmlrpc/test_cookie.rb
index 4f5e17a1b5d..cfcfe4c3f0b 100644
--- a/test/xmlrpc/test_cookie.rb
+++ b/test/xmlrpc/test_cookie.rb
@@ -66,22 +66,20 @@ class TestCookie < Test::Unit::TestCase
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
diff --git a/test/xmlrpc/test_webrick_server.rb b/test/xmlrpc/test_webrick_server.rb
index 0877ad2e6a5..36d64d50930 100644
--- a/test/xmlrpc/test_webrick_server.rb
+++ b/test/xmlrpc/test_webrick_server.rb
@@ -47,7 +47,7 @@ class Test_Webrick < Test::Unit::TestCase
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::TestCase
)
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::TestCase
do_test
end
@s.http.finish
- ensure
- stop_server
- end
+ }
end
end
diff --git a/test/xmlrpc/webrick_testing.rb b/test/xmlrpc/webrick_testing.rb
index e2a0c3f1334..cfbaba07d9a 100644
--- a/test/xmlrpc/webrick_testing.rb
+++ b/test/xmlrpc/webrick_testing.rb
@@ -37,14 +37,20 @@ module WEBrick_Testing
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