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 Feb 10, 2017
1 parent b3df991 commit 4a94e33
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 @@ -435,6 +435,28 @@ def test_xpath_after_reset_doc_via_innerhtml
assert_equal 1, sections.size
assert_equal "[TEXT_INSIDE_SECTION]", sections.first.text
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 4a94e33

Please sign in to comment.