[前][次][番号順一覧][スレッド一覧]

ruby-changes:20669

From: seki <ko1@a...>
Date: Thu, 28 Jul 2011 12:26:08 +0900 (JST)
Subject: [ruby-changes:20669] seki:r32717 (trunk): the code that depends on timing. [Bug #372] [Bug #4160]

seki	2011-07-28 12:25:55 +0900 (Thu, 28 Jul 2011)

  New Revision: 32717

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=32717

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

  Modified files:
    trunk/ChangeLog
    trunk/test/rinda/test_rinda.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 32716)
+++ ChangeLog	(revision 32717)
@@ -1,3 +1,8 @@
+Thu Jul 28 12:21:15 2011  Masatoshi SEKI  <m_seki@m...>
+
+	* 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@s...>
 
 	* lib/delegate.rb:  Move file-level documentation to the appropriate
Index: test/rinda/test_rinda.rb
===================================================================
--- test/rinda/test_rinda.rb	(revision 32716)
+++ test/rinda/test_rinda.rb	(revision 32717)
@@ -269,37 +269,29 @@
     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 @@
     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 @@
       [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 @@
 
     @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 @@
     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)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]