summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorseki <seki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-07-28 03:25:55 +0000
committerseki <seki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-07-28 03:25:55 +0000
commite2b800113cae1e3b5b28e24f520fe694bd27506b (patch)
tree4729997b7fa144d4521d55bcdd8afd56bee30143
parentda6c57aa54182447491d2650269e3ba98437ef86 (diff)
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
-rw-r--r--ChangeLog5
-rw-r--r--test/rinda/test_rinda.rb86
2 files changed, 29 insertions, 62 deletions
diff --git a/ChangeLog b/ChangeLog
index 0550f0e12a..6a0e9e4fc7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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>
* lib/delegate.rb: Move file-level documentation to the appropriate
diff --git a/test/rinda/test_rinda.rb b/test/rinda/test_rinda.rb
index e91ecf395f..8154b46da3 100644
--- a/test/rinda/test_rinda.rb
+++ b/test/rinda/test_rinda.rb
@@ -269,37 +269,29 @@ module TupleSpaceTestModule
assert_equal([[:req, 2], [:req, 2], [:req, 2], [:req, 2], [:req, 2]],
@ts.read_all([nil, nil]))
- taker = Thread.new do
+ taker = Thread.new(5) do |count|
s = 0
- while true
- begin
- tuple = @ts.take([:req, Integer], 1)
- assert_equal(2, tuple[1])
- s += tuple[1]
- rescue Rinda::RequestExpiredError
- break
- end
+ count.times do
+ tuple = @ts.take([:req, Integer])
+ assert_equal(2, tuple[1])
+ s += tuple[1]
end
@ts.write([:ans, s])
s
end
assert_equal(10, thread_join(taker))
- tuple = @ts.take([:ans, nil])
- assert_equal(10, tuple[1])
+ assert_equal([:ans, 10], @ts.take([:ans, 10]))
+ assert_equal([], @ts.read_all([nil, nil]))
end
def test_core_02
- taker = Thread.new do
+ taker = Thread.new(5) do |count|
s = 0
- while true
- begin
- tuple = @ts.take([:req, Integer], 1)
- assert_equal(2, tuple[1])
- s += tuple[1]
- rescue Rinda::RequestExpiredError
- break
- end
+ count.times do
+ tuple = @ts.take([:req, Integer])
+ assert_equal(2, tuple[1])
+ s += tuple[1]
end
@ts.write([:ans, s])
s
@@ -310,22 +302,20 @@ module TupleSpaceTestModule
end
assert_equal(10, thread_join(taker))
- tuple = @ts.take([:ans, nil])
- assert_equal(10, tuple[1])
+ assert_equal([:ans, 10], @ts.take([:ans, 10]))
assert_equal([], @ts.read_all([nil, nil]))
end
def test_core_03_notify
notify1 = @ts.notify(nil, [:req, Integer])
- notify2 = @ts.notify(nil, [:ans, Integer], 8)
- notify3 = @ts.notify(nil, {"message"=>String, "name"=>String}, 8)
+ 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"})
- listener1 = Thread.new do
+ listener = Thread.new do
lv = 0
n = 0
notify1.each do |ev, tuple|
@@ -343,35 +333,12 @@ module TupleSpaceTestModule
[lv, n]
end
- listener2 = Thread.new do
- 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
+ taker = Thread.new(5) do |count|
s = 0
- while true
- begin
- tuple = @ts.take([:req, Integer], 1)
- s += tuple[1]
- rescue Rinda::RequestExpiredError
- break
- end
+ count.times do
+ tuple = @ts.take([:req, Integer])
+ assert_equal(2, tuple[1])
+ s += tuple[1]
end
@ts.write([:ans, s])
s
@@ -383,19 +350,14 @@ module TupleSpaceTestModule
@ts.take({"message"=>"first", "name"=>"3"})
- sleep(4)
assert_equal(10, thread_join(taker))
- # notify2 must not expire until this @ts.take.
- # 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([:ans, 10], @ts.take([:ans, 10]))
assert_equal([], @ts.read_all([nil, nil]))
notify1.cancel
- sleep(7) # notify2 expired (sleep(4)+sleep(7) > 8)
+ sleep(8)
- assert_equal([0, 11], thread_join(listener1))
- assert_equal([0, 3], thread_join(listener2))
+ assert_equal([0, 11], thread_join(listener))
ary = []
ary.push(["write", {"message"=>"first", "name"=>"3"}])
@@ -406,7 +368,7 @@ module TupleSpaceTestModule
ary.push(["delete", {"message"=>"second", "name"=>"1"}])
ary.push(["close"])
- notify3.each do |ev|
+ notify2.each do |ev|
assert_equal(ary.shift, ev)
end
assert_equal([], ary)