1
0
Fork 0
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:
kazu 2018-10-20 13:14:02 +00:00
parent eab51f71d6
commit 4757c7eead
4 changed files with 107 additions and 124 deletions

View file

@ -7,7 +7,6 @@ require 'timeout'
module DRbTests module DRbTests
class DRbService class DRbService
@@manager = DRb::ExtServManager.new
@@ruby = [EnvUtil.rubybin] @@ruby = [EnvUtil.rubybin]
@@ruby << "-d" if $DEBUG @@ruby << "-d" if $DEBUG
def self.add_service_command(nm) 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| %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) add_service_command(nm)
end end
@server = @@server = DRb::DRbServer.new('druby://localhost:0', @@manager, {})
@@manager.uri = @@server.uri def initialize
def self.manager @manager = DRb::ExtServManager.new
@@manager start
@manager.uri = server.uri
end end
def self.server
@server || @@server def start
@server = DRb::DRbServer.new('druby://localhost:0', manager, {})
end end
def self.ext_service(name)
attr_reader :manager
attr_reader :server
def ext_service(name)
Timeout.timeout(100, RuntimeError) do Timeout.timeout(100, RuntimeError) do
manager.service(name) manager.service(name)
end end
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
end end
@ -68,15 +77,20 @@ class XArray < Array
end end
module DRbBase module DRbBase
def setup
@drb_service ||= DRbService.new
end
def setup_service(service_name) def setup_service(service_name)
@service_name = service_name @service_name = service_name
@ext = DRbService.ext_service(@service_name) @ext = @drb_service.ext_service(@service_name)
@there = @ext.front @there = @ext.front
end end
def teardown def teardown
@ext.stop_service if defined?(@ext) && @ext @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) while (@there&&@there.to_s rescue nil)
# nop # nop
end end
@ -98,6 +112,8 @@ module DRbBase
end end
} }
end end
@drb_service.finish
end
end end
module DRbCore module DRbCore

View file

@ -7,29 +7,14 @@ class TestDRbCore < Test::Unit::TestCase
include DRbCore include DRbCore
def setup def setup
super
setup_service 'ut_drb.rb' setup_service 'ut_drb.rb'
super
end
def teardown
super
DRbService.finish
end end
end end
class TestDRbYield < Test::Unit::TestCase module DRbYield
include DRbBase include DRbBase
def setup
setup_service 'ut_drb.rb'
super
end
def teardown
super
DRbService.finish
end
def test_01_one def test_01_one
@there.echo_yield_1([]) {|one| @there.echo_yield_1([]) {|one|
assert_equal([], one) assert_equal([], one)
@ -129,7 +114,23 @@ class TestDRbYield < Test::Unit::TestCase
end end
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) def echo_yield(*arg)
yield(*arg) yield(*arg)
end end
@ -153,15 +154,11 @@ class TestDRbRubyYield < TestDRbYield
end end
end end
def setup
@there = self
end end
def teardown class TestDRbRuby18Yield < Test::Unit::TestCase
end include DRbYield
end
class TestDRbRuby18Yield < TestDRbRubyYield
class YieldTest18 class YieldTest18
def echo_yield(*arg, &proc) def echo_yield(*arg, &proc)
proc.call(*arg) proc.call(*arg)
@ -188,6 +185,7 @@ class TestDRbRuby18Yield < TestDRbRubyYield
def setup def setup
@there = YieldTest18.new @there = YieldTest18.new
super
end end
end end
@ -195,13 +193,8 @@ class TestDRbAry < Test::Unit::TestCase
include DRbAry include DRbAry
def setup def setup
super
setup_service 'ut_array.rb' setup_service 'ut_array.rb'
super
end
def teardown
super
DRbService.finish
end end
end end
@ -209,8 +202,8 @@ class TestDRbMServer < Test::Unit::TestCase
include DRbBase include DRbBase
def setup def setup
setup_service 'ut_drb.rb'
super super
setup_service 'ut_drb.rb'
@server = (1..3).collect do |n| @server = (1..3).collect do |n|
DRb::DRbServer.new("druby://localhost:0", Onecky.new(n.to_s)) DRb::DRbServer.new("druby://localhost:0", Onecky.new(n.to_s))
end end
@ -221,7 +214,6 @@ class TestDRbMServer < Test::Unit::TestCase
s.stop_service s.stop_service
end end
super super
DRbService.finish
end end
def test_01 def test_01
@ -229,14 +221,11 @@ class TestDRbMServer < Test::Unit::TestCase
end end
end end
class TestDRbSafe1 < TestDRbAry class TestDRbSafe1 < Test::Unit::TestCase
include DRbAry
def setup def setup
setup_service 'ut_safe1.rb'
end
def teardown
super super
DRbService.finish setup_service 'ut_safe1.rb'
end end
end end
@ -244,13 +233,8 @@ class TestDRbLarge < Test::Unit::TestCase
include DRbBase include DRbBase
def setup def setup
super
setup_service 'ut_large.rb' setup_service 'ut_large.rb'
super
end
def teardown
super
DRbService.finish
end end
def test_01_large_ary def test_01_large_ary
@ -333,13 +317,8 @@ class TestBug4409 < Test::Unit::TestCase
include DRbBase include DRbBase
def setup def setup
super
setup_service 'ut_eq.rb' setup_service 'ut_eq.rb'
super
end
def teardown
super
DRbService.finish
end end
def test_bug4409 def test_bug4409

View file

@ -15,6 +15,8 @@ class DRbSSLService < DRbService
%w(ut_drb_drbssl.rb ut_array_drbssl.rb).each do |nm| %w(ut_drb_drbssl.rb ut_array_drbssl.rb).each do |nm|
add_service_command(nm) add_service_command(nm)
end end
def start
config = Hash.new config = Hash.new
config[:SSLVerifyMode] = OpenSSL::SSL::VERIFY_PEER config[:SSLVerifyMode] = OpenSSL::SSL::VERIFY_PEER
@ -32,20 +34,16 @@ class DRbSSLService < DRbService
[ ["C","JP"], ["O","Foo.DRuby.Org"], ["CN", "Sample"] ] [ ["C","JP"], ["O","Foo.DRuby.Org"], ["CN", "Sample"] ]
end end
uri = ARGV.shift if $0 == __FILE__ @server = DRb::DRbServer.new('drbssl://:0', manager, config)
@server = DRb::DRbServer.new(uri || 'drbssl://:0', self.manager, config) end
end end
class TestDRbSSLCore < Test::Unit::TestCase class TestDRbSSLCore < Test::Unit::TestCase
include DRbCore include DRbCore
def setup def setup
@drb_service = DRbSSLService.new
super
setup_service 'ut_drb_drbssl.rb' setup_service 'ut_drb_drbssl.rb'
super
end
def teardown
super
DRbService.finish
end end
def test_02_unknown def test_02_unknown
@ -61,13 +59,9 @@ end
class TestDRbSSLAry < Test::Unit::TestCase class TestDRbSSLAry < Test::Unit::TestCase
include DRbAry include DRbAry
def setup def setup
@drb_service = DRbSSLService.new
super
setup_service 'ut_array_drbssl.rb' setup_service 'ut_array_drbssl.rb'
super
end
def teardown
super
DRbService.finish
end end
end end

View file

@ -16,20 +16,17 @@ class DRbUNIXService < DRbService
add_service_command(nm) add_service_command(nm)
end end
uri = ARGV.shift if $0 == __FILE__ def start
@server = DRb::DRbServer.new(uri || 'drbunix:', self.manager, {}) @server = DRb::DRbServer.new('drbunix:', manager, {})
end
end end
class TestDRbUNIXCore < Test::Unit::TestCase class TestDRbUNIXCore < Test::Unit::TestCase
include DRbCore include DRbCore
def setup def setup
@drb_service = DRbUNIXService.new
super
setup_service 'ut_drb_drbunix.rb' setup_service 'ut_drb_drbunix.rb'
super
end
def teardown
super
DRbService.finish
end end
def test_02_unknown def test_02_unknown
@ -51,12 +48,9 @@ end
class TestDRbUNIXAry < Test::Unit::TestCase class TestDRbUNIXAry < Test::Unit::TestCase
include DRbAry include DRbAry
def setup def setup
@drb_service = DRbUNIXService.new
super
setup_service 'ut_array_drbunix.rb' setup_service 'ut_array_drbunix.rb'
super
end
def teardown
super
DRbService.finish
end end
end end