123456789_123456789_123456789_123456789_123456789_

Class: ActiveSupport::Testing::ParallelizeExecutor

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: activesupport/lib/active_support/testing/parallelize_executor.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(size:, with:, threshold: ActiveSupport.test_parallelization_threshold) ⇒ ParallelizeExecutor

[ GitHub ]

  
# File 'activesupport/lib/active_support/testing/parallelize_executor.rb', line 8

def initialize(size:, with:, threshold: ActiveSupport.test_parallelization_threshold)
  @size = size
  @parallelize_with = with
  @threshold = threshold
  @parallelized = false
end

Instance Attribute Details

#many_workers?Boolean (readonly, private)

[ GitHub ]

  
# File 'activesupport/lib/active_support/testing/parallelize_executor.rb', line 60

def many_workers?
  size > 1
end

#parallelize_with (readonly)

[ GitHub ]

  
# File 'activesupport/lib/active_support/testing/parallelize_executor.rb', line 6

attr_reader :size, :parallelize_with, :threshold

#parallelized?Boolean (readonly, private)

[ GitHub ]

  
# File 'activesupport/lib/active_support/testing/parallelize_executor.rb', line 52

def parallelized?
  @parallelized
end

#should_parallelize?Boolean (readonly, private)

[ GitHub ]

  
# File 'activesupport/lib/active_support/testing/parallelize_executor.rb', line 56

def should_parallelize?
  (ENV["PARALLEL_WORKERS"] || tests_count > threshold) && many_workers?
end

#size (readonly)

[ GitHub ]

  
# File 'activesupport/lib/active_support/testing/parallelize_executor.rb', line 6

attr_reader :size, :parallelize_with, :threshold

#threshold (readonly)

[ GitHub ]

  
# File 'activesupport/lib/active_support/testing/parallelize_executor.rb', line 6

attr_reader :size, :parallelize_with, :threshold

Instance Method Details

#<<(work)

[ GitHub ]

  
# File 'activesupport/lib/active_support/testing/parallelize_executor.rb', line 22

def <<(work)
  parallel_executor << work if parallelized?
end

#build_parallel_executor (private)

[ GitHub ]

  
# File 'activesupport/lib/active_support/testing/parallelize_executor.rb', line 35

def build_parallel_executor
  case parallelize_with
  when :processes
    Testing::Parallelization.new(size)
  when :threads
    ActiveSupport::TestCase.lock_threads = false if defined?(ActiveSupport::TestCase.lock_threads)
    Minitest::Parallel::Executor.new(size)
  else
    raise ArgumentError, "#{parallelize_with} is not a supported parallelization executor."
  end
end

#execution_info (private)

[ GitHub ]

  
# File 'activesupport/lib/active_support/testing/parallelize_executor.rb', line 72

def execution_info
  if parallelized?
    "Running #{tests_count} tests in parallel using #{parallel_executor.size} #{parallelize_with}"
  elsif many_workers?
    "Running #{tests_count} tests in a single process (parallelization threshold is #{threshold})"
  end
end

#parallel_executor (private)

[ GitHub ]

  
# File 'activesupport/lib/active_support/testing/parallelize_executor.rb', line 31

def parallel_executor
  @parallel_executor ||= build_parallel_executor
end

#parallelize (private)

[ GitHub ]

  
# File 'activesupport/lib/active_support/testing/parallelize_executor.rb', line 47

def parallelize
  @parallelized = true
  Minitest::Test.parallelize_me!
end

#show_execution_info (private)

[ GitHub ]

  
# File 'activesupport/lib/active_support/testing/parallelize_executor.rb', line 68

def show_execution_info
  puts execution_info
end

#shutdown

[ GitHub ]

  
# File 'activesupport/lib/active_support/testing/parallelize_executor.rb', line 26

def shutdown
  parallel_executor.shutdown if parallelized?
end

#start

[ GitHub ]

  
# File 'activesupport/lib/active_support/testing/parallelize_executor.rb', line 15

def start
  parallelize if should_parallelize?
  show_execution_info

  parallel_executor.start if parallelized?
end

#tests_count (private)

[ GitHub ]

  
# File 'activesupport/lib/active_support/testing/parallelize_executor.rb', line 64

def tests_count
  @tests_count ||= Minitest::Runnable.runnables.sum { |runnable| runnable.runnable_methods.size }
end