class RSpec::Parallel::Worker::Iterator
Attributes
socket_builder[R]
@return [RSpec::Parallel::SocketBuilder]
worker[R]
@return [RSpec::Parallel::Worker]
Public Class Methods
new(worker, socket_builder)
click to toggle source
@param worker [RSpec::Parallel::Worker] @param socket_builder
[RSpec::Parallel::SocketBuilder]
# File lib/rspec/parallel/worker.rb, line 34 def initialize(worker, socket_builder) @worker = worker @socket_builder = socket_builder end
Public Instance Methods
each() { |example_group| ... }
click to toggle source
@yield [RSpec::Core::ExampleGroup]
# File lib/rspec/parallel/worker.rb, line 59 def each loop do socket = connect_to_distributor break if socket.nil? RSpec::Parallel.configuration.logger.debug("Send POP request") socket.puts("#{Protocol::POP} #{worker.number}") # TODO: Rescue `Broken pipe (Errno::EPIPE)` error _, _, es = IO.select([socket], nil, [socket]) unless es.empty? RSpec::Parallel.configuration.logger.error("Socket error occurs") break end path = socket.read(65_536) socket.close RSpec.world.example_groups.clear RSpec::Parallel.configuration.logger.debug("Load #{path}") Kernel.load path RSpec.world.example_groups.each do |example_group| yield example_group end end end
ping()
click to toggle source
@return [void]
# File lib/rspec/parallel/worker.rb, line 40 def ping loop do socket = connect_to_distributor if socket.nil? RSpec::Parallel.configuration.logger.debug("Sleep a little to wait master process") sleep 0.5 next end RSpec::Parallel.configuration.logger.debug("Send PING request") socket.puts(Protocol::PING) # TODO: handle socket error and check pong message IO.select([socket]) socket.read(65_536) socket.close break end end
Private Instance Methods
connect_to_distributor()
click to toggle source
@return [BasicSocket, nil]
# File lib/rspec/parallel/worker.rb, line 90 def connect_to_distributor socket_builder.run end