From 06d9340f2e1491697625afbf1fe94137e252319c Mon Sep 17 00:00:00 2001 From: matz Date: Tue, 21 Oct 2003 14:42:15 +0000 Subject: * eval.c (ruby_cleanup): call finalizers and exit procs before terminating threads. * eval.c (ruby_cleanup): preserve ruby_errinfo before ruby_finalize_0(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4826 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/drb/test_drb.rb | 376 +++++---------------------------------------- test/drb/test_drbssl.rb | 65 ++++---- test/drb/test_drbunix.rb | 31 ++-- test/drb/ut_drb.rb | 1 - test/drb/ut_drb_drbssl.rb | 2 +- test/drb/ut_drb_drbunix.rb | 2 +- 6 files changed, 83 insertions(+), 394 deletions(-) (limited to 'test') diff --git a/test/drb/test_drb.rb b/test/drb/test_drb.rb index 437e2b4560..213c70f95d 100644 --- a/test/drb/test_drb.rb +++ b/test/drb/test_drb.rb @@ -1,225 +1,12 @@ -require 'rubyunit' -require 'runit/cui/testrunner' -require 'rbconfig' -require 'drb/drb' -require 'drb/extservm' -require 'timeout' - -class TestService - @@scripts = %w(ut_drb.rb ut_array.rb ut_port.rb ut_large.rb ut_safe1.rb ut_eval.rb) - - def initialize(uri=nil, config={}) - ruby = Config::CONFIG["RUBY_INSTALL_NAME"] - @manager = DRb::ExtServManager.new - @@scripts.each do |nm| - DRb::ExtServManager.command[nm] = "#{ruby} #{nm}" - end - @server = DRb::DRbServer.new(uri, @manager, config) - end - attr_reader :manager, :server -end - -class Onecky - include DRbUndumped - def initialize(n) - @num = n - end - - def to_i - @num.to_i - end - - def sleep(n) - Kernel.sleep(n) - to_i - end -end - -class FailOnecky < Onecky - class OneckyError < RuntimeError; end - def to_i - raise(OneckyError, @num.to_s) - end -end - -class XArray < Array - def initialize(ary) - ary.each do |x| - self.push(x) - end - end -end - -class DRbCoreTest < RUNIT::TestCase - def setup - @ext = $manager.service('ut_drb.rb') - @there = @ext.front - end - - def teardown - @ext.stop_service - end - - def test_00_DRbObject - ro = DRbObject.new(nil, 'druby://localhost:12345') - assert_equal('druby://localhost:12345', ro.__drburi) - assert_equal(nil, ro.__drbref) - - ro = DRbObject.new_with_uri('druby://localhost:12345') - assert_equal('druby://localhost:12345', ro.__drburi) - assert_equal(nil, ro.__drbref) - - ro = DRbObject.new_with_uri('druby://localhost:12345?foobar') - assert_equal('druby://localhost:12345', ro.__drburi) - assert_equal(DRb::DRbURIOption.new('foobar'), ro.__drbref) - end - - def test_01 - assert_equal("hello", @there.hello) - onecky = Onecky.new('3') - assert_equal(6, @there.sample(onecky, 1, 2)) - ary = @there.to_a - assert_kind_of(DRb::DRbObject, ary) - end - - def test_01_02_loop - onecky = Onecky.new('3') - 50.times do - assert_equal(6, @there.sample(onecky, 1, 2)) - ary = @there.to_a - assert_kind_of(DRb::DRbObject, ary) - end - end - - def test_02_unknown - obj = @there.unknown_class - assert_kind_of(DRb::DRbUnknown, obj) - assert_equal('Unknown2', obj.name) - - obj = @there.unknown_module - assert_kind_of(DRb::DRbUnknown, obj) - if RUBY_VERSION >= '1.8' - assert_equal('DRbEx::', obj.name) - else - assert_equal('DRbEx', obj.name) - end - - assert_exception(DRb::DRbUnknownError) do - @there.unknown_error - end - - onecky = FailOnecky.new('3') - - assert_exception(FailOnecky::OneckyError) do - @there.sample(onecky, 1, 2) - end - end - - def test_03 - assert_equal(8, @there.sum(1, 1, 1, 1, 1, 1, 1, 1)) - assert_exception(ArgumentError) do - @there.sum(1, 1, 1, 1, 1, 1, 1, 1, 1) - end - assert_exception(DRb::DRbConnError) do - @there.sum('1' * 2048) - end - end - - def test_04 - assert_respond_to('sum', @there) - assert(!(@there.respond_to? "foobar")) - end - - def test_05_eq - a = @there.to_a[0] - b = @there.to_a[0] - assert(a.id != b.id) - assert(a != b) - assert(a.hash != b.hash) - assert(! a.eql?(b)) - require 'drb/eq' - assert(a == b) - assert_equal(a, b) - assert(a == @there) - assert_equal(a.hash, b.hash) - assert_equal(a.hash, @there.hash) - assert(a.eql?(b)) - assert(a.eql?(@there)) - end - - def test_06_timeout - ten = Onecky.new(10) - assert_exception(TimeoutError) do - @there.do_timeout(ten) - end - assert_exception(TimeoutError) do - @there.do_timeout(ten) - end - end - - def test_07_public_private - assert_no_exception() { - begin - @there.method_missing(:eval) - rescue NameError - assert_match($!.message, /^private method `eval'/) - end - } - assert_no_exception() { - begin - @there.method_missing(:undefined_method_test) - rescue NameError - assert_match($!.message, /^undefined method `undefined_method_test'/) - end - } - assert_exception(SecurityError) do - @there.method_missing(:__send__, :to_s) - end - end - - def test_08_here - ro = DRbObject.new(nil, DRb.uri) - assert_kind_of(String, ro.to_s) - - ro = DRbObject.new_with_uri(DRb.uri) - assert_kind_of(String, ro.to_s) - end - - def uri_concat_option(uri, opt) - "#{uri}?#{opt}" - end +require "#{File.dirname(File.expand_path(__FILE__))}/drbtest" - def test_09_option - uri = uri_concat_option(@there.__drburi, "foo") - ro = DRbObject.new_with_uri(uri) - assert_equal(ro.__drburi, @there.__drburi) - assert_equal(3, ro.size) - - uri = uri_concat_option(@there.__drburi, "") - ro = DRbObject.new_with_uri(uri) - assert_equal(ro.__drburi, @there.__drburi) - assert_equal(DRb::DRbURIOption.new(''), ro.__drbref) - - uri = uri_concat_option(@there.__drburi, "hello?world") - ro = DRbObject.new_with_uri(uri) - assert_equal(DRb::DRbURIOption.new('hello?world'), ro.__drbref) - - uri = uri_concat_option(@there.__drburi, "?hello?world") - ro = DRbObject.new_with_uri(uri) - assert_equal(DRb::DRbURIOption.new('?hello?world'), ro.__drbref) - end - - def test_10_yield_undumped - @there.xarray2_hash.each do |k, v| - assert_kind_of(String, k) - assert_kind_of(DRbObject, v) - end - end +class TestDRbCore < Test::Unit::TestCase + include DRbCore end -class DRbYieldTest < RUNIT::TestCase +class TestDRbYield < Test::Unit::TestCase def setup - @ext = $manager.service('ut_drb.rb') + @ext = DRbService.manager.service('ut_drb.rb') @there = @ext.front end @@ -282,20 +69,20 @@ class DRbYieldTest < RUNIT::TestCase def test_04_many_to_one s = nil - @there.echo_yield_0 {|s|} - assert_equal(nil, s) - @there.echo_yield(nil) {|s|} - assert_equal(nil, s) - @there.echo_yield(1) {|s|} - assert_equal(1, s) - @there.echo_yield(1, 2) {|s|} + @there.echo_yield_0 {|*s|} + assert_equal([], s) + @there.echo_yield(nil) {|*s|} + assert_equal([nil], s) + @there.echo_yield(1) {|*s|} + assert_equal([1], s) + @there.echo_yield(1, 2) {|*s|} assert_equal([1, 2], s) - @there.echo_yield(1, 2, 3) {|s|} + @there.echo_yield(1, 2, 3) {|*s|} assert_equal([1, 2, 3], s) - @there.echo_yield([], []) {|s|} + @there.echo_yield([], []) {|*s|} assert_equal([[], []], s) - @there.echo_yield([]) {|s|} - assert_equal([], s) + @there.echo_yield([]) {|*s|} + assert_equal([[]], s) end def test_05_array_subclass @@ -306,7 +93,7 @@ class DRbYieldTest < RUNIT::TestCase end end -class RubyYieldTest < DRbYieldTest +class TestRubyYield < TestDRbYield def echo_yield(*arg) yield(*arg) end @@ -338,7 +125,7 @@ class RubyYieldTest < DRbYieldTest end end -class Ruby18YieldTest < RubyYieldTest +class TestRuby18Yield < TestRubyYield class YieldTest18 def echo_yield(*arg, &proc) proc.call(*arg) @@ -368,87 +155,13 @@ class Ruby18YieldTest < RubyYieldTest end end -class DRbAryTest < RUNIT::TestCase - def setup - @ext = $manager.service('ut_array.rb') - @there = @ext.front - end - - def teardown - @ext.stop_service - end - - def test_01 - assert_kind_of(DRb::DRbObject, @there) - end - - def test_02_collect - ary = @there.collect do |x| x + x end - assert_kind_of(Array, ary) - assert_equal([2, 4, 'IIIIII', 8, 'fivefive', 12], ary) - end - - def test_03_redo - ary = [] - count = 0 - @there.each do |x| - count += 1 - ary.push x - redo if count == 3 - end - assert_equal([1, 2, 'III', 'III', 4, 'five', 6], ary) - end - - def test_04_retry - retried = false - ary = [] - @there.each do |x| - ary.push x - if x == 4 && !retried - retried = true - retry - end - end - assert_equal([1, 2, 'III', 4, 1, 2, 'III', 4, 'five', 6], ary) - end - - def test_05_break - ary = [] - @there.each do |x| - ary.push x - break if x == 4 - end - assert_equal([1, 2, 'III', 4], ary) - end - - def test_06_next - ary = [] - @there.each do |x| - next if String === x - ary.push x - end - assert_equal([1, 2, 4, 6], ary) - end - - if RUBY_VERSION >= '1.8' - class_eval <= '1.8' - RUNIT::CUI::TestRunner.run(Ruby18YieldTest.suite) - end - RUNIT::CUI::TestRunner.run(DRbYieldTest.suite) - RUNIT::CUI::TestRunner.run(DRbAryTest.suite) - RUNIT::CUI::TestRunner.run(DRbMServerTest.suite) - RUNIT::CUI::TestRunner.run(DRbSafe1Test.suite) - RUNIT::CUI::TestRunner.run(DRbReusePortTest.suite) - RUNIT::CUI::TestRunner.run(DRbLargeTest.suite) -end - diff --git a/test/drb/test_drbssl.rb b/test/drb/test_drbssl.rb index 249e90aa99..6e2e0b1746 100644 --- a/test/drb/test_drbssl.rb +++ b/test/drb/test_drbssl.rb @@ -1,13 +1,34 @@ -require 'test_drb' +require "#{File.dirname(File.expand_path(__FILE__))}/drbtest" require 'drb/ssl' -class TestService - @@scripts = %w(ut_drb_drbssl.rb ut_array_drbssl.rb) +class DRbSSLService < DRbService + %w(ut_drb_drbssl.rb ut_array_drbssl.rb).each do |nm| + DRb::ExtServManager.command[nm] = "#{@@ruby} #{@@dir}/#{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 + + @server = DRb::DRbServer.new(ARGV.shift || 'drbssl://:0', @@manager, config) end -class DRbXCoreTest < DRbCoreTest +class TestDRbSSLCore < Test::Unit::TestCase + include DRbCore def setup - @ext = $manager.service('ut_drb_drbssl.rb') + @ext = DRbSSLService.manager.service('ut_drb_drbssl.rb') @there = @ext.front end @@ -22,10 +43,10 @@ class DRbXCoreTest < DRbCoreTest def test_06_timeout ten = Onecky.new(3) - assert_exception(TimeoutError) do + assert_raises(TimeoutError) do @there.do_timeout(ten) end - assert_exception(TimeoutError) do + assert_raises(TimeoutError) do @there.do_timeout(ten) end sleep 3 @@ -33,34 +54,10 @@ class DRbXCoreTest < DRbCoreTest end -class DRbXAryTest < DRbAryTest +class TestDRbSSLAry < Test::Unit::TestCase + include DRbAry def setup - @ext = $manager.service('ut_array_drbssl.rb') + @ext = DRbSSLService.manager.service('ut_array_drbssl.rb') @there = @ext.front end end - -if __FILE__ == $0 - 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 - - $testservice = TestService.new(ARGV.shift || 'drbssl://:0', config) - $manager = $testservice.manager - RUNIT::CUI::TestRunner.run(DRbXCoreTest.suite) - RUNIT::CUI::TestRunner.run(DRbXAryTest.suite) - # exit! -end diff --git a/test/drb/test_drbunix.rb b/test/drb/test_drbunix.rb index d1fa63dd77..1aaaffe359 100644 --- a/test/drb/test_drbunix.rb +++ b/test/drb/test_drbunix.rb @@ -1,12 +1,17 @@ -require 'test_drb' +require "#{File.dirname(File.expand_path(__FILE__))}/drbtest" +require 'drb/unix' -class TestService - @@scripts = %w(ut_drb_drbunix.rb ut_array_drbunix.rb) +class DRbUNIXService < DRbService + %w(ut_drb_drbunix.rb ut_array_drbunix.rb).each do |nm| + DRb::ExtServManager.command[nm] = "#{@@ruby} #{@@dir}/#{nm}" + end + @server = DRb::DRbServer.new(ARGV.shift || 'drbunix:', @@manager, {}) end -class DRbXCoreTest < DRbCoreTest +class TestDRbUNIXCore < Test::Unit::TestCase + include DRbCore def setup - @ext = $manager.service('ut_drb_drbunix.rb') + @ext = DRbUNIXService.manager.service('ut_drb_drbunix.rb') @there = @ext.front end @@ -21,26 +26,20 @@ class DRbXCoreTest < DRbCoreTest def test_06_timeout ten = Onecky.new(3) - assert_exception(TimeoutError) do + assert_raises(TimeoutError) do @there.do_timeout(ten) end - assert_exception(TimeoutError) do + assert_raises(TimeoutError) do @there.do_timeout(ten) end sleep 3 end end -class DRbXAryTest < DRbAryTest +class TestDRbUNIXAry < Test::Unit::TestCase + include DRbAry def setup - @ext = $manager.service('ut_array_drbunix.rb') + @ext = DRbUNIXService.manager.service('ut_array_drbunix.rb') @there = @ext.front end end - -if __FILE__ == $0 - $testservice = TestService.new(ARGV.shift || 'drbunix:') - $manager = $testservice.manager - RUNIT::CUI::TestRunner.run(DRbXCoreTest.suite) - RUNIT::CUI::TestRunner.run(DRbXAryTest.suite) -end diff --git a/test/drb/ut_drb.rb b/test/drb/ut_drb.rb index 7a6409a783..2a121b0de3 100644 --- a/test/drb/ut_drb.rb +++ b/test/drb/ut_drb.rb @@ -134,4 +134,3 @@ if __FILE__ == $0 es = DRb::ExtServ.new(ARGV.shift, ARGV.shift) DRb.thread.join end - diff --git a/test/drb/ut_drb_drbssl.rb b/test/drb/ut_drb_drbssl.rb index cc5aea9733..b09864aebe 100644 --- a/test/drb/ut_drb_drbssl.rb +++ b/test/drb/ut_drb_drbssl.rb @@ -1,4 +1,4 @@ -require 'ut_drb' +require "#{File.dirname(File.expand_path(__FILE__))}/ut_drb" require 'drb/ssl' if __FILE__ == $0 diff --git a/test/drb/ut_drb_drbunix.rb b/test/drb/ut_drb_drbunix.rb index 7e1f6a2e5a..ae0674ef37 100644 --- a/test/drb/ut_drb_drbunix.rb +++ b/test/drb/ut_drb_drbunix.rb @@ -1,4 +1,4 @@ -require 'ut_drb' +require "#{File.dirname(File.expand_path(__FILE__))}/ut_drb" if __FILE__ == $0 def ARGV.shift -- cgit v1.2.3