2015-12-16 00:07:31 -05:00
|
|
|
# frozen_string_literal: false
|
2010-02-02 08:58:56 -05:00
|
|
|
require_relative 'drbtest'
|
2003-10-20 11:24:00 -04:00
|
|
|
|
2014-05-31 23:07:58 -04:00
|
|
|
module DRbTests
|
|
|
|
|
2003-10-21 10:42:15 -04:00
|
|
|
class TestDRbCore < Test::Unit::TestCase
|
|
|
|
include DRbCore
|
2003-10-20 11:24:00 -04:00
|
|
|
|
|
|
|
def setup
|
2013-06-19 03:47:38 -04:00
|
|
|
setup_service 'ut_drb.rb'
|
|
|
|
super
|
2003-10-20 11:24:00 -04:00
|
|
|
end
|
2014-06-02 07:34:50 -04:00
|
|
|
|
|
|
|
def teardown
|
|
|
|
super
|
|
|
|
DRbService.finish
|
|
|
|
end
|
2013-06-19 03:47:38 -04:00
|
|
|
end
|
2003-10-20 11:24:00 -04:00
|
|
|
|
2013-06-19 03:47:38 -04:00
|
|
|
class TestDRbYield < Test::Unit::TestCase
|
|
|
|
include DRbBase
|
|
|
|
|
|
|
|
def setup
|
|
|
|
setup_service 'ut_drb.rb'
|
|
|
|
super
|
2003-10-20 11:24:00 -04:00
|
|
|
end
|
|
|
|
|
2014-06-02 07:34:50 -04:00
|
|
|
def teardown
|
|
|
|
super
|
|
|
|
DRbService.finish
|
|
|
|
end
|
|
|
|
|
2003-10-20 11:24:00 -04:00
|
|
|
def test_01_one
|
2003-10-30 04:36:41 -05:00
|
|
|
@there.echo_yield_1([]) {|one|
|
|
|
|
assert_equal([], one)
|
|
|
|
}
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2003-10-30 04:36:41 -05:00
|
|
|
@there.echo_yield_1(1) {|one|
|
|
|
|
assert_equal(1, one)
|
|
|
|
}
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2003-10-30 04:36:41 -05:00
|
|
|
@there.echo_yield_1(nil) {|one|
|
|
|
|
assert_equal(nil, one)
|
|
|
|
}
|
2003-10-20 11:24:00 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_02_two
|
2003-10-30 04:36:41 -05:00
|
|
|
@there.echo_yield_2([], []) {|one, two|
|
|
|
|
assert_equal([], one)
|
|
|
|
assert_equal([], two)
|
|
|
|
}
|
2003-10-20 11:24:00 -04:00
|
|
|
|
2003-10-30 04:36:41 -05:00
|
|
|
@there.echo_yield_2(1, 2) {|one, two|
|
|
|
|
assert_equal(1, one)
|
|
|
|
assert_equal(2, two)
|
|
|
|
}
|
2003-10-20 11:24:00 -04:00
|
|
|
|
2003-10-30 04:36:41 -05:00
|
|
|
@there.echo_yield_2(3, nil) {|one, two|
|
|
|
|
assert_equal(3, one)
|
|
|
|
assert_equal(nil, two)
|
|
|
|
}
|
2003-10-26 08:07:58 -05:00
|
|
|
|
2003-10-30 04:36:41 -05:00
|
|
|
@there.echo_yield_1([:key, :value]) {|one, two|
|
|
|
|
assert_equal(:key, one)
|
|
|
|
assert_equal(:value, two)
|
|
|
|
}
|
2003-10-20 11:24:00 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_03_many
|
2003-10-30 04:36:41 -05:00
|
|
|
@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|
|
|
|
|
assert_equal([1, 2, 3], s)
|
|
|
|
}
|
|
|
|
@there.echo_yield([], []) {|*s|
|
|
|
|
assert_equal([[], []], s)
|
|
|
|
}
|
|
|
|
@there.echo_yield([]) {|*s|
|
2003-10-20 11:24:00 -04:00
|
|
|
assert_equal([[]], s) # !
|
2003-10-30 04:36:41 -05:00
|
|
|
}
|
2003-10-20 11:24:00 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_04_many_to_one
|
2003-10-30 04:36:41 -05:00
|
|
|
@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|
|
|
|
|
assert_equal([1, 2, 3], s)
|
|
|
|
}
|
|
|
|
@there.echo_yield([], []) {|*s|
|
|
|
|
assert_equal([[], []], s)
|
|
|
|
}
|
|
|
|
@there.echo_yield([]) {|*s|
|
|
|
|
assert_equal([[]], s)
|
|
|
|
}
|
2003-10-20 11:24:00 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_05_array_subclass
|
|
|
|
@there.xarray_each {|x| assert_kind_of(XArray, x)}
|
2003-10-30 04:36:41 -05:00
|
|
|
@there.xarray_each {|*x| assert_kind_of(XArray, x[0])}
|
2003-10-20 11:24:00 -04:00
|
|
|
end
|
2005-04-11 10:48:50 -04:00
|
|
|
|
|
|
|
def test_06_taint
|
|
|
|
x = proc {}
|
|
|
|
assert(! x.tainted?)
|
|
|
|
@there.echo_yield(x) {|o|
|
|
|
|
assert_equal(x, o)
|
|
|
|
assert(! x.tainted?)
|
|
|
|
}
|
|
|
|
end
|
2003-10-20 11:24:00 -04:00
|
|
|
end
|
|
|
|
|
2007-11-19 22:01:49 -05:00
|
|
|
class TestDRbRubyYield < TestDRbYield
|
2003-10-20 11:24:00 -04:00
|
|
|
def echo_yield(*arg)
|
|
|
|
yield(*arg)
|
|
|
|
end
|
|
|
|
|
|
|
|
def echo_yield_0
|
|
|
|
yield
|
|
|
|
end
|
|
|
|
|
|
|
|
def echo_yield_1(a)
|
|
|
|
yield(a)
|
|
|
|
end
|
|
|
|
|
|
|
|
def echo_yield_2(a, b)
|
|
|
|
yield(a, b)
|
|
|
|
end
|
|
|
|
|
|
|
|
def xarray_each
|
|
|
|
xary = [XArray.new([0])]
|
|
|
|
xary.each do |x|
|
|
|
|
yield(x)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def setup
|
|
|
|
@there = self
|
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2003-10-20 11:24:00 -04:00
|
|
|
def teardown
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2007-11-19 22:01:49 -05:00
|
|
|
class TestDRbRuby18Yield < TestDRbRubyYield
|
2003-10-20 11:24:00 -04:00
|
|
|
class YieldTest18
|
|
|
|
def echo_yield(*arg, &proc)
|
|
|
|
proc.call(*arg)
|
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2003-10-20 11:24:00 -04:00
|
|
|
def echo_yield_0(&proc)
|
|
|
|
proc.call
|
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2003-10-20 11:24:00 -04:00
|
|
|
def echo_yield_1(a, &proc)
|
|
|
|
proc.call(a)
|
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2003-10-20 11:24:00 -04:00
|
|
|
def echo_yield_2(a, b, &proc)
|
|
|
|
proc.call(a, b)
|
|
|
|
end
|
|
|
|
|
|
|
|
def xarray_each(&proc)
|
|
|
|
xary = [XArray.new([0])]
|
|
|
|
xary.each(&proc)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def setup
|
|
|
|
@there = YieldTest18.new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2003-10-21 10:42:15 -04:00
|
|
|
class TestDRbAry < Test::Unit::TestCase
|
|
|
|
include DRbAry
|
2013-06-19 03:47:38 -04:00
|
|
|
|
|
|
|
def setup
|
|
|
|
setup_service 'ut_array.rb'
|
|
|
|
super
|
|
|
|
end
|
2014-06-02 07:34:50 -04:00
|
|
|
|
|
|
|
def teardown
|
|
|
|
super
|
|
|
|
DRbService.finish
|
|
|
|
end
|
2003-10-20 11:24:00 -04:00
|
|
|
end
|
|
|
|
|
2003-10-21 10:42:15 -04:00
|
|
|
class TestDRbMServer < Test::Unit::TestCase
|
2013-06-19 03:47:38 -04:00
|
|
|
include DRbBase
|
|
|
|
|
2003-10-20 11:24:00 -04:00
|
|
|
def setup
|
2013-06-19 03:47:38 -04:00
|
|
|
setup_service 'ut_drb.rb'
|
|
|
|
super
|
2003-10-20 11:24:00 -04:00
|
|
|
@server = (1..3).collect do |n|
|
2015-09-21 15:28:14 -04:00
|
|
|
DRb::DRbServer.new("druby://localhost:0", Onecky.new(n.to_s))
|
2003-10-20 11:24:00 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
|
|
|
@server.each do |s|
|
|
|
|
s.stop_service
|
|
|
|
end
|
2013-06-19 03:47:38 -04:00
|
|
|
super
|
2014-06-02 07:34:50 -04:00
|
|
|
DRbService.finish
|
2003-10-20 11:24:00 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_01
|
|
|
|
assert_equal(6, @there.sample(@server[0].front, @server[1].front, @server[2].front))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2003-10-21 10:42:15 -04:00
|
|
|
class TestDRbSafe1 < TestDRbAry
|
2003-10-20 11:24:00 -04:00
|
|
|
def setup
|
2013-06-19 03:47:38 -04:00
|
|
|
setup_service 'ut_safe1.rb'
|
2003-10-20 11:24:00 -04:00
|
|
|
end
|
2014-06-02 07:34:50 -04:00
|
|
|
|
|
|
|
def teardown
|
|
|
|
super
|
|
|
|
DRbService.finish
|
|
|
|
end
|
2003-10-20 11:24:00 -04:00
|
|
|
end
|
|
|
|
|
2007-11-26 09:24:29 -05:00
|
|
|
class TestDRbEval # < Test::Unit::TestCase
|
2003-10-20 11:24:00 -04:00
|
|
|
def setup
|
|
|
|
super
|
2005-01-01 11:20:35 -05:00
|
|
|
@ext = DRbService.ext_service('ut_eval.rb')
|
2003-10-20 11:24:00 -04:00
|
|
|
@there = @ext.front
|
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
2005-01-01 11:20:35 -05:00
|
|
|
@ext.stop_service if @ext
|
2003-10-20 11:24:00 -04:00
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2005-02-13 10:13:54 -05:00
|
|
|
def test_01_safe1_safe4_eval
|
2008-09-24 13:44:39 -04:00
|
|
|
assert_raise(SecurityError) do
|
2003-10-20 11:24:00 -04:00
|
|
|
@there.method_missing(:instance_eval, 'ENV.inspect')
|
|
|
|
end
|
|
|
|
|
2008-09-24 13:44:39 -04:00
|
|
|
assert_raise(SecurityError) do
|
2003-10-20 11:24:00 -04:00
|
|
|
@there.method_missing(:send, :eval, 'ENV.inspect')
|
|
|
|
end
|
|
|
|
|
|
|
|
remote_class = @there.remote_class
|
|
|
|
|
2008-09-24 13:44:39 -04:00
|
|
|
assert_raise(SecurityError) do
|
2005-02-13 10:13:54 -05:00
|
|
|
remote_class.class_eval('ENV.inspect')
|
|
|
|
end
|
|
|
|
|
2008-09-24 13:44:39 -04:00
|
|
|
assert_raise(SecurityError) do
|
2005-02-13 10:13:54 -05:00
|
|
|
remote_class.module_eval('ENV.inspect')
|
|
|
|
end
|
|
|
|
|
|
|
|
four = @there.four
|
|
|
|
assert_equal(1, four.method_missing(:send, :eval, '1'))
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2005-02-13 10:13:54 -05:00
|
|
|
remote_class = four.remote_class
|
|
|
|
|
2005-02-16 10:30:52 -05:00
|
|
|
assert_equal(1, remote_class.class_eval('1'))
|
|
|
|
|
|
|
|
assert_equal(1, remote_class.module_eval('1'))
|
|
|
|
|
2008-09-24 13:44:39 -04:00
|
|
|
assert_raise(SecurityError) do
|
2005-02-16 10:30:52 -05:00
|
|
|
remote_class.class_eval('ENV = {}')
|
2003-10-20 11:24:00 -04:00
|
|
|
end
|
|
|
|
|
2008-09-24 13:44:39 -04:00
|
|
|
assert_raise(SecurityError) do
|
2005-02-16 10:30:52 -05:00
|
|
|
remote_class.module_eval('ENV = {}')
|
2003-10-20 11:24:00 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2003-10-21 10:42:15 -04:00
|
|
|
class TestDRbLarge < Test::Unit::TestCase
|
2013-06-19 03:47:38 -04:00
|
|
|
include DRbBase
|
2003-10-20 11:24:00 -04:00
|
|
|
|
2013-06-19 03:47:38 -04:00
|
|
|
def setup
|
|
|
|
setup_service 'ut_large.rb'
|
|
|
|
super
|
2003-10-20 11:24:00 -04:00
|
|
|
end
|
|
|
|
|
2014-06-02 07:34:50 -04:00
|
|
|
def teardown
|
|
|
|
super
|
|
|
|
DRbService.finish
|
|
|
|
end
|
|
|
|
|
2003-10-20 11:24:00 -04:00
|
|
|
def test_01_large_ary
|
|
|
|
ary = [2] * 10240
|
|
|
|
assert_equal(10240, @there.size(ary))
|
|
|
|
assert_equal(20480, @there.sum(ary))
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_02_large_ary
|
|
|
|
ary = ["Hello, World"] * 10240
|
|
|
|
assert_equal(10240, @there.size(ary))
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_03_large_ary
|
|
|
|
ary = [Thread.current] * 10240
|
|
|
|
assert_equal(10240, @there.size(ary))
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_04_many_arg
|
2010-06-14 04:52:30 -04:00
|
|
|
assert_raise(DRb::DRbConnError) {
|
2003-10-20 11:24:00 -04:00
|
|
|
@there.arg_test(1, 2, 3, 4, 5, 6, 7, 8, 9, 0)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_05_too_large_ary
|
|
|
|
ary = ["Hello, World"] * 102400
|
|
|
|
exception = nil
|
|
|
|
begin
|
2009-03-05 22:56:38 -05:00
|
|
|
@there.size(ary)
|
2003-10-20 11:24:00 -04:00
|
|
|
rescue StandardError
|
|
|
|
exception = $!
|
|
|
|
end
|
|
|
|
assert_kind_of(StandardError, exception)
|
|
|
|
end
|
|
|
|
end
|
2011-06-27 11:18:22 -04:00
|
|
|
|
|
|
|
class TestBug4409 < Test::Unit::TestCase
|
2013-06-19 03:47:38 -04:00
|
|
|
include DRbBase
|
2011-06-27 11:18:22 -04:00
|
|
|
|
2013-06-19 03:47:38 -04:00
|
|
|
def setup
|
|
|
|
setup_service 'ut_eq.rb'
|
|
|
|
super
|
2011-06-27 11:18:22 -04:00
|
|
|
end
|
2012-08-21 00:50:18 -04:00
|
|
|
|
2014-06-02 07:34:50 -04:00
|
|
|
def teardown
|
|
|
|
super
|
|
|
|
DRbService.finish
|
|
|
|
end
|
|
|
|
|
2011-06-27 11:18:22 -04:00
|
|
|
def test_bug4409
|
|
|
|
foo = @there.foo
|
|
|
|
assert(@there.foo?(foo))
|
|
|
|
end
|
|
|
|
end
|
2014-05-31 23:07:58 -04:00
|
|
|
|
|
|
|
end
|