Skip to content

Commit

Permalink
test: repro namespace_scopes compaction issue
Browse files Browse the repository at this point in the history
Co-Authored-By: Matt Valentine-House <matt@eightbitraptor.com>
Co-Authored-By: Peter Zhu <peter@peterzhu.ca>
  • Loading branch information
3 people committed Oct 16, 2022
1 parent 7b369e5 commit b08a858
Showing 1 changed file with 32 additions and 10 deletions.
42 changes: 32 additions & 10 deletions test/test_compaction.rb
Expand Up @@ -3,19 +3,41 @@
require "helper"

describe "compaction" do
it "https://github.com/sparklemotion/nokogiri/pull/2579" do
skip unless GC.respond_to?(:verify_compaction_references)
describe Nokogiri::XML::Node do
it "compacts safely" do # https://github.com/sparklemotion/nokogiri/pull/2579
skip unless GC.respond_to?(:verify_compaction_references)

big_doc = "<root>" + ("a".."zz").map { |x| "<#{x}>#{x}</#{x}>" }.join + "</root>"
doc = Nokogiri.XML(big_doc)
big_doc = "<root>" + ("a".."zz").map { |x| "<#{x}>#{x}</#{x}>" }.join + "</root>"
doc = Nokogiri.XML(big_doc)

# ensure a bunch of node objects have been wrapped
doc.root.children.each(&:inspect)
# ensure a bunch of node objects have been wrapped
doc.root.children.each(&:inspect)

# compact the heap and try to get the node wrappers to move
GC.verify_compaction_references(double_heap: true, toward: :empty)
# compact the heap and try to get the node wrappers to move
GC.verify_compaction_references(double_heap: true, toward: :empty)

# access the node wrappers and make sure they didn't move
doc.root.children.each(&:inspect)
# access the node wrappers and make sure they didn't move
doc.root.children.each(&:inspect)
end
end

describe Nokogiri::XML::Namespace do
it "namespace_scopes" do
skip unless GC.respond_to?(:verify_compaction_references)

doc = Nokogiri::XML(<<~EOF)
<root xmlns="http://example.com/root" xmlns:bar="http://example.com/bar">
<first/>
<second xmlns="http://example.com/child"/>
<third xmlns:foo="http://example.com/foo"/>
</root>
EOF

doc.at_xpath("//root:first", "root" => "http://example.com/root").namespace_scopes.inspect

GC.verify_compaction_references(double_heap: true, toward: :empty)

doc.at_xpath("//root:first", "root" => "http://example.com/root").namespace_scopes.inspect
end
end
end

0 comments on commit b08a858

Please sign in to comment.