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
|
2014-06-02 07:34:50 -04:00
|
|
|
super
|
2018-10-20 09:14:02 -04:00
|
|
|
setup_service 'ut_drb.rb'
|
2014-06-02 07:34:50 -04:00
|
|
|
end
|
2013-06-19 03:47:38 -04:00
|
|
|
end
|
2003-10-20 11:24:00 -04:00
|
|
|
|
2018-10-20 09:14:02 -04:00
|
|
|
module DRbYield
|
2013-06-19 03:47:38 -04:00
|
|
|
include DRbBase
|
|
|
|
|
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
|
|
|
|
end
|
|
|
|
|
2018-10-20 09:14:02 -04: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 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
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2018-10-20 09:14:02 -04:00
|
|
|
class TestDRbRuby18Yield < Test::Unit::TestCase
|
|
|
|
include DRbYield
|
|
|
|
|
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
|
2018-10-20 09:14:02 -04:00
|
|
|
super
|
2003-10-20 11:24:00 -04:00
|
|
|
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
|
2014-06-02 07:34:50 -04:00
|
|
|
super
|
2018-10-20 09:14:02 -04:00
|
|
|
setup_service 'ut_array.rb'
|
2014-06-02 07:34:50 -04:00
|
|
|
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
|
|
|
super
|
2018-10-20 09:14:02 -04:00
|
|
|
setup_service 'ut_drb.rb'
|
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
|
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
|
|
|
|
|
2018-10-20 09:14:02 -04:00
|
|
|
class TestDRbSafe1 < Test::Unit::TestCase
|
|
|
|
include DRbAry
|
2003-10-20 11:24:00 -04:00
|
|
|
def setup
|
2014-06-02 07:34:50 -04:00
|
|
|
super
|
2018-10-20 09:14:02 -04:00
|
|
|
setup_service 'ut_safe1.rb'
|
2014-06-02 07:34:50 -04:00
|
|
|
end
|
2003-10-20 11:24:00 -04:00
|
|
|
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
|
2014-06-02 07:34:50 -04:00
|
|
|
super
|
2018-10-20 09:14:02 -04:00
|
|
|
setup_service 'ut_large.rb'
|
2014-06-02 07:34:50 -04:00
|
|
|
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))
|
2016-01-30 22:34:21 -05:00
|
|
|
assert_equal(2 ** 10240, @there.multiply(ary))
|
|
|
|
assert_equal(2, @there.avg(ary))
|
|
|
|
assert_equal(2, @there.median(ary))
|
2003-10-20 11:24:00 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_02_large_ary
|
|
|
|
ary = ["Hello, World"] * 10240
|
|
|
|
assert_equal(10240, @there.size(ary))
|
2016-01-30 22:34:21 -05:00
|
|
|
assert_equal(ary[0..ary.length].inject(:+), @there.sum(ary))
|
2017-09-25 20:07:41 -04:00
|
|
|
assert_raise(TypeError) {@there.multiply(ary)}
|
|
|
|
assert_raise(TypeError) {@there.avg(ary)}
|
|
|
|
assert_raise(TypeError) {@there.median(ary)}
|
2003-10-20 11: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 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
|
2016-01-30 22:34:21 -05: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 11:24:00 -04:00
|
|
|
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
|
2014-06-02 07:34:50 -04:00
|
|
|
super
|
2018-10-20 09:14:02 -04:00
|
|
|
setup_service 'ut_eq.rb'
|
2014-06-02 07:34:50 -04:00
|
|
|
end
|
|
|
|
|
2011-06-27 11:18:22 -04:00
|
|
|
def test_bug4409
|
|
|
|
foo = @there.foo
|
2017-04-07 09:26:12 -04:00
|
|
|
assert_operator(@there, :foo?, foo)
|
2011-06-27 11:18:22 -04:00
|
|
|
end
|
|
|
|
end
|
2014-05-31 23:07:58 -04:00
|
|
|
|
2019-10-14 12:00:42 -04:00
|
|
|
class TestDRbAnyToS < Test::Unit::TestCase
|
|
|
|
class BO < BasicObject
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_any_to_s
|
|
|
|
server = DRb::DRbServer.new('druby://:0')
|
|
|
|
server.singleton_class.send(:public, :any_to_s)
|
|
|
|
assert_equal("foo:String", server.any_to_s("foo"))
|
|
|
|
assert_match(/\A#<DRbTests::TestDRbAnyToS::BO:0x[0-9a-f]+>\z/, server.any_to_s(BO.new))
|
|
|
|
server.stop_service
|
|
|
|
server.thread.join
|
2019-12-09 22:41:09 -05:00
|
|
|
DRb::DRbConn.stop_pool
|
2019-10-14 12:00:42 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-08-08 18:44:26 -04:00
|
|
|
class TestDRbTCP < Test::Unit::TestCase
|
|
|
|
def test_immediate_close
|
|
|
|
server = DRb::DRbServer.new('druby://:0')
|
|
|
|
host, port, = DRb::DRbTCPSocket.send(:parse_uri, server.uri)
|
|
|
|
socket = TCPSocket.open host, port
|
|
|
|
socket.shutdown
|
|
|
|
socket.close
|
|
|
|
client = DRb::DRbTCPSocket.new(server.uri, socket)
|
|
|
|
assert client
|
|
|
|
client.close
|
|
|
|
server.stop_service
|
|
|
|
server.thread.join
|
2019-12-09 22:41:09 -05:00
|
|
|
DRb::DRbConn.stop_pool
|
2019-08-08 18:44:26 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-02-15 02:27:03 -05:00
|
|
|
class TestBug16634 < Test::Unit::TestCase
|
|
|
|
include DRbBase
|
|
|
|
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
setup_service 'ut_drb.rb'
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_bug16634
|
|
|
|
assert_equal(42, @there.keyword_test1(a: 42))
|
|
|
|
assert_equal("default", @there.keyword_test2)
|
|
|
|
assert_equal(42, @there.keyword_test2(b: 42))
|
|
|
|
assert_equal({:a=>42, :b=>42}, @there.keyword_test3(a: 42, b: 42))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-05-31 23:07:58 -04:00
|
|
|
end
|