1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* test/rinda/test_rinda.rb (test_core_03_notify): Fixed test failures

[ruby-dev:44430] [Ruby 1.9 - Bug #372]



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33196 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
seki 2011-09-05 20:39:54 +00:00
parent 4117048c40
commit 319531524b
2 changed files with 27 additions and 57 deletions

View file

@ -1,3 +1,8 @@
Tue Sep 6 05:37:11 2011 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
* test/rinda/test_rinda.rb (test_core_03_notify): Fixed test failures
[ruby-dev:44430] [Ruby 1.9 - Bug #372]
Mon Sep 5 20:59:30 2011 CHIKANAGA Tomoyuki <nagachika00@gmail.com>
* insns.def: change encoding pragma for emacs (shift_jis to utf-8).

View file

@ -308,70 +308,35 @@ module TupleSpaceTestModule
def test_core_03_notify
notify1 = @ts.notify(nil, [:req, Integer])
notify2 = @ts.notify(nil, {"message"=>String, "name"=>String}, 8)
@ts.write({"message"=>"first", "name"=>"3"}, 3)
@ts.write({"message"=>"second", "name"=>"1"}, 1)
@ts.write({"message"=>"third", "name"=>"0"})
@ts.take({"message"=>"third", "name"=>"0"})
listener = Thread.new do
lv = 0
n = 0
notify1.each do |ev, tuple|
n += 1
if ev == 'write'
lv = lv + 1
elsif ev == 'take'
lv = lv - 1
else
break
end
assert(lv >= 0)
assert_equal([:req, 2], tuple)
end
[lv, n]
end
taker = Thread.new(5) do |count|
s = 0
count.times do
tuple = @ts.take([:req, Integer])
assert_equal(2, tuple[1])
s += tuple[1]
end
@ts.write([:ans, s])
s
end
notify2 = @ts.notify(nil, {"message"=>String, "name"=>String})
5.times do |n|
@ts.write([:req, 2])
end
5.times do
tuple = @ts.take([:req, Integer])
assert_equal(2, tuple[1])
end
5.times do
assert_equal(['write', [:req, 2]], notify1.pop)
end
5.times do
assert_equal(['take', [:req, 2]], notify1.pop)
end
@ts.write({"message"=>"first", "name"=>"3"})
@ts.write({"message"=>"second", "name"=>"1"})
@ts.write({"message"=>"third", "name"=>"0"})
@ts.take({"message"=>"third", "name"=>"0"})
@ts.take({"message"=>"first", "name"=>"3"})
assert_equal(10, thread_join(taker))
assert_equal([:ans, 10], @ts.take([:ans, 10]))
assert_equal([], @ts.read_all([nil, nil]))
notify1.cancel
sleep(8)
assert_equal([0, 11], thread_join(listener))
ary = []
ary.push(["write", {"message"=>"first", "name"=>"3"}])
ary.push(["write", {"message"=>"second", "name"=>"1"}])
ary.push(["write", {"message"=>"third", "name"=>"0"}])
ary.push(["take", {"message"=>"third", "name"=>"0"}])
ary.push(["take", {"message"=>"first", "name"=>"3"}])
ary.push(["delete", {"message"=>"second", "name"=>"1"}])
ary.push(["close"])
notify2.each do |ev|
assert_equal(ary.shift, ev)
end
assert_equal([], ary)
assert_equal(["write", {"message"=>"first", "name"=>"3"}], notify2.pop)
assert_equal(["write", {"message"=>"second", "name"=>"1"}], notify2.pop)
assert_equal(["write", {"message"=>"third", "name"=>"0"}], notify2.pop)
assert_equal(["take", {"message"=>"third", "name"=>"0"}], notify2.pop)
assert_equal(["take", {"message"=>"first", "name"=>"3"}], notify2.pop)
end
def test_cancel_01