Skip to content

Commit

Permalink
Add test to show #xpath is not thread-safe
Browse files Browse the repository at this point in the history
This test was submitted in #1596 by @kares.
  • Loading branch information
flavorjones committed Jan 22, 2019
1 parent 281881c commit 792e711
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions test/xml/test_xpath.rb
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,28 @@ def test_xpath_syntax_error
assert_equal false, e.message.include?('0:0')
end
end

def test_concurrent_xpath
skip("MRI doesn't have real threads") unless Nokogiri.jruby?
doc = Nokogiri::XML(File.open(XPATH_FILE))

threads = []; errors = []
4.times do |i|
threads << Thread.start do
begin
sleep 0.01 * i
assert_equal 11, doc.xpath('.//category').size
assert_equal 1165, doc.xpath('//module').size
assert_equal 10353, doc.xpath('//module/param').size
assert_equal 14, doc.xpath('//param[@name="href"]').size
rescue Exception => ex
errors << ex
end
end
end
threads.each(&:join)
raise errors.first if errors.any?
end
end
end
end

0 comments on commit 792e711

Please sign in to comment.