Fail before suite if more than 1 thread exists
MSP-11147 Detect thread leaks in a `before(:suite)` configured by `Metasploit::Framework::Spec::Threads::Suite.configure!` and fail if any leaks are found.bug/bundler_fix
parent
cca30b536f
commit
96990fdc02
|
@ -32,6 +32,10 @@ module Metasploit
|
|||
# works in compatible manner with activerecord's rake tasks and other
|
||||
# railties.
|
||||
module Framework
|
||||
extend ActiveSupport::Autoload
|
||||
|
||||
autoload :Spec
|
||||
|
||||
# Returns the root of the metasploit-framework project. Use in place of
|
||||
# `Rails.root`.
|
||||
#
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
module Metasploit::Framework::Spec
|
||||
extend ActiveSupport::Autoload
|
||||
|
||||
autoload :Threads
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
module Metasploit::Framework::Spec::Threads
|
||||
extend ActiveSupport::Autoload
|
||||
|
||||
autoload :Suite
|
||||
end
|
|
@ -0,0 +1,35 @@
|
|||
module Metasploit::Framework::Spec::Threads::Suite
|
||||
#
|
||||
# CONSTANTS
|
||||
#
|
||||
|
||||
EXPECTED_THREAD_COUNT_BEFORE_SUITE = 1
|
||||
|
||||
#
|
||||
# Module Methods
|
||||
#
|
||||
|
||||
# Configures `before(:suite)` and `after(:suite)` callback to detect thread leaks.
|
||||
#
|
||||
# @return [void]
|
||||
def self.configure!
|
||||
unless @configured
|
||||
RSpec.configure do |config|
|
||||
config.before(:suite) do
|
||||
thread_count = Thread.list.count
|
||||
|
||||
expect(thread_count).to(
|
||||
(be <= EXPECTED_THREAD_COUNT_BEFORE_SUITE),
|
||||
"#{thread_count} #{'thread'.pluralize(thread_count)} exist(s) when " \
|
||||
"only #{EXPECTED_THREAD_COUNT_BEFORE_SUITE} #{'thread'.pluralize(EXPECTED_THREAD_COUNT_BEFORE_SUITE)} " \
|
||||
"expected before suite runs"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
@configured = true
|
||||
end
|
||||
|
||||
@configured
|
||||
end
|
||||
end
|
|
@ -55,3 +55,5 @@ RSpec.configure do |config|
|
|||
# instead of true.
|
||||
config.use_transactional_fixtures = true
|
||||
end
|
||||
|
||||
Metasploit::Framework::Spec::Threads::Suite.configure!
|
||||
|
|
Loading…
Reference in New Issue