Class: RSpec::Distrib::Worker::RSpecRunner

Inherits:
Core::Runner
  • Object
show all
Includes:
DistribCore::Worker
Defined in:
lib/rspec/distrib/worker/rspec_runner.rb

Overview

Modified RSpec runner to consume files from the leader

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(leader) ⇒ RSpecRunner

Returns a new instance of RSpecRunner.

Parameters:

  • leader (DRbObject)

See Also:

  • Core::Runner#initialize


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/rspec/distrib/worker/rspec_runner.rb', line 33

def initialize(leader) # rubocop:disable Metrics/MethodLength
  @success = true
  @leader = leader
  @seed = connect_to_leader_with_timeout { leader.seed }

  handle_configuration_failure do
    @options = RSpec::Core::ConfigurationOptions.new(["--seed=#{@seed}"])
    # as long as there is this assignment to global variable
    # the test have to restore RSpec.configuration after the example
    # see `around` block in spec/rspec/distrib/worker/rspec_runner_spec.rb
    @configuration = RSpec.configuration = RSpec::Distrib::Worker::Configuration.new
    @configuration.leader = leader
    init_formatters
    @world = RSpec.world
    setup($stdout, $stderr)
  end
end

Class Method Details

.run_from_leader(leader_ip) ⇒ Object

Public method that invokes the runner.

Parameters:

  • leader_ip (String)


26
27
28
29
# File 'lib/rspec/distrib/worker/rspec_runner.rb', line 26

def self.run_from_leader(leader_ip)
  leader = DRbObject.new_with_uri(Leader::DRB_SERVER_URL % leader_ip)
  new(leader).run
end

Instance Method Details

#runObject

Note:

Originally it makes setup and runs specs. We patch this method to consume from the leader, instead of the given example_groups param.

See Also:

  • Core::Runner#run
  • Core::Runner#run_specs


58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/rspec/distrib/worker/rspec_runner.rb', line 58

def run(*) # rubocop:disable Metrics/MethodLength
  handle_configuration_failure do
    @configuration.reporter.report(Leader::FAKE_TOTAL_EXAMPLES_COUNT) do |reporter|
      @configuration.with_suite_hooks do
        # Disable handler since consume_queue has it's own handler
        @handle_configuration_failure = false
        consume_queue(reporter)
      end
    end
  end
  persist_example_statuses

  return ::DistribCore::ReceivedSignals.exit_code if received_any_signal?

  success && !world.non_example_failure ? 0 : @configuration.failure_exit_code
end