mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* test/ruby/test_require.rb (test_race_exception): rewrote without
global attribute. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34077 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f26ee7454f
commit
0ead5c4983
1 changed files with 25 additions and 25 deletions
|
@ -340,57 +340,57 @@ class TestRequire < Test::Unit::TestCase
|
||||||
bug3756)
|
bug3756)
|
||||||
end
|
end
|
||||||
|
|
||||||
class << self
|
|
||||||
attr_accessor :scratch
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_race_exception
|
def test_race_exception
|
||||||
bug5754 = '[ruby-core:41618]'
|
bug5754 = '[ruby-core:41618]'
|
||||||
tmp = Tempfile.new(%w"bug5754 .rb")
|
tmp = Tempfile.new(%w"bug5754 .rb")
|
||||||
path = tmp.path
|
path = tmp.path
|
||||||
tmp.print <<-EOS
|
tmp.print %{\
|
||||||
TestRequire.scratch << :pre
|
th = Thread.current
|
||||||
Thread.pass until t2 = TestRequire.scratch[1]
|
t = th[:t]
|
||||||
Thread.pass until t2.stop?
|
scratch = th[:scratch]
|
||||||
open(__FILE__, "w") {|f| f.puts "TestRequire.scratch << :post"}
|
|
||||||
raise "con1"
|
if scratch.empty?
|
||||||
EOS
|
scratch << :pre
|
||||||
|
Thread.pass until t.stop?
|
||||||
|
raise RuntimeError
|
||||||
|
else
|
||||||
|
scratch << :post
|
||||||
|
end
|
||||||
|
}
|
||||||
tmp.close
|
tmp.close
|
||||||
|
|
||||||
fin = false
|
start = false
|
||||||
|
|
||||||
TestRequire.scratch = scratch = []
|
scratch = []
|
||||||
t1_res = nil
|
t1_res = nil
|
||||||
t2_res = nil
|
t2_res = nil
|
||||||
|
|
||||||
t1 = Thread.new do
|
t1 = Thread.new do
|
||||||
|
Thread.pass until start
|
||||||
begin
|
begin
|
||||||
require(path)
|
require(path)
|
||||||
rescue RuntimeError
|
rescue RuntimeError
|
||||||
end
|
end
|
||||||
|
|
||||||
t1_res = require(path)
|
t1_res = require(path)
|
||||||
|
|
||||||
Thread.pass until fin
|
|
||||||
scratch << :t1
|
|
||||||
end
|
end
|
||||||
|
|
||||||
t2 = Thread.new do
|
t2 = Thread.new do
|
||||||
Thread.pass until scratch[0]
|
Thread.pass until scratch[0]
|
||||||
begin
|
t2_res = require(path)
|
||||||
scratch << t2
|
|
||||||
t2_res = require(path)
|
|
||||||
scratch << :t2
|
|
||||||
ensure
|
|
||||||
fin = true
|
|
||||||
end
|
|
||||||
end
|
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) {t1.join}
|
||||||
assert_nothing_raised(ThreadError, bug5754) {t2.join}
|
assert_nothing_raised(ThreadError, bug5754) {t2.join}
|
||||||
|
|
||||||
assert_equal(true, (t1_res ^ t2_res), bug5754)
|
assert_equal(true, (t1_res ^ t2_res), bug5754 + " t1:#{t1_res} t2:#{t2_res}")
|
||||||
assert_equal([:pre, t2, :post, :t2, :t1], scratch, bug5754)
|
assert_equal([:pre, :post], scratch, bug5754)
|
||||||
ensure
|
ensure
|
||||||
tmp.close(true) if tmp
|
tmp.close(true) if tmp
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue