Skip to content

Commit

Permalink
ci: make some slow tests run only under NOKOGIRI_GC
Browse files Browse the repository at this point in the history
and speed a few other tests up. suite drops from ~22s to ~6s on my dev
machine (with GC_LEVEL=minor).
  • Loading branch information
flavorjones committed Apr 5, 2021
1 parent beb77f5 commit cb36a56
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

require 'minitest/autorun'
require 'minitest/reporters'
NOKOGIRI_MINITEST_REPORTERS_OPTIONS = { color: true, slow_count: 5, detailed_skip: false }
NOKOGIRI_MINITEST_REPORTERS_OPTIONS = { color: true, slow_count: 10, detailed_skip: false }
NOKOGIRI_MINITEST_REPORTERS_OPTIONS[:fast_fail] = true if ENV["NOKOGIRI_TEST_FAIL_FAST"]
puts "Minitest::Reporters options: #{NOKOGIRI_MINITEST_REPORTERS_OPTIONS}"
Minitest::Reporters.use!(Minitest::Reporters::DefaultReporter.new(NOKOGIRI_MINITEST_REPORTERS_OPTIONS))
Expand Down
2 changes: 2 additions & 0 deletions test/xml/test_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1197,9 +1197,11 @@ def test_set_node_lang
end

def test_text_node_robustness_gh1426
skip("only run if NOKOGIRI_GC is set") unless ENV['NOKOGIRI_GC']
skip("No need to test libxml-ruby workarounds on JRuby") if Nokogiri.jruby?
# notably, the original bug report was about libxml-ruby interactions
# this test should blow up under valgrind if we regress on libxml-ruby workarounds
# side note: this was fixed in libxml-ruby 2.9.0 by https://github.com/xml4r/libxml-ruby/pull/119
message = "<section><h2>BOOM!</h2></section>"
10_000.times do
node = Nokogiri::HTML::DocumentFragment.parse(message).at_css("h2")
Expand Down
13 changes: 9 additions & 4 deletions test/xml/test_node_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -889,13 +889,18 @@ def awesome!; end
<?xml version="1.0" encoding="UTF-8"?>
<container></container>
EOF

# proc that returns Nodes but allows the Documents to be GCed
scope = lambda do
Nokogiri::XML::Document.parse(xml).css("container") + Nokogiri::XML::Document.parse(xml).css("container")
end
stress_memory_while do
node_set = scope.call
node_set.to_s
end
node_set = scope.call

# kick off major GC
GC.start

# see if everything's still there
node_set.to_s
end

it "should handle this case just fine" do
Expand Down
4 changes: 2 additions & 2 deletions test/xml/test_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ def test_reader_blocking
end
rd.close
end
sleep(1) # sleep for one second to make sure the reader will actually block for input
sleep(0.1) # sleep to make sure the reader will actually block for input
begin
wr.puts "<foo>"
wr.puts "<bar/>" * 10000
wr.flush
rescue Errno::EPIPE
end
res = t.join(5) # wait 5 seconds for the thread to finish
res = t.join(1) # give the thread a moment to finish
wr.close
refute_nil node_out, "Didn't read any nodes, exclude the trivial case"
refute_nil res, "Reader blocks trying to read the entire stream"
Expand Down
1 change: 1 addition & 0 deletions test/xml/test_reader_encoding.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def test_name
end

def test_value_lookup_segfault
skip("only run if NOKOGIRI_GC is set") unless ENV['NOKOGIRI_GC']
skip("JRuby doesn't do GC.") if Nokogiri.jruby?
stress_memory_while do
while node = @reader.read
Expand Down

0 comments on commit cb36a56

Please sign in to comment.