diff options
author | Kazuhiro NISHIYAMA <zn@mbf.nifty.com> | 2019-12-06 00:11:11 +0900 |
---|---|---|
committer | Kazuhiro NISHIYAMA <zn@mbf.nifty.com> | 2019-12-06 00:12:58 +0900 |
commit | 693cba1a136aafb0faa25f93434a2e8dbad320de (patch) | |
tree | 111ff8ad5159ec1a7ae07af84df668eddaf4c4f2 /test/ruby | |
parent | 173b864668777ef157a0c82b6e6f1a6aa0f06ac9 (diff) | |
download | ruby-693cba1a136aafb0faa25f93434a2e8dbad320de.tar.gz |
Detect started threads when require only
Diffstat (limited to 'test/ruby')
-rw-r--r-- | test/ruby/test_require_lib.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/test/ruby/test_require_lib.rb b/test/ruby/test_require_lib.rb new file mode 100644 index 0000000000..4af57173b8 --- /dev/null +++ b/test/ruby/test_require_lib.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: false +require 'test/unit' + +class TestRequireLib < Test::Unit::TestCase + TEST_RATIO = ENV["TEST_REQUIRE_THREAD_RATIO"]&.tap {|s|break s.to_f} || 0.05 # testing all files needs too long time... + + Dir.glob(File.expand_path('../../lib/**/*.rb', __dir__)).each do |lib| + # skip some problems + next if %r!/lib/(?:bundler|rubygems)\b! =~ lib + next if %r!/lib/(?:debug|mkmf)\.rb\z! =~ lib + # skip because "in `<module:Maker>': undefined method `add_maker' for RSS::Maker:Module (NoMethodError)" + next if %r!/lib/rss\b! =~ lib + # skip many files that almost use no threads + next if TEST_RATIO < rand(0.0..1.0) + define_method "test_thread_size:#{lib}" do + assert_separately(['--disable-gems', '-W0'], "#{<<~"begin;"}\n#{<<~"end;"}") + begin; + n = Thread.list.size + begin + require #{lib.dump} + rescue Exception + skip $! + end + assert_equal n, Thread.list.size + end; + end + end +end |