Skip to content

Commit

Permalink
* test/rinda/test_rinda.rb (test_core_03_notify): Fixed test failures
Browse files Browse the repository at this point in the history
	  [ruby-dev:44430] [Ruby 1.9 - Bug ruby#372]



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33196 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
seki committed Sep 5, 2011
1 parent 4117048 commit 3195315
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 55 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
@@ -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).
Expand Down
75 changes: 20 additions & 55 deletions test/rinda/test_rinda.rb
Expand Up @@ -308,70 +308,35 @@ def test_core_02

def test_core_03_notify
notify1 = @ts.notify(nil, [:req, Integer])
notify2 = @ts.notify(nil, {"message"=>String, "name"=>String}, 8)
notify2 = @ts.notify(nil, {"message"=>String, "name"=>String})

@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]
5.times do |n|
@ts.write([:req, 2])
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
5.times do
tuple = @ts.take([:req, Integer])
assert_equal(2, tuple[1])
end

5.times do |n|
@ts.write([:req, 2])
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
Expand Down

0 comments on commit 3195315

Please sign in to comment.