Repository: puma/puma
File: test/helper.rb (Ruby)

Code before:
          end
        end

        capture_exceptions do
          ::Timeout.timeout($test_case_timeout, TestTookTooLong) do
            Minitest::Test::TEARDOWN_METHODS.each { |hook| self.send hook }
          end
        end
        if respond_to? :clean_tmp_paths
          clean_tmp_paths
        end
      end
    end

    Minitest::Result.from self # per contract
  end
end

Minitest::Test.prepend TimeoutEveryTestCase

if ENV['CI']
  require 'minitest/retry'

  SUMMARY_FILE = ENV['GITHUB_STEP_SUMMARY']

  Minitest::Retry.use!

  if SUMMARY_FILE && ENV['GITHUB_ACTIONS'] == 'true'

    GITHUB_STEP_SUMMARY_MUTEX = Mutex.new

    Minitest::Retry.on_failure do |klass, test_name, result|
      full_method = "#{klass}##{test_name}"
      result_str = result.to_s.gsub(/#{full_method}:?\s*/, '').dup
      result_str.gsub!(/\A(Failure:|Error:)\s/, '\1 ')
      issue = result_str[/\A[^\n]+/]
      result_str.gsub!(issue, '')
      # shorten directory lists
      result_str.gsub! ENV['GITHUB_WORKSPACE'], 'puma'
      result_str.gsub! ENV['RUNNER_TOOL_CACHE'], ''
      # remove indent
      result_str.gsub!(/^ +/, '')
      str = "\n**#{full_method}**\n**#{issue}**\n```\n#{result_str.strip}\n```\n"
      GITHUB_STEP_SUMMARY_MUTEX.synchronize {
        File.write SUMMARY_FILE, str, mode: 'a+'
      }
    end
  end
end

module TestSkips

Review comment (refactor):
This doesn't make sense to me. You shouldn't be calling with_info_handler... and you prolly shouldn't be overriding run like this, let alone having to duplicate all of its code. Instead, override [Minitest::Runnable.run_one_method](https://github.com/minitest/minitest/blob/master/lib/minitest.rb#L444) and you don't need ANY of this boilerplate. Should look something like this:

```ruby
def run_one_method klass, method_name, reporter
  ::Timeout.timeout($test_case_timeout, TestTookTooLong) do
    super
  end
ensure
  clean_tmp_paths if respond_to? :clean_tmp_paths
end
```

because it is a class method, you'll prolly have to `extend` rather than `include`... I would make it a subclass of Runnable and subclass it. Happy to provide a PR if you want to see it in full.

Code after:
              before_setup; setup; after_setup
              self.send self.name
            end
          end

          capture_exceptions do
            ::Timeout.timeout($test_case_timeout, TestTookTooLong) do
              Minitest::Test::TEARDOWN_METHODS.each { |hook| self.send hook }
            end
          end
          if respond_to? :clean_tmp_paths
            clean_tmp_paths
          end
        end
      end

      Minitest::Result.from self # per contract
    end
  end
else
  module TimeoutEveryTestCase
    # our own subclass so we never confuse different timeouts
    class TestTookTooLong < Timeout::Error
    end

    def run
      time_it do
        capture_exceptions do
          ::Timeout.timeout($test_case_timeout, TestTookTooLong) do
            Minitest::Test::SETUP_METHODS.each { |hook| self.send hook }
            self.send self.name
          end
        end

        capture_exceptions do
          ::Timeout.timeout($test_case_timeout, TestTookTooLong) do
            Minitest::Test::TEARDOWN_METHODS.each { |hook| self.send hook }
          end
        end
        if respond_to? :clean_tmp_paths
          clean_tmp_paths
        end
      end

      Minitest::Result.from self # per contract
    end
  end
end

Minitest::Test.prepend TimeoutEveryTestCase