2015-12-16 08:07:31 +03:00
|
|
|
# frozen_string_literal: false
|
2010-02-02 16:58:56 +03:00
|
|
|
require_relative 'drbtest'
|
2003-10-20 19:24:00 +04:00
|
|
|
|
2014-06-01 07:07:58 +04:00
|
|
|
module DRbTests
|
|
|
|
|
2003-10-21 18:42:15 +04:00
|
|
|
class TestDRbCore < Test::Unit::TestCase
|
|
|
|
include DRbCore
|
2003-10-20 19:24:00 +04:00
|
|
|
|
|
|
|
def setup
|
2014-06-02 15:34:50 +04:00
|
|
|
super
|
2018-10-20 16:14:02 +03:00
|
|
|
setup_service 'ut_drb.rb'
|
2014-06-02 15:34:50 +04:00
|
|
|
end
|
2013-06-19 11:47:38 +04:00
|
|
|
end
|
2003-10-20 19:24:00 +04:00
|
|
|
|
2018-10-20 16:14:02 +03:00
|
|
|
module DRbYield
|
2013-06-19 11:47:38 +04:00
|
|
|
include DRbBase
|
|
|
|
|
2003-10-20 19:24:00 +04:00
|
|
|
def test_01_one
|
2003-10-30 12:36:41 +03:00
|
|
|
@there.echo_yield_1([]) {|one|
|
|
|
|
assert_equal([], one)
|
|
|
|
}
|
2009-03-06 06:56:38 +03:00
|
|
|
|
2003-10-30 12:36:41 +03:00
|
|
|
@there.echo_yield_1(1) {|one|
|
|
|
|
assert_equal(1, one)
|
|
|
|
}
|
2009-03-06 06:56:38 +03:00
|
|
|
|
2003-10-30 12:36:41 +03:00
|
|
|
@there.echo_yield_1(nil) {|one|
|
|
|
|
assert_equal(nil, one)
|
|
|
|
}
|
2003-10-20 19:24:00 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_02_two
|
2003-10-30 12:36:41 +03:00
|
|
|
@there.echo_yield_2([], []) {|one, two|
|
|
|
|
assert_equal([], one)
|
|
|
|
assert_equal([], two)
|
|
|
|
}
|
2003-10-20 19:24:00 +04:00
|
|
|
|
2003-10-30 12:36:41 +03:00
|
|
|
@there.echo_yield_2(1, 2) {|one, two|
|
|
|
|
assert_equal(1, one)
|
|
|
|
assert_equal(2, two)
|
|
|
|
}
|
2003-10-20 19:24:00 +04:00
|
|
|
|
2003-10-30 12:36:41 +03:00
|
|
|
@there.echo_yield_2(3, nil) {|one, two|
|
|
|
|
assert_equal(3, one)
|
|
|
|
assert_equal(nil, two)
|
|
|
|
}
|
2003-10-26 16:07:58 +03:00
|
|
|
|
2003-10-30 12:36:41 +03:00
|
|
|
@there.echo_yield_1([:key, :value]) {|one, two|
|
|
|
|
assert_equal(:key, one)
|
|
|
|
assert_equal(:value, two)
|
|
|
|
}
|
2003-10-20 19:24:00 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_03_many
|
2003-10-30 12:36:41 +03: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 19:24:00 +04:00
|
|
|
assert_equal([[]], s) # !
|
2003-10-30 12:36:41 +03:00
|
|
|
}
|
2003-10-20 19:24:00 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_04_many_to_one
|
2003-10-30 12:36:41 +03: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 19:24:00 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_05_array_subclass
|
|
|
|
@there.xarray_each {|x| assert_kind_of(XArray, x)}
|
2003-10-30 12:36:41 +03:00
|
|
|
@there.xarray_each {|*x| assert_kind_of(XArray, x[0])}
|
2003-10-20 19:24:00 +04:00
|
|
|
end
|
2005-04-11 18:48:50 +04:00
|
|
|
|
|
|
|
def test_06_taint
|
|
|
|
x = proc {}
|
2017-04-07 16:26:12 +03:00
|
|
|
assert_not_predicate(x, :tainted?)
|
2005-04-11 18:48:50 +04:00
|
|
|
@there.echo_yield(x) {|o|
|
|
|
|
assert_equal(x, o)
|
2017-04-07 16:26:12 +03:00
|
|
|
assert_not_predicate(x, :tainted?)
|
2005-04-11 18:48:50 +04:00
|
|
|
}
|
|
|
|
end
|
2003-10-20 19:24:00 +04:00
|
|
|
end
|
|
|
|
|
2018-10-20 16:14:02 +03:00
|
|
|
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
|
|
|
|
|
2003-10-20 19: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
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2018-10-20 16:14:02 +03:00
|
|
|
class TestDRbRuby18Yield < Test::Unit::TestCase
|
|
|
|
include DRbYield
|
|
|
|
|
2003-10-20 19:24:00 +04:00
|
|
|
class YieldTest18
|
|
|
|
def echo_yield(*arg, &proc)
|
|
|
|
proc.call(*arg)
|
|
|
|
end
|
2009-03-06 06:56:38 +03:00
|
|
|
|
2003-10-20 19:24:00 +04:00
|
|
|
def echo_yield_0(&proc)
|
|
|
|
proc.call
|
|
|
|
end
|
2009-03-06 06:56:38 +03:00
|
|
|
|
2003-10-20 19:24:00 +04:00
|
|
|
def echo_yield_1(a, &proc)
|
|
|
|
proc.call(a)
|
|
|
|
end
|
2009-03-06 06:56:38 +03:00
|
|
|
|
2003-10-20 19: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
|
2018-10-20 16:14:02 +03:00
|
|
|
super
|
2003-10-20 19:24:00 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2003-10-21 18:42:15 +04:00
|
|
|
class TestDRbAry < Test::Unit::TestCase
|
|
|
|
include DRbAry
|
2013-06-19 11:47:38 +04:00
|
|
|
|
|
|
|
def setup
|
2014-06-02 15:34:50 +04:00
|
|
|
super
|
2018-10-20 16:14:02 +03:00
|
|
|
setup_service 'ut_array.rb'
|
2014-06-02 15:34:50 +04:00
|
|
|
end
|
2003-10-20 19:24:00 +04:00
|
|
|
end
|
|
|
|
|
2003-10-21 18:42:15 +04:00
|
|
|
class TestDRbMServer < Test::Unit::TestCase
|
2013-06-19 11:47:38 +04:00
|
|
|
include DRbBase
|
|
|
|
|
2003-10-20 19:24:00 +04:00
|
|
|
def setup
|
2013-06-19 11:47:38 +04:00
|
|
|
super
|
2018-10-20 16:14:02 +03:00
|
|
|
setup_service 'ut_drb.rb'
|
2003-10-20 19:24:00 +04:00
|
|
|
@server = (1..3).collect do |n|
|
2015-09-21 22:28:14 +03:00
|
|
|
DRb::DRbServer.new("druby://localhost:0", Onecky.new(n.to_s))
|
2003-10-20 19:24:00 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
|
|
|
@server.each do |s|
|
|
|
|
s.stop_service
|
|
|
|
end
|
2013-06-19 11:47:38 +04:00
|
|
|
super
|
2003-10-20 19:24:00 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_01
|
|
|
|
assert_equal(6, @there.sample(@server[0].front, @server[1].front, @server[2].front))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-10-20 16:14:02 +03:00
|
|
|
class TestDRbSafe1 < Test::Unit::TestCase
|
|
|
|
include DRbAry
|
2003-10-20 19:24:00 +04:00
|
|
|
def setup
|
2014-06-02 15:34:50 +04:00
|
|
|
super
|
2018-10-20 16:14:02 +03:00
|
|
|
setup_service 'ut_safe1.rb'
|
2014-06-02 15:34:50 +04:00
|
|
|
end
|
2003-10-20 19:24:00 +04:00
|
|
|
end
|
|
|
|
|
2003-10-21 18:42:15 +04:00
|
|
|
class TestDRbLarge < Test::Unit::TestCase
|
2013-06-19 11:47:38 +04:00
|
|
|
include DRbBase
|
2003-10-20 19:24:00 +04:00
|
|
|
|
2013-06-19 11:47:38 +04:00
|
|
|
def setup
|
2014-06-02 15:34:50 +04:00
|
|
|
super
|
2018-10-20 16:14:02 +03:00
|
|
|
setup_service 'ut_large.rb'
|
2014-06-02 15:34:50 +04:00
|
|
|
end
|
|
|
|
|
2003-10-20 19:24:00 +04:00
|
|
|
def test_01_large_ary
|
|
|
|
ary = [2] * 10240
|
|
|
|
assert_equal(10240, @there.size(ary))
|
|
|
|
assert_equal(20480, @there.sum(ary))
|
2016-01-31 06:34:21 +03:00
|
|
|
assert_equal(2 ** 10240, @there.multiply(ary))
|
|
|
|
assert_equal(2, @there.avg(ary))
|
|
|
|
assert_equal(2, @there.median(ary))
|
2003-10-20 19:24:00 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_02_large_ary
|
|
|
|
ary = ["Hello, World"] * 10240
|
|
|
|
assert_equal(10240, @there.size(ary))
|
2016-01-31 06:34:21 +03:00
|
|
|
assert_equal(ary[0..ary.length].inject(:+), @there.sum(ary))
|
2017-09-26 03:07:41 +03:00
|
|
|
assert_raise(TypeError) {@there.multiply(ary)}
|
|
|
|
assert_raise(TypeError) {@there.avg(ary)}
|
|
|
|
assert_raise(TypeError) {@there.median(ary)}
|
2003-10-20 19:24:00 +04:00
|
|
|
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 12:52:30 +04:00
|
|
|
assert_raise(DRb::DRbConnError) {
|
2003-10-20 19: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-06 06:56:38 +03:00
|
|
|
@there.size(ary)
|
2003-10-20 19:24:00 +04:00
|
|
|
rescue StandardError
|
|
|
|
exception = $!
|
|
|
|
end
|
|
|
|
assert_kind_of(StandardError, exception)
|
|
|
|
end
|
2016-01-31 06:34:21 +03:00
|
|
|
|
|
|
|
def test_06_array_operations
|
|
|
|
ary = [1,50,3,844,7,45,23]
|
|
|
|
assert_equal(7, @there.size(ary))
|
|
|
|
assert_equal(973, @there.sum(ary))
|
|
|
|
assert_equal(917217000, @there.multiply(ary))
|
|
|
|
assert_equal(139.0, @there.avg(ary))
|
|
|
|
assert_equal(23.0, @there.median(ary))
|
|
|
|
|
|
|
|
ary2 = [1,2,3,4]
|
|
|
|
assert_equal(4, @there.size(ary2))
|
|
|
|
assert_equal(10, @there.sum(ary2))
|
|
|
|
assert_equal(24, @there.multiply(ary2))
|
|
|
|
assert_equal(2.5, @there.avg(ary2))
|
|
|
|
assert_equal(2.5, @there.median(ary2))
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_07_one_element_array
|
|
|
|
ary = [50]
|
|
|
|
assert_equal(1, @there.size(ary))
|
|
|
|
assert_equal(50, @there.sum(ary))
|
|
|
|
assert_equal(50, @there.multiply(ary))
|
|
|
|
assert_equal(50.0, @there.avg(ary))
|
|
|
|
assert_equal(50.0, @there.median(ary))
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_08_empty_array
|
|
|
|
ary = []
|
|
|
|
assert_equal(0, @there.size(ary))
|
|
|
|
assert_equal(nil, @there.sum(ary))
|
|
|
|
assert_equal(nil, @there.multiply(ary))
|
|
|
|
assert_equal(nil, @there.avg(ary))
|
|
|
|
assert_equal(nil, @there.median(ary))
|
|
|
|
end
|
2003-10-20 19:24:00 +04:00
|
|
|
end
|
2011-06-27 19:18:22 +04:00
|
|
|
|
|
|
|
class TestBug4409 < Test::Unit::TestCase
|
2013-06-19 11:47:38 +04:00
|
|
|
include DRbBase
|
2011-06-27 19:18:22 +04:00
|
|
|
|
2013-06-19 11:47:38 +04:00
|
|
|
def setup
|
2014-06-02 15:34:50 +04:00
|
|
|
super
|
2018-10-20 16:14:02 +03:00
|
|
|
setup_service 'ut_eq.rb'
|
2014-06-02 15:34:50 +04:00
|
|
|
end
|
|
|
|
|
2011-06-27 19:18:22 +04:00
|
|
|
def test_bug4409
|
|
|
|
foo = @there.foo
|
2017-04-07 16:26:12 +03:00
|
|
|
assert_operator(@there, :foo?, foo)
|
2011-06-27 19:18:22 +04:00
|
|
|
end
|
|
|
|
end
|
2014-06-01 07:07:58 +04:00
|
|
|
|
|
|
|
end
|