diff --git a/lib/capybara/result.rb b/lib/capybara/result.rb index 616c7a70..936d1e9d 100644 --- a/lib/capybara/result.rb +++ b/lib/capybara/result.rb @@ -171,10 +171,13 @@ module Capybara @rest ||= @elements - full_results end - if (RUBY_PLATFORM == 'java') && (Gem::Version.new(JRUBY_VERSION) < Gem::Version.new('9.2.8.0')) + if RUBY_PLATFORM == 'java' # JRuby < 9.2.8.0 has an issue with lazy enumerators which # causes a concurrency issue with network requests here # https://github.com/jruby/jruby/issues/4212 + # while JRuby >= 9.2.8.0 leaks threads when using lazy enumerators + # https://github.com/teamcapybara/capybara/issues/2349 + # so disable the use and JRuby users will need to pay a performance penalty def lazy_select_elements(&block) @elements.select(&block).to_enum # non-lazy evaluation end diff --git a/spec/result_spec.rb b/spec/result_spec.rb index d6bc15aa..73bf89d5 100644 --- a/spec/result_spec.rb +++ b/spec/result_spec.rb @@ -190,23 +190,7 @@ RSpec.describe Capybara::Result do end end - context 'lazy select' do - it 'is compatible' do - # This test will let us know when JRuby fixes lazy select so we can re-enable it in Result - pending 'JRuby < 9.2.8.0 has an issue with lazy enumberator evaluation' if jruby_lazy_enumerator_workaround? - eval_count = 0 - enum = %w[Text1 Text2 Text3].lazy.select do - eval_count += 1 - true - end - expect(eval_count).to eq 0 - enum.next - sleep 1 - expect(eval_count).to eq 1 - end - end - def jruby_lazy_enumerator_workaround? - (RUBY_PLATFORM == 'java') && (Gem::Version.new(JRUBY_VERSION) < Gem::Version.new('9.2.8.0')) + RUBY_PLATFORM == 'java' end end