Class: RSpec::Parallel::Worker::Iterator

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/rspec/parallel/worker.rb

Instance Method Summary collapse

Constructor Details

#initialize(worker, socket_builder) ⇒ Iterator

Returns a new instance of Iterator.

Parameters:



34
35
36
37
# File 'lib/rspec/parallel/worker.rb', line 34

def initialize(worker, socket_builder)
  @worker = worker
  @socket_builder = socket_builder
end

Instance Method Details

#each {|RSpec::Core::ExampleGroup| ... } ⇒ Object

Yields:

  • (RSpec::Core::ExampleGroup)


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# 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

#pingvoid

This method returns an undefined value.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# 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