Class: RSpec::Conductor::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/conductor/server.rb

Constant Summary collapse

MAX_SEED =
2**16

Instance Method Summary collapse

Constructor Details

#initialize(worker_count:, rspec_args:, **opts) ⇒ Server

Returns a new instance of Server.

Parameters:

  • worker_count (Hash)

    a customizable set of options

  • rspec_args (Hash)

    a customizable set of options

  • worker_number_offset (Hash)

    a customizable set of options

  • prefork_require (Hash)

    a customizable set of options

  • postfork_require (Hash)

    a customizable set of options

  • first_is_1 (Hash)

    a customizable set of options

  • seed (Hash)

    a customizable set of options

  • fail_fast_after (Hash)

    a customizable set of options

  • formatter (Hash)

    a customizable set of options

  • verbose (Hash)

    a customizable set of options

  • display_retry_backtraces (Hash)

    a customizable set of options

  • print_slowest_count (Hash)

    a customizable set of options

Options Hash (worker_count:):

  • How (Integer)

    many workers to spin

Options Hash (rspec_args:):

  • A (Array<String>)

    list of rspec options



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rspec/conductor/server.rb', line 20

def initialize(worker_count:, rspec_args:, **opts)
  @worker_count = worker_count
  @worker_number_offset = opts.fetch(:worker_number_offset, 0)
  @prefork_require = opts.fetch(:prefork_require, nil)
  @postfork_require = opts.fetch(:postfork_require, nil)
  @first_is_1 = opts.fetch(:first_is_1, Conductor.default_first_is_1?)
  @seed = opts[:seed] || (Random.new_seed % MAX_SEED)
  @fail_fast_after = opts[:fail_fast_after]
  @display_retry_backtraces = opts.fetch(:display_retry_backtraces, false)
  @print_slowest_count = opts.fetch(:print_slowest_count, nil)
  @verbose = opts.fetch(:verbose, false)

  @rspec_args = rspec_args
  @worker_processes = []
  @spec_queue = []
  @formatter_class = case opts[:formatter]
                     when "ci"
                       Formatters::CI
                     when "fancy"
                       Formatters::Fancy
                     when "plain"
                       Formatters::Plain
                     else
                       (!@verbose && Formatters::Fancy.recommended?) ? Formatters::Fancy : Formatters::Plain
                     end
  @formatter = @formatter_class.new(worker_count: @worker_count)
  @suite_run = SuiteRun.new

  $stdout.sync = true
  $stdin.echo = false if $stdin.tty?
  Dir.chdir(Conductor.root)
  ENV["PARALLEL_TEST_GROUPS"] = worker_count.to_s # parallel_tests backward-compatibility
end

Instance Method Details

#runObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/rspec/conductor/server.rb', line 54

def run
  setup_signal_handlers
  build_spec_queue
  preload_application

  @formatter.print_startup_banner(worker_count: @worker_count, seed: @seed, spec_files_count: @spec_queue.size)

  start_workers
  run_event_loop
  wait_for_workers_to_exit
  @suite_run.suite_complete

  @formatter.print_summary(@suite_run, seed: @seed, success: success?)
  @formatter.print_slowest(@suite_run, @print_slowest_count) if @print_slowest_count
  exit_with_status
end