Skip to content

Commit

Permalink
More logging
Browse files Browse the repository at this point in the history
  • Loading branch information
adfoster-r7 committed Sep 14, 2023
1 parent 69c907f commit cf926aa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Use in a context to clean up the constants that are created by the module loader.
RSpec.shared_context 'Metasploit::Framework::Spec::Constants cleaner' do
after(:example) do
$stderr.puts "cleaning constants"
Metasploit::Framework::Spec::Constants.clean
$stderr.puts "constants cleaned"
end
end
end
11 changes: 11 additions & 0 deletions spec/support/shared/contexts/msf/framework/threads/cleaner.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
RSpec.shared_context 'Msf::Framework#threads cleaner' do |options = {}|
after(:example) do |example|
$stderr.puts "starting to kill threads"
if options.fetch(:verify_cleanup_required, true) && !framework.threads?
fail RuntimeError.new(
"framework.threads was never initialized. There are no threads to clean up. " \
Expand All @@ -11,14 +12,24 @@
# explicitly kill threads so that they don't exhaust connection pool
thread_manager = framework.threads

$stderr.puts "starting to kill threads"
thread_manager.each do |thread|
puts "-----------------------------------------------------"
thread_deets = "thread=#{thread} - name=#{thread[:tm_name]} --- backtrace=#{thread.backtrace ? thread.backtrace.join("\n") : 'no backtrace'} ---"
$stderr.puts "killing thread #{thread_deets}"
thread.kill
$stderr.puts "Waiting to join"
# ensure killed thread is cleaned up by VM
thread.join
$stderr.puts "Joined on thread"
$stderr.puts
end

$stderr.puts "Killing thread manager monitor"
thread_manager.monitor.kill
# ensure killed thread is cleaned up by VM
$stderr.puts "Joining killed thread monitor"
thread_manager.monitor.join
$stderr.puts "successfully joined thread monitor"
end
end
2 changes: 2 additions & 0 deletions spec/support/shared/contexts/msf/simple/framework.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
end

after(:example) do
$stderr.puts "before cleaning framework path"
FileUtils.rm_rf(dummy_pathname)
$stderr.puts "after cleaning framework path"
end
end

0 comments on commit cf926aa

Please sign in to comment.