From cb36a562897c824617a932bbc31e1902237752f9 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Mon, 5 Apr 2021 12:33:37 -0400 Subject: [PATCH] ci: make some slow tests run only under NOKOGIRI_GC and speed a few other tests up. suite drops from ~22s to ~6s on my dev machine (with GC_LEVEL=minor). --- test/helper.rb | 2 +- test/xml/test_node.rb | 2 ++ test/xml/test_node_set.rb | 13 +++++++++---- test/xml/test_reader.rb | 4 ++-- test/xml/test_reader_encoding.rb | 1 + 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/test/helper.rb b/test/helper.rb index ad1597414a..4be9f82ac9 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -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)) diff --git a/test/xml/test_node.rb b/test/xml/test_node.rb index a1cd24392c..346e4b5f15 100644 --- a/test/xml/test_node.rb +++ b/test/xml/test_node.rb @@ -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 = "

BOOM!

" 10_000.times do node = Nokogiri::HTML::DocumentFragment.parse(message).at_css("h2") diff --git a/test/xml/test_node_set.rb b/test/xml/test_node_set.rb index 31af44efb5..3c76b1375d 100644 --- a/test/xml/test_node_set.rb +++ b/test/xml/test_node_set.rb @@ -889,13 +889,18 @@ def awesome!; end 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 diff --git a/test/xml/test_reader.rb b/test/xml/test_reader.rb index 750a634ec4..be9e19a6e6 100644 --- a/test/xml/test_reader.rb +++ b/test/xml/test_reader.rb @@ -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 "" wr.puts "" * 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" diff --git a/test/xml/test_reader_encoding.rb b/test/xml/test_reader_encoding.rb index a216c69862..1a2f9e9c96 100644 --- a/test/xml/test_reader_encoding.rb +++ b/test/xml/test_reader_encoding.rb @@ -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