1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
# frozen_string_literal: true
require File.expand_path('helper', __dir__)
class TestGcCompact < Test::Unit::TestCase
ITERATIONS = (ENV['CURB_GC_COMPACT_ITERATIONS'] || 5).to_i
EASY_PER_MULTI = 3
def setup
omit('GC.compact unavailable on this Ruby') unless defined?(GC.compact)
end
def test_multi_perform_with_gc_compact
ITERATIONS.times do
multi = Curl::Multi.new
add_easy_handles(multi)
compact
assert_nothing_raised { multi.perform }
compact
end
end
def test_gc_compact_during_multi_cleanup
ITERATIONS.times do
multi = Curl::Multi.new
add_easy_handles(multi)
compact
multi = nil
compact
end
end
def test_gc_compact_after_detach
multi = Curl::Multi.new
handles = add_easy_handles(multi)
compact
assert_nothing_raised { multi.perform }
handles.each { |easy| multi.remove(easy) }
compact
end
private
def add_easy_handles(multi)
Array.new(EASY_PER_MULTI) do
Curl::Easy.new($TEST_URL) do |easy|
easy.timeout = 5
easy.on_complete { |_e| }
easy.on_failure { |_e, _code| }
end.tap { |easy| multi.add(easy) }
end
end
def compact
GC.compact
end
end
|