Repository: rails/rails
File: activesupport/lib/active_support/testing/parallelization/worker.rb (Ruby)

Code before:
        def safe_record(reporter, result)
          add_setup_exception(result) if @setup_exception

          begin
            @queue.record(reporter, result)
          rescue DRb::DRbConnError
            result.failures.map! do |failure|
              if failure.respond_to?(:error)
                # minitest >5.14.0
                error = DRb::DRbRemoteError.new(failure.error)
              else
                error = DRb::DRbRemoteError.new(failure.exception)
              end
              Minitest::UnexpectedError.new(error)
            end
            @queue.record(reporter, result)
          rescue Interrupt
            @queue.interrupt
            raise
          end

          set_process_title("(idle)")
        end

        def after_fork
          ActiveSupport::TestCase.parallel_worker_id = @number if defined?(ActiveSupport::TestCase)
          Parallelization.after_fork_hooks.each do |cb|
            cb.call(@number)
          end
        end

        def run_cleanup
          Parallelization.run_cleanup_hooks.each do |cb|
            cb.call(@number)
          end
        end

        private
          def add_setup_exception(result)
            result.failures.prepend Minitest::UnexpectedError.new(@setup_exception)
          end

          def set_process_title(status)
            Process.setproctitle("Rails test worker #{@number} - #{status}")
          end
      end
    end
  end
end


Review comment (suggestion):
Hrm, when is `ActiveSupport::TestCase` not defined?

Also style nit, add a new line after this.

```suggestion
          ActiveSupport::TestCase.parallel_worker_id = @number if defined?(ActiveSupport::TestCase)
          
```

Code after:
        def safe_record(reporter, result)
          add_setup_exception(result) if @setup_exception

          begin
            @queue.record(reporter, result)
          rescue DRb::DRbConnError
            result.failures.map! do |failure|
              if failure.respond_to?(:error)
                # minitest >5.14.0
                error = DRb::DRbRemoteError.new(failure.error)
              else
                error = DRb::DRbRemoteError.new(failure.exception)
              end
              Minitest::UnexpectedError.new(error)
            end
            @queue.record(reporter, result)
          rescue Interrupt
            @queue.interrupt
            raise
          end

          set_process_title("(idle)")
        end

        def after_fork
          ActiveSupport::TestCase.parallel_worker_id = @number

          Parallelization.after_fork_hooks.each do |cb|
            cb.call(@number)
          end
        end

        def run_cleanup
          Parallelization.run_cleanup_hooks.each do |cb|
            cb.call(@number)
          end
        end

        private
          def add_setup_exception(result)
            result.failures.prepend Minitest::UnexpectedError.new(@setup_exception)
          end

          def set_process_title(status)
            Process.setproctitle("Rails test worker #{@number} - #{status}")
          end
      end
    end
  end
end