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
# 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
  @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.



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

def close
  server.close
end

#runvoid

This method returns an undefined value.



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

def run
  until files_to_run.empty?
    rs, _ws, _es = IO.select([server])
    rs.each do |s|
      socket = s.accept
      method, _data = socket.gets.strip.split("\t", 2)
      case method
      when Protocol::POP
        path = files_to_run.pop
        RSpec::Parallel.configuration.logger.info("Deliver #{path}")
        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.



56
57
58
# File 'lib/rspec/parallel/master.rb', line 56

def socket_builder
  SocketBuilder.new(path)
end