diff --git a/test/drb/drbtest.rb b/test/drb/drbtest.rb index 668a260825..8ca575089f 100644 --- a/test/drb/drbtest.rb +++ b/test/drb/drbtest.rb @@ -63,9 +63,9 @@ class XArray < Array end end -module DRbCore - def setup - @service_name = 'ut_drb.rb' +module DRbBase + def setup_service(service_name) + @service_name = service_name @ext = DRbService.ext_service(@service_name) @there = @ext.front end @@ -94,6 +94,10 @@ module DRbCore end } end +end + +module DRbCore + include DRbBase def test_00_DRbObject ro = DRbObject.new(nil, 'druby://localhost:12345') @@ -288,36 +292,7 @@ module DRbCore end module DRbAry - def setup - @service_name = 'ut_array.rb' - @ext = DRbService.ext_service(@service_name) - @there = @ext.front - end - - def teardown - @ext.stop_service if defined?(@ext) && @ext - DRbService.manager.unregist(@service_name) - while (@there&&@there.to_s rescue nil) - # nop - end - signal = /mswin|mingw/ =~ RUBY_PLATFORM ? :KILL : :TERM - Thread.list.each {|th| - if th.respond_to?(:pid) && th[:drb_service] == @service_name - 10.times do - begin - Process.kill signal, th.pid - break - rescue Errno::ESRCH - break - rescue Errno::EPERM # on Windows - sleep 0.1 - retry - end - end - th.join - end - } - end + include DRbBase def test_01 assert_kind_of(DRb::DRbObject, @there) diff --git a/test/drb/ignore_test_drb.rb b/test/drb/ignore_test_drb.rb index d0bb1f49b0..217c1c3f6b 100644 --- a/test/drb/ignore_test_drb.rb +++ b/test/drb/ignore_test_drb.rb @@ -4,21 +4,7 @@ class TestDRbReusePort < Test::Unit::TestCase include DRbAry def setup - @ext = DRbService.ext_service('ut_port.rb') - @there = @ext.front - end - - def teardown - return unless @ext - @ext.stop_service - while true - sleep 0.1 - begin - @ext.alive? - rescue DRb::DRbConnError - break - end - end + setup_service 'ut_port.rb' end end diff --git a/test/drb/test_drb.rb b/test/drb/test_drb.rb index 5841687b38..573818558a 100644 --- a/test/drb/test_drb.rb +++ b/test/drb/test_drb.rb @@ -2,16 +2,19 @@ require_relative 'drbtest' class TestDRbCore < Test::Unit::TestCase include DRbCore + + def setup + setup_service 'ut_drb.rb' + super + end end class TestDRbYield < Test::Unit::TestCase - def setup - @ext = DRbService.ext_service('ut_drb.rb') - @there = @ext.front - end + include DRbBase - def teardown - @ext.stop_service if @ext + def setup + setup_service 'ut_drb.rb' + super end def test_01_one @@ -177,12 +180,19 @@ end class TestDRbAry < Test::Unit::TestCase include DRbAry + + def setup + setup_service 'ut_array.rb' + super + end end class TestDRbMServer < Test::Unit::TestCase + include DRbBase + def setup - @ext = DRbService.ext_service('ut_drb.rb') - @there = @ext.front + setup_service 'ut_drb.rb' + super @server = (1..3).collect do |n| DRb::DRbServer.new(nil, Onecky.new(n.to_s)) end @@ -192,7 +202,7 @@ class TestDRbMServer < Test::Unit::TestCase @server.each do |s| s.stop_service end - @ext.stop_service if @ext + super end def test_01 @@ -202,9 +212,7 @@ end class TestDRbSafe1 < TestDRbAry def setup - @service_name = 'ut_safe1.rb' - @ext = DRbService.ext_service(@service_name) - @there = @ext.front + setup_service 'ut_safe1.rb' end end @@ -258,13 +266,11 @@ class TestDRbEval # < Test::Unit::TestCase end class TestDRbLarge < Test::Unit::TestCase - def setup - @ext = DRbService.ext_service('ut_large.rb') - @there = @ext.front - end + include DRbBase - def teardown - @ext.stop_service if @ext + def setup + setup_service 'ut_large.rb' + super end def test_01_large_ary @@ -302,13 +308,11 @@ class TestDRbLarge < Test::Unit::TestCase end class TestBug4409 < Test::Unit::TestCase - def setup - @ext = DRbService.ext_service('ut_eq.rb') - @there = @ext.front - end + include DRbBase - def teardown - @ext.stop_service if @ext + def setup + setup_service 'ut_eq.rb' + super end def test_bug4409 diff --git a/test/drb/test_drbssl.rb b/test/drb/test_drbssl.rb index 6322434eaa..a54e2234ba 100644 --- a/test/drb/test_drbssl.rb +++ b/test/drb/test_drbssl.rb @@ -36,9 +36,8 @@ end class TestDRbSSLCore < Test::Unit::TestCase include DRbCore def setup - @service_name = 'ut_drb_drbssl.rb' - @ext = DRbSSLService.ext_service(@service_name) - @there = @ext.front + setup_service 'ut_drb_drbssl.rb' + super end def test_02_unknown @@ -54,9 +53,8 @@ end class TestDRbSSLAry < Test::Unit::TestCase include DRbAry def setup - @service_name = 'ut_array_drbssl.rb' - @ext = DRbSSLService.ext_service(@service_name) - @there = @ext.front + setup_service 'ut_array_drbssl.rb' + super end end diff --git a/test/drb/test_drbunix.rb b/test/drb/test_drbunix.rb index 1fba033aca..ffc09e25b3 100644 --- a/test/drb/test_drbunix.rb +++ b/test/drb/test_drbunix.rb @@ -20,9 +20,8 @@ end class TestDRbUNIXCore < Test::Unit::TestCase include DRbCore def setup - @service_name = 'ut_drb_drbunix.rb' - @ext = DRbUNIXService.ext_service(@service_name) - @there = @ext.front + setup_service 'ut_drb_drbunix.rb' + super end def test_02_unknown @@ -38,9 +37,8 @@ end class TestDRbUNIXAry < Test::Unit::TestCase include DRbAry def setup - @service_name = 'ut_array_drbunix.rb' - @ext = DRbUNIXService.ext_service(@service_name) - @there = @ext.front + setup_service 'ut_array_drbunix.rb' + super end end