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

the code that depends on timing. [Bug #372] [Bug #4160]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32717 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
seki 2011-07-28 03:25:55 +00:00
parent da6c57aa54
commit e2b800113c
2 changed files with 29 additions and 62 deletions

View file

@ -1,3 +1,8 @@
Thu Jul 28 12:21:15 2011 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
* test/rinda/test_rinda.rb: decrease the code that depends on timing.
[Bug #372] [Bug #4160]
Thu Jul 28 04:53:31 2011 Eric Hodel <drbrain@segment7.net> Thu Jul 28 04:53:31 2011 Eric Hodel <drbrain@segment7.net>
* lib/delegate.rb: Move file-level documentation to the appropriate * lib/delegate.rb: Move file-level documentation to the appropriate

View file

@ -269,37 +269,29 @@ module TupleSpaceTestModule
assert_equal([[:req, 2], [:req, 2], [:req, 2], [:req, 2], [:req, 2]], assert_equal([[:req, 2], [:req, 2], [:req, 2], [:req, 2], [:req, 2]],
@ts.read_all([nil, nil])) @ts.read_all([nil, nil]))
taker = Thread.new do taker = Thread.new(5) do |count|
s = 0 s = 0
while true count.times do
begin tuple = @ts.take([:req, Integer])
tuple = @ts.take([:req, Integer], 1) assert_equal(2, tuple[1])
assert_equal(2, tuple[1]) s += tuple[1]
s += tuple[1]
rescue Rinda::RequestExpiredError
break
end
end end
@ts.write([:ans, s]) @ts.write([:ans, s])
s s
end end
assert_equal(10, thread_join(taker)) assert_equal(10, thread_join(taker))
tuple = @ts.take([:ans, nil]) assert_equal([:ans, 10], @ts.take([:ans, 10]))
assert_equal(10, tuple[1]) assert_equal([], @ts.read_all([nil, nil]))
end end
def test_core_02 def test_core_02
taker = Thread.new do taker = Thread.new(5) do |count|
s = 0 s = 0
while true count.times do
begin tuple = @ts.take([:req, Integer])
tuple = @ts.take([:req, Integer], 1) assert_equal(2, tuple[1])
assert_equal(2, tuple[1]) s += tuple[1]
s += tuple[1]
rescue Rinda::RequestExpiredError
break
end
end end
@ts.write([:ans, s]) @ts.write([:ans, s])
s s
@ -310,22 +302,20 @@ module TupleSpaceTestModule
end end
assert_equal(10, thread_join(taker)) assert_equal(10, thread_join(taker))
tuple = @ts.take([:ans, nil]) assert_equal([:ans, 10], @ts.take([:ans, 10]))
assert_equal(10, tuple[1])
assert_equal([], @ts.read_all([nil, nil])) assert_equal([], @ts.read_all([nil, nil]))
end end
def test_core_03_notify def test_core_03_notify
notify1 = @ts.notify(nil, [:req, Integer]) notify1 = @ts.notify(nil, [:req, Integer])
notify2 = @ts.notify(nil, [:ans, Integer], 8) notify2 = @ts.notify(nil, {"message"=>String, "name"=>String}, 8)
notify3 = @ts.notify(nil, {"message"=>String, "name"=>String}, 8)
@ts.write({"message"=>"first", "name"=>"3"}, 3) @ts.write({"message"=>"first", "name"=>"3"}, 3)
@ts.write({"message"=>"second", "name"=>"1"}, 1) @ts.write({"message"=>"second", "name"=>"1"}, 1)
@ts.write({"message"=>"third", "name"=>"0"}) @ts.write({"message"=>"third", "name"=>"0"})
@ts.take({"message"=>"third", "name"=>"0"}) @ts.take({"message"=>"third", "name"=>"0"})
listener1 = Thread.new do listener = Thread.new do
lv = 0 lv = 0
n = 0 n = 0
notify1.each do |ev, tuple| notify1.each do |ev, tuple|
@ -343,35 +333,12 @@ module TupleSpaceTestModule
[lv, n] [lv, n]
end end
listener2 = Thread.new do taker = Thread.new(5) do |count|
result = nil
lv = 0
n = 0
notify2.each do |ev, tuple|
n += 1
if ev == 'write'
lv = lv + 1
elsif ev == 'take'
lv = lv - 1
elsif ev == 'close'
result = [lv, n]
break
end
assert(lv >= 0)
assert_equal([:ans, 10], tuple)
end
result
end
taker = Thread.new do
s = 0 s = 0
while true count.times do
begin tuple = @ts.take([:req, Integer])
tuple = @ts.take([:req, Integer], 1) assert_equal(2, tuple[1])
s += tuple[1] s += tuple[1]
rescue Rinda::RequestExpiredError
break
end
end end
@ts.write([:ans, s]) @ts.write([:ans, s])
s s
@ -383,19 +350,14 @@ module TupleSpaceTestModule
@ts.take({"message"=>"first", "name"=>"3"}) @ts.take({"message"=>"first", "name"=>"3"})
sleep(4)
assert_equal(10, thread_join(taker)) assert_equal(10, thread_join(taker))
# notify2 must not expire until this @ts.take. assert_equal([:ans, 10], @ts.take([:ans, 10]))
# sleep(4) might be short enough for the timeout of notify2 (8 secs)
tuple = @ts.take([:ans, nil])
assert_equal(10, tuple[1])
assert_equal([], @ts.read_all([nil, nil])) assert_equal([], @ts.read_all([nil, nil]))
notify1.cancel notify1.cancel
sleep(7) # notify2 expired (sleep(4)+sleep(7) > 8) sleep(8)
assert_equal([0, 11], thread_join(listener1)) assert_equal([0, 11], thread_join(listener))
assert_equal([0, 3], thread_join(listener2))
ary = [] ary = []
ary.push(["write", {"message"=>"first", "name"=>"3"}]) ary.push(["write", {"message"=>"first", "name"=>"3"}])
@ -406,7 +368,7 @@ module TupleSpaceTestModule
ary.push(["delete", {"message"=>"second", "name"=>"1"}]) ary.push(["delete", {"message"=>"second", "name"=>"1"}])
ary.push(["close"]) ary.push(["close"])
notify3.each do |ev| notify2.each do |ev|
assert_equal(ary.shift, ev) assert_equal(ary.shift, ev)
end end
assert_equal([], ary) assert_equal([], ary)