Permalink
Browse files

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
  • Loading branch information...
znz committed Oct 20, 2018
1 parent eab51f7 commit 4757c7eead9ef8aa999fb2a8b7f68dc14701914f
Showing with 107 additions and 124 deletions.
  1. +46 −30 test/drb/drbtest.rb
  2. +30 −51 test/drb/test_drb.rb
  3. +24 −30 test/drb/test_drbssl.rb
  4. +7 −13 test/drb/test_drbunix.rb
@@ -7,7 +7,6 @@
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 @@ def self.add_service_command(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)
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,35 +77,42 @@ def initialize(ary)
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)
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
if defined?(@service_name) && @service_name
@drb_service.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
th.join
end
}
}
end
@drb_service.finish
end
end
@@ -7,29 +7,14 @@ class TestDRbCore < Test::Unit::TestCase
include DRbCore
def setup
setup_service 'ut_drb.rb'
super
end
def teardown
super
DRbService.finish
setup_service 'ut_drb.rb'
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 @@ def test_06_taint
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 @@ def xarray_each
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,29 +185,25 @@ def xarray_each(&proc)
def setup
@there = YieldTest18.new
super
end
end
class TestDRbAry < Test::Unit::TestCase
include DRbAry
def setup
setup_service 'ut_array.rb'
super
end
def teardown
super
DRbService.finish
setup_service 'ut_array.rb'
end
end
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,36 +214,27 @@ def teardown
s.stop_service
end
super
DRbService.finish
end
def test_01
assert_equal(6, @there.sample(@server[0].front, @server[1].front, @server[2].front))
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
class TestDRbLarge < Test::Unit::TestCase
include DRbBase
def setup
setup_service 'ut_large.rb'
super
end
def teardown
super
DRbService.finish
setup_service 'ut_large.rb'
end
def test_01_large_ary
@@ -333,13 +317,8 @@ class TestBug4409 < Test::Unit::TestCase
include DRbBase
def setup
setup_service 'ut_eq.rb'
super
end
def teardown
super
DRbService.finish
setup_service 'ut_eq.rb'
end
def test_bug4409
@@ -15,37 +15,35 @@ class DRbSSLService < DRbService
%w(ut_drb_drbssl.rb ut_array_drbssl.rb).each do |nm|
add_service_command(nm)
end
config = Hash.new
config[:SSLVerifyMode] = OpenSSL::SSL::VERIFY_PEER
config[:SSLVerifyCallback] = lambda{ |ok,x509_store|
true
}
begin
data = open("sample.key"){|io| io.read }
config[:SSLPrivateKey] = OpenSSL::PKey::RSA.new(data)
data = open("sample.crt"){|io| io.read }
config[:SSLCertificate] = OpenSSL::X509::Certificate.new(data)
rescue
# $stderr.puts "Switching to use self-signed certificate"
config[:SSLCertName] =
[ ["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)
def start
config = Hash.new
config[:SSLVerifyMode] = OpenSSL::SSL::VERIFY_PEER
config[:SSLVerifyCallback] = lambda{ |ok,x509_store|
true
}
begin
data = open("sample.key"){|io| io.read }
config[:SSLPrivateKey] = OpenSSL::PKey::RSA.new(data)
data = open("sample.crt"){|io| io.read }
config[:SSLCertificate] = OpenSSL::X509::Certificate.new(data)
rescue
# $stderr.puts "Switching to use self-signed certificate"
config[:SSLCertName] =
[ ["C","JP"], ["O","Foo.DRuby.Org"], ["CN", "Sample"] ]
end
@server = DRb::DRbServer.new('drbssl://:0', manager, config)
end
end
class TestDRbSSLCore < Test::Unit::TestCase
include DRbCore
def setup
setup_service 'ut_drb_drbssl.rb'
super
end
def teardown
@drb_service = DRbSSLService.new
super
DRbService.finish
setup_service 'ut_drb_drbssl.rb'
end
def test_02_unknown
@@ -61,13 +59,9 @@ def test_05_eq
class TestDRbSSLAry < Test::Unit::TestCase
include DRbAry
def setup
setup_service 'ut_array_drbssl.rb'
super
end
def teardown
@drb_service = DRbSSLService.new
super
DRbService.finish
setup_service 'ut_array_drbssl.rb'
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
setup_service 'ut_drb_drbunix.rb'
super
end
def teardown
@drb_service = DRbUNIXService.new
super
DRbService.finish
setup_service 'ut_drb_drbunix.rb'
end
def test_02_unknown
@@ -51,12 +48,9 @@ def test_bad_uri
class TestDRbUNIXAry < Test::Unit::TestCase
include DRbAry
def setup
setup_service 'ut_array_drbunix.rb'
@drb_service = DRbUNIXService.new
super
end
def teardown
super
DRbService.finish
setup_service 'ut_array_drbunix.rb'
end
end

0 comments on commit 4757c7e

Please sign in to comment.