mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Run background threads while testing drb
Do not start background thread on load test/drb/drbtest.rb, and stop threads on each test. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65247 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
eab51f71d6
commit
4757c7eead
4 changed files with 107 additions and 124 deletions
|
@ -7,7 +7,6 @@ require 'timeout'
|
|||
module DRbTests
|
||||
|
||||
class DRbService
|
||||
@@manager = DRb::ExtServManager.new
|
||||
@@ruby = [EnvUtil.rubybin]
|
||||
@@ruby << "-d" if $DEBUG
|
||||
def self.add_service_command(nm)
|
||||
|
@ -18,21 +17,31 @@ class DRbService
|
|||
%w(ut_drb.rb ut_array.rb ut_port.rb ut_large.rb ut_safe1.rb ut_eq.rb).each do |nm|
|
||||
add_service_command(nm)
|
||||
end
|
||||
@server = @@server = DRb::DRbServer.new('druby://localhost:0', @@manager, {})
|
||||
@@manager.uri = @@server.uri
|
||||
def self.manager
|
||||
@@manager
|
||||
|
||||
def initialize
|
||||
@manager = DRb::ExtServManager.new
|
||||
start
|
||||
@manager.uri = server.uri
|
||||
end
|
||||
def self.server
|
||||
@server || @@server
|
||||
|
||||
def start
|
||||
@server = DRb::DRbServer.new('druby://localhost:0', manager, {})
|
||||
end
|
||||
def self.ext_service(name)
|
||||
|
||||
attr_reader :manager
|
||||
attr_reader :server
|
||||
|
||||
def ext_service(name)
|
||||
Timeout.timeout(100, RuntimeError) do
|
||||
manager.service(name)
|
||||
end
|
||||
end
|
||||
def self.finish
|
||||
@server.instance_variable_get(:@grp).list.each {|th| th.join }
|
||||
|
||||
def finish
|
||||
server.instance_variable_get(:@grp).list.each {|th| th.join }
|
||||
server.stop_service
|
||||
manager.instance_variable_get(:@queue)&.push(nil)
|
||||
manager.instance_variable_get(:@thread)&.join
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -68,15 +77,20 @@ class XArray < Array
|
|||
end
|
||||
|
||||
module DRbBase
|
||||
def setup
|
||||
@drb_service ||= DRbService.new
|
||||
end
|
||||
|
||||
def setup_service(service_name)
|
||||
@service_name = service_name
|
||||
@ext = DRbService.ext_service(@service_name)
|
||||
@ext = @drb_service.ext_service(@service_name)
|
||||
@there = @ext.front
|
||||
end
|
||||
|
||||
def teardown
|
||||
@ext.stop_service if defined?(@ext) && @ext
|
||||
DRbService.manager.unregist(@service_name)
|
||||
if defined?(@service_name) && @service_name
|
||||
@drb_service.manager.unregist(@service_name)
|
||||
while (@there&&@there.to_s rescue nil)
|
||||
# nop
|
||||
end
|
||||
|
@ -98,6 +112,8 @@ module DRbBase
|
|||
end
|
||||
}
|
||||
end
|
||||
@drb_service.finish
|
||||
end
|
||||
end
|
||||
|
||||
module DRbCore
|
||||
|
|
|
@ -7,29 +7,14 @@ class TestDRbCore < Test::Unit::TestCase
|
|||
include DRbCore
|
||||
|
||||
def setup
|
||||
super
|
||||
setup_service 'ut_drb.rb'
|
||||
super
|
||||
end
|
||||
|
||||
def teardown
|
||||
super
|
||||
DRbService.finish
|
||||
end
|
||||
end
|
||||
|
||||
class TestDRbYield < Test::Unit::TestCase
|
||||
module DRbYield
|
||||
include DRbBase
|
||||
|
||||
def setup
|
||||
setup_service 'ut_drb.rb'
|
||||
super
|
||||
end
|
||||
|
||||
def teardown
|
||||
super
|
||||
DRbService.finish
|
||||
end
|
||||
|
||||
def test_01_one
|
||||
@there.echo_yield_1([]) {|one|
|
||||
assert_equal([], one)
|
||||
|
@ -129,7 +114,23 @@ class TestDRbYield < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
class TestDRbRubyYield < TestDRbYield
|
||||
class TestDRbYield < Test::Unit::TestCase
|
||||
include DRbYield
|
||||
|
||||
def setup
|
||||
super
|
||||
setup_service 'ut_drb.rb'
|
||||
end
|
||||
end
|
||||
|
||||
class TestDRbRubyYield < Test::Unit::TestCase
|
||||
include DRbYield
|
||||
|
||||
def setup
|
||||
@there = self
|
||||
super
|
||||
end
|
||||
|
||||
def echo_yield(*arg)
|
||||
yield(*arg)
|
||||
end
|
||||
|
@ -153,15 +154,11 @@ class TestDRbRubyYield < TestDRbYield
|
|||
end
|
||||
end
|
||||
|
||||
def setup
|
||||
@there = self
|
||||
end
|
||||
|
||||
def teardown
|
||||
end
|
||||
end
|
||||
|
||||
class TestDRbRuby18Yield < TestDRbRubyYield
|
||||
class TestDRbRuby18Yield < Test::Unit::TestCase
|
||||
include DRbYield
|
||||
|
||||
class YieldTest18
|
||||
def echo_yield(*arg, &proc)
|
||||
proc.call(*arg)
|
||||
|
@ -188,6 +185,7 @@ class TestDRbRuby18Yield < TestDRbRubyYield
|
|||
|
||||
def setup
|
||||
@there = YieldTest18.new
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -195,13 +193,8 @@ class TestDRbAry < Test::Unit::TestCase
|
|||
include DRbAry
|
||||
|
||||
def setup
|
||||
super
|
||||
setup_service 'ut_array.rb'
|
||||
super
|
||||
end
|
||||
|
||||
def teardown
|
||||
super
|
||||
DRbService.finish
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -209,8 +202,8 @@ class TestDRbMServer < Test::Unit::TestCase
|
|||
include DRbBase
|
||||
|
||||
def setup
|
||||
setup_service 'ut_drb.rb'
|
||||
super
|
||||
setup_service 'ut_drb.rb'
|
||||
@server = (1..3).collect do |n|
|
||||
DRb::DRbServer.new("druby://localhost:0", Onecky.new(n.to_s))
|
||||
end
|
||||
|
@ -221,7 +214,6 @@ class TestDRbMServer < Test::Unit::TestCase
|
|||
s.stop_service
|
||||
end
|
||||
super
|
||||
DRbService.finish
|
||||
end
|
||||
|
||||
def test_01
|
||||
|
@ -229,14 +221,11 @@ class TestDRbMServer < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
class TestDRbSafe1 < TestDRbAry
|
||||
class TestDRbSafe1 < Test::Unit::TestCase
|
||||
include DRbAry
|
||||
def setup
|
||||
setup_service 'ut_safe1.rb'
|
||||
end
|
||||
|
||||
def teardown
|
||||
super
|
||||
DRbService.finish
|
||||
setup_service 'ut_safe1.rb'
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -244,13 +233,8 @@ class TestDRbLarge < Test::Unit::TestCase
|
|||
include DRbBase
|
||||
|
||||
def setup
|
||||
super
|
||||
setup_service 'ut_large.rb'
|
||||
super
|
||||
end
|
||||
|
||||
def teardown
|
||||
super
|
||||
DRbService.finish
|
||||
end
|
||||
|
||||
def test_01_large_ary
|
||||
|
@ -333,13 +317,8 @@ class TestBug4409 < Test::Unit::TestCase
|
|||
include DRbBase
|
||||
|
||||
def setup
|
||||
super
|
||||
setup_service 'ut_eq.rb'
|
||||
super
|
||||
end
|
||||
|
||||
def teardown
|
||||
super
|
||||
DRbService.finish
|
||||
end
|
||||
|
||||
def test_bug4409
|
||||
|
|
|
@ -15,6 +15,8 @@ class DRbSSLService < DRbService
|
|||
%w(ut_drb_drbssl.rb ut_array_drbssl.rb).each do |nm|
|
||||
add_service_command(nm)
|
||||
end
|
||||
|
||||
def start
|
||||
config = Hash.new
|
||||
|
||||
config[:SSLVerifyMode] = OpenSSL::SSL::VERIFY_PEER
|
||||
|
@ -32,20 +34,16 @@ class DRbSSLService < DRbService
|
|||
[ ["C","JP"], ["O","Foo.DRuby.Org"], ["CN", "Sample"] ]
|
||||
end
|
||||
|
||||
uri = ARGV.shift if $0 == __FILE__
|
||||
@server = DRb::DRbServer.new(uri || 'drbssl://:0', self.manager, config)
|
||||
@server = DRb::DRbServer.new('drbssl://:0', manager, config)
|
||||
end
|
||||
end
|
||||
|
||||
class TestDRbSSLCore < Test::Unit::TestCase
|
||||
include DRbCore
|
||||
def setup
|
||||
@drb_service = DRbSSLService.new
|
||||
super
|
||||
setup_service 'ut_drb_drbssl.rb'
|
||||
super
|
||||
end
|
||||
|
||||
def teardown
|
||||
super
|
||||
DRbService.finish
|
||||
end
|
||||
|
||||
def test_02_unknown
|
||||
|
@ -61,13 +59,9 @@ end
|
|||
class TestDRbSSLAry < Test::Unit::TestCase
|
||||
include DRbAry
|
||||
def setup
|
||||
@drb_service = DRbSSLService.new
|
||||
super
|
||||
setup_service 'ut_array_drbssl.rb'
|
||||
super
|
||||
end
|
||||
|
||||
def teardown
|
||||
super
|
||||
DRbService.finish
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -16,20 +16,17 @@ class DRbUNIXService < DRbService
|
|||
add_service_command(nm)
|
||||
end
|
||||
|
||||
uri = ARGV.shift if $0 == __FILE__
|
||||
@server = DRb::DRbServer.new(uri || 'drbunix:', self.manager, {})
|
||||
def start
|
||||
@server = DRb::DRbServer.new('drbunix:', manager, {})
|
||||
end
|
||||
end
|
||||
|
||||
class TestDRbUNIXCore < Test::Unit::TestCase
|
||||
include DRbCore
|
||||
def setup
|
||||
@drb_service = DRbUNIXService.new
|
||||
super
|
||||
setup_service 'ut_drb_drbunix.rb'
|
||||
super
|
||||
end
|
||||
|
||||
def teardown
|
||||
super
|
||||
DRbService.finish
|
||||
end
|
||||
|
||||
def test_02_unknown
|
||||
|
@ -51,12 +48,9 @@ end
|
|||
class TestDRbUNIXAry < Test::Unit::TestCase
|
||||
include DRbAry
|
||||
def setup
|
||||
@drb_service = DRbUNIXService.new
|
||||
super
|
||||
setup_service 'ut_array_drbunix.rb'
|
||||
super
|
||||
end
|
||||
def teardown
|
||||
super
|
||||
DRbService.finish
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue