ruby-changes:49386
From: ko1 <ko1@a...>
Date: Wed, 27 Dec 2017 23:50:55 +0900 (JST)
Subject: [ruby-changes:49386] ko1:r61501 (trunk): fix concurrent test.
ko1 2017-12-27 23:50:49 +0900 (Wed, 27 Dec 2017) New Revision: 61501 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61501 Log: 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. Modified files: trunk/test/rubygems/test_require.rb Index: test/rubygems/test_require.rb =================================================================== --- test/rubygems/test_require.rb (revision 61500) +++ test/rubygems/test_require.rb (revision 61501) @@ -38,18 +38,6 @@ class TestGemRequire < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_require.rb#L38 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 https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_require.rb#L68 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 https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_require.rb#L88 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 https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_require.rb#L100 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/