tool/lib/leakchecker.rb: show the code location that allocated leaked fd
by using ObjectSpace.trace_object_allocations. `make test-all LEAK_CHECKER_TRACE_OBJECT_ALLOCATION=true` will print not only leaked fds but also where it was created.
This commit is contained in:
parent
b72eda3c59
commit
c02de30efb
@ -75,9 +75,13 @@ class LeakChecker
|
|||||||
}
|
}
|
||||||
fd_leaked.each {|fd|
|
fd_leaked.each {|fd|
|
||||||
str = ''.dup
|
str = ''.dup
|
||||||
|
pos = nil
|
||||||
if h[fd]
|
if h[fd]
|
||||||
str << ' :'
|
str << ' :'
|
||||||
h[fd].map {|io, autoclose, inspect|
|
h[fd].map {|io, autoclose, inspect|
|
||||||
|
if ENV["LEAK_CHECKER_TRACE_OBJECT_ALLOCATION"]
|
||||||
|
pos = "#{ObjectSpace.allocation_sourcefile(io)}:#{ObjectSpace.allocation_sourceline(io)}"
|
||||||
|
end
|
||||||
s = ' ' + inspect
|
s = ' ' + inspect
|
||||||
s << "(not-autoclose)" if !autoclose
|
s << "(not-autoclose)" if !autoclose
|
||||||
s
|
s
|
||||||
@ -86,6 +90,7 @@ class LeakChecker
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
puts "Leaked file descriptor: #{test_name}: #{fd}#{str}"
|
puts "Leaked file descriptor: #{test_name}: #{fd}#{str}"
|
||||||
|
puts " The IO was created at #{pos}" if pos
|
||||||
}
|
}
|
||||||
#system("lsof -p #$$") if !fd_leaked.empty?
|
#system("lsof -p #$$") if !fd_leaked.empty?
|
||||||
h.each {|fd, list|
|
h.each {|fd, list|
|
||||||
|
@ -941,6 +941,7 @@ module MiniTest
|
|||||||
|
|
||||||
leakchecker = LeakChecker.new
|
leakchecker = LeakChecker.new
|
||||||
|
|
||||||
|
continuation = proc do
|
||||||
assertions = filtered_test_methods.map { |method|
|
assertions = filtered_test_methods.map { |method|
|
||||||
inst = suite.new method
|
inst = suite.new method
|
||||||
inst._assertions = 0
|
inst._assertions = 0
|
||||||
@ -961,10 +962,17 @@ module MiniTest
|
|||||||
|
|
||||||
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
|
||||||
|
|
||||||
|
if ENV["LEAK_CHECKER_TRACE_OBJECT_ALLOCATION"]
|
||||||
|
require "objspace"
|
||||||
|
ObjectSpace.trace_object_allocations(&continuation)
|
||||||
|
else
|
||||||
|
continuation.call
|
||||||
|
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