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

ruby-changes:22028

From: nobu <ko1@a...>
Date: Tue, 20 Dec 2011 14:58:05 +0900 (JST)
Subject: [ruby-changes:22028] nobu:r34077 (trunk): * test/ruby/test_require.rb (test_race_exception): rewrote without

nobu	2011-12-20 14:57:53 +0900 (Tue, 20 Dec 2011)

  New Revision: 34077

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

  Log:
    * test/ruby/test_require.rb (test_race_exception): rewrote without
      global attribute.

  Modified files:
    trunk/test/ruby/test_require.rb

Index: test/ruby/test_require.rb
===================================================================
--- test/ruby/test_require.rb	(revision 34076)
+++ test/ruby/test_require.rb	(revision 34077)
@@ -340,57 +340,57 @@
                       bug3756)
   end
 
-  class << self
-    attr_accessor :scratch
-  end
-
   def test_race_exception
     bug5754 = '[ruby-core:41618]'
     tmp = Tempfile.new(%w"bug5754 .rb")
     path = tmp.path
-    tmp.print <<-EOS
-TestRequire.scratch << :pre
-Thread.pass until t2 = TestRequire.scratch[1]
-Thread.pass until t2.stop?
-open(__FILE__, "w") {|f| f.puts "TestRequire.scratch << :post"}
-raise "con1"
-    EOS
+    tmp.print %{\
+      th = Thread.current
+      t = th[:t]
+      scratch = th[:scratch]
+
+      if scratch.empty?
+        scratch << :pre
+        Thread.pass until t.stop?
+        raise RuntimeError
+      else
+        scratch << :post
+      end
+    }
     tmp.close
 
-    fin = false
+    start = false
 
-    TestRequire.scratch = scratch = []
+    scratch = []
     t1_res = nil
     t2_res = nil
 
     t1 = Thread.new do
+      Thread.pass until start
       begin
         require(path)
       rescue RuntimeError
       end
 
       t1_res = require(path)
-
-      Thread.pass until fin
-      scratch << :t1
     end
 
     t2 = Thread.new do
       Thread.pass until scratch[0]
-      begin
-        scratch << t2
-        t2_res = require(path)
-        scratch << :t2
-      ensure
-        fin = true
-      end
+      t2_res = require(path)
     end
 
+    t1[:scratch] = t2[:scratch] = scratch
+    t1[:t] = t2
+    t2[:t] = t1
+
+    start = true
+
     assert_nothing_raised(ThreadError, bug5754) {t1.join}
     assert_nothing_raised(ThreadError, bug5754) {t2.join}
 
-    assert_equal(true, (t1_res ^ t2_res), bug5754)
-    assert_equal([:pre, t2, :post, :t2, :t1], scratch, bug5754)
+    assert_equal(true, (t1_res ^ t2_res), bug5754 + " t1:#{t1_res} t2:#{t2_res}")
+    assert_equal([:pre, :post], scratch, bug5754)
   ensure
     tmp.close(true) if tmp
   end

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

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