diff options
author | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-12-27 14:50:49 +0000 |
---|---|---|
committer | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-12-27 14:50:49 +0000 |
commit | f8fac84c7ba232166fdacdcff026e6ea0570075b (patch) | |
tree | 0c784f162cb300926d8417240ed0be3d26008926 /test | |
parent | ecbb128273cd7b15d7ad9c96048275ec4f582342 (diff) | |
download | ruby-f8fac84c7ba232166fdacdcff026e6ea0570075b.tar.gz |
fix concurrent test.
* test/rubygems/test_require.rb (test_concurrent_require):
Synchronizations should be in ensure clause. Sometimes
`require` fails (not sure why) and latch is not released.
Such case introduces unlimited awaiting.
This patch soleve this problem.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61501 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/rubygems/test_require.rb | 30 |
1 files changed, 11 insertions, 19 deletions
diff --git a/test/rubygems/test_require.rb b/test/rubygems/test_require.rb index a846f46833..a106fc21a6 100644 --- a/test/rubygems/test_require.rb +++ b/test/rubygems/test_require.rb @@ -38,18 +38,6 @@ class TestGemRequire < Gem::TestCase assert require(path), "'#{path}' was already required" end - def append_latch spec - dir = spec.gem_dir - Dir.chdir dir do - spec.files.each do |file| - File.open file, 'a' do |fp| - fp.puts "FILE_ENTERED_LATCH.release" - fp.puts "FILE_EXIT_LATCH.await" - end - end - end - end - # Providing -I on the commandline should always beat gems def test_dash_i_beats_gems a1 = new_spec "a", "1", {"b" => "= 1"}, "lib/test_gem_require_a.rb" @@ -80,6 +68,15 @@ class TestGemRequire < Gem::TestCase Object.send :remove_const, :HELLO if Object.const_defined? :HELLO end + def create_sync_thread + Thread.new do + yield + ensure + FILE_ENTERED_LATCH.release + FILE_EXIT_LATCH.await + end + end + def test_concurrent_require skip 'deadlock' if /^1\.8\./ =~ RUBY_VERSION @@ -91,11 +88,8 @@ class TestGemRequire < Gem::TestCase install_specs a1, b1 - append_latch a1 - append_latch b1 - - t1 = Thread.new { assert_require 'a' } - t2 = Thread.new { assert_require 'b' } + t1 = create_sync_thread{ assert_require 'a' } + t2 = create_sync_thread{ assert_require 'b' } # wait until both files are waiting on the exit latch FILE_ENTERED_LATCH.await @@ -106,8 +100,6 @@ class TestGemRequire < Gem::TestCase assert t1.join, "thread 1 should exit" assert t2.join, "thread 2 should exit" ensure - return if $! # skipping - Object.send :remove_const, :FILE_ENTERED_LATCH Object.send :remove_const, :FILE_EXIT_LATCH end |