Class: RSpec::MultiprocessRunner::Coordinator

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/multiprocess_runner/coordinator.rb

Instance Method Summary collapse

Constructor Details

#initialize(worker_count, files, options = {}) ⇒ Coordinator

Returns a new instance of Coordinator.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/rspec/multiprocess_runner/coordinator.rb', line 7

def initialize(worker_count, files, options={})
  @worker_count = worker_count
  @file_timeout_seconds = options[:file_timeout_seconds]
  @example_timeout_seconds = options[:example_timeout_seconds]
  @test_env_number_first_is_1 = options[:test_env_number_first_is_1]
  @log_failing_files = options[:log_failing_files]
  @rspec_options = options[:rspec_options]
  @spec_files = options[:use_given_order] ? files : sort_files(files)
  @workers = []
  @stopped_workers = []
end

Instance Method Details

#exit_codeObject



35
36
37
38
39
40
41
# File 'lib/rspec/multiprocess_runner/coordinator.rb', line 35

def exit_code
  exit_code = 0
  exit_code |= 1 if any_example_failed?
  exit_code |= 2 if !failed_workers.empty?
  exit_code |= 4 if !@spec_files.empty?
  exit_code
end

#failed?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/rspec/multiprocess_runner/coordinator.rb', line 31

def failed?
  0 < exit_code
end

#runObject



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rspec/multiprocess_runner/coordinator.rb', line 19

def run
  @start_time = Time.now
  expected_worker_numbers.each do |n|
    create_and_start_worker_if_necessary(n)
  end
  run_loop
  quit_all_workers
  print_summary

  exit_code
end

#shutdown(options = {}) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/rspec/multiprocess_runner/coordinator.rb', line 43

def shutdown(options={})
  if @shutting_down
    # Immediately kill the workers if shutdown is requested again
    end_workers_in_parallel(@workers.dup, :kill_now)
  else
    @shutting_down = true
    print "Shutting down #{pluralize(@workers.size, "worker")}" if options[:print_summary]
    # end_workers_in_parallel modifies @workers, so dup before sending in
    end_workers_in_parallel(@workers.dup, :shutdown_now)
    if options[:print_summary]
      puts " done"
      print_summary
    end
  end
end