1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

Stop using lazy enumeration with any version of JRuby

This commit is contained in:
Thomas Walpole 2020-05-15 09:04:53 -07:00
parent ed0ecb18b7
commit 98c2206b87
2 changed files with 5 additions and 18 deletions

View file

@ -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

View file

@ -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