Class: RSpec::Parallel::Master

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/parallel/master.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Master

Note:

RSpec must be configured ahead

Returns a new instance of Master.

Parameters:

  • args (Array<String>)

    command line arguments



18
19
20
21
22
23
24
# File 'lib/rspec/parallel/master.rb', line 18

def initialize(args)
  @args = args
  @path = "/tmp/parallel-rspec-#{$PID}.sock"
  @files_to_run = ::RSpec.configuration.files_to_run.uniq
  @total = @files_to_run.size
  @server = ::UNIXServer.new(@path)
end

Instance Attribute Details

#argsObject (readonly)

Parameters:

  • args (Array<String>)


14
15
16
# File 'lib/rspec/parallel/master.rb', line 14

def args
  @args
end

Instance Method Details

#closevoid

This method returns an undefined value.



27
28
29
# File 'lib/rspec/parallel/master.rb', line 27

def close
  server.close
end

#runvoid

This method returns an undefined value.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/rspec/parallel/master.rb', line 32

def run
  count = 1
  until files_to_run.empty?
    rs, _ws, _es = IO.select([server])
    rs.each do |s|
      socket = s.accept
      method, data = socket.gets.strip.split(" ", 2)
      case method
      when Protocol::POP
        path = files_to_run.pop
        RSpec::Parallel.configuration.logger.info("[#{count} / #{total}] Deliver #{path} to worker[#{data}]")
        count += 1
        socket.write(path)
      when Protocol::PING
        socket.write("ok")
      end
      socket.close
    end
  end
  close
  remove_socket_file
end

#socket_builderRSpec::Parallel::SocketBuilder

Create a socket builder which builds a socket to connect with the master process.



59
60
61
# File 'lib/rspec/parallel/master.rb', line 59

def socket_builder
  SocketBuilder.new(path)
end