* test/lib/minitest/unit.rb: Show leakes threads and tempfiles.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46089 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
bb64a96178
commit
0be4ec01cd
@ -1,3 +1,7 @@
|
|||||||
|
Sun May 25 09:40:44 2014 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* test/lib/minitest/unit.rb: Show leakes threads and tempfiles.
|
||||||
|
|
||||||
Sun May 25 08:54:38 2014 SHIBATA Hiroshi <shibata.hiroshi@gmail.com>
|
Sun May 25 08:54:38 2014 SHIBATA Hiroshi <shibata.hiroshi@gmail.com>
|
||||||
|
|
||||||
* test/openssl/test_partial_record_read.rb: Testing read_nonblock on
|
* test/openssl/test_partial_record_read.rb: Testing read_nonblock on
|
||||||
|
@ -927,6 +927,8 @@ module MiniTest
|
|||||||
inst = suite.new method
|
inst = suite.new method
|
||||||
inst._assertions = 0
|
inst._assertions = 0
|
||||||
|
|
||||||
|
live1 = live_thread_and_tempfile
|
||||||
|
|
||||||
print "#{suite}##{method} = " if @verbose
|
print "#{suite}##{method} = " if @verbose
|
||||||
|
|
||||||
start_time = Time.now if @verbose
|
start_time = Time.now if @verbose
|
||||||
@ -936,12 +938,45 @@ module MiniTest
|
|||||||
print result
|
print result
|
||||||
puts if @verbose
|
puts if @verbose
|
||||||
|
|
||||||
|
check_tempfile_and_thread inst, live1
|
||||||
|
|
||||||
inst._assertions
|
inst._assertions
|
||||||
}
|
}
|
||||||
|
|
||||||
return assertions.size, assertions.inject(0) { |sum, n| sum + n }
|
return assertions.size, assertions.inject(0) { |sum, n| sum + n }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def live_thread_and_tempfile
|
||||||
|
live_threads = ObjectSpace.each_object(Thread).find_all {|t|
|
||||||
|
t != Thread.current && t.alive?
|
||||||
|
}
|
||||||
|
if defined? Tempfile
|
||||||
|
live_tempfiles = ObjectSpace.each_object(Tempfile).find_all {|t|
|
||||||
|
t.path
|
||||||
|
}
|
||||||
|
else
|
||||||
|
live_tempfiles = []
|
||||||
|
end
|
||||||
|
[live_threads, live_tempfiles]
|
||||||
|
end
|
||||||
|
|
||||||
|
def check_tempfile_and_thread(inst, live1)
|
||||||
|
live2 = live_thread_and_tempfile
|
||||||
|
thread_finished = live1[0] - live2[0]
|
||||||
|
if !thread_finished.empty?
|
||||||
|
puts "Finished threads: #{inst.class}\##{inst.__name__}:#{thread_finished.map {|t| ' ' + t.inspect }.join}"
|
||||||
|
end
|
||||||
|
thread_retained = live2[0] - live1[0]
|
||||||
|
if !thread_retained.empty?
|
||||||
|
puts "Leaked threads: #{inst.class}\##{inst.__name__}:#{thread_retained.map {|t| ' ' + t.inspect }.join}"
|
||||||
|
end
|
||||||
|
tempfile_retained = live2[1] - live1[1]
|
||||||
|
if !tempfile_retained.empty?
|
||||||
|
puts "Leaked tempfiles: #{inst.class}\##{inst.__name__}:#{tempfile_retained.map {|t| ' ' + t.inspect }.join}"
|
||||||
|
tempfile_retained.each {|t| t.unlink }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# Record the result of a single test. Makes it very easy to gather
|
# Record the result of a single test. Makes it very easy to gather
|
||||||
# information. Eg:
|
# information. Eg:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user