lib/rspec/parallel/worker.rb in parallel-rspec-0.1.0 vs lib/rspec/parallel/worker.rb in parallel-rspec-0.1.1
- old
+ new
@@ -7,14 +7,14 @@
attr_reader :number
# @param master [RSpec::Parallel::Master]
# @param number [Integer]
def initialize(master, number)
- RSpec::Parallel.configuration.logger.info("Initialize Iterator")
- @iterator = Iterator.new(master.socket_builder)
+ RSpec::Parallel.configuration.logger.debug("Initialize Iterator")
+ @iterator = Iterator.new(self, master.socket_builder)
@number = number
- RSpec::Parallel.configuration.logger.info("Initialize SpecRunner")
+ RSpec::Parallel.configuration.logger.debug("Initialize SpecRunner")
@spec_runner = SpecRunner.new(master.args)
end
# @return [void]
def run
@@ -27,25 +27,27 @@
attr_reader :iterator, :spec_runner
class Iterator
include Enumerable
+ # @param worker [RSpec::Parallel::Worker]
# @param socket_builder [RSpec::Parallel::SocketBuilder]
- def initialize(socket_builder)
+ def initialize(worker, socket_builder)
+ @worker = worker
@socket_builder = socket_builder
end
# @return [void]
def ping
loop do
socket = connect_to_distributor
if socket.nil?
- RSpec::Parallel.configuration.logger.info("Sleep a little to wait master process")
+ RSpec::Parallel.configuration.logger.debug("Sleep a little to wait master process")
sleep 0.5
next
end
- RSpec::Parallel.configuration.logger.info("Send PING request")
+ 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
@@ -56,21 +58,21 @@
# @yield [RSpec::Core::ExampleGroup]
def each
loop do
socket = connect_to_distributor
break if socket.nil?
- RSpec::Parallel.configuration.logger.info("Send POP request")
- socket.puts(Protocol::POP)
+ 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.info("Load #{path}")
+ RSpec::Parallel.configuration.logger.debug("Load #{path}")
Kernel.load path
RSpec.world.example_groups.each do |example_group|
yield example_group
end
end
@@ -79,10 +81,13 @@
private
# @return [RSpec::Parallel::SocketBuilder]
attr_reader :socket_builder
+ # @return [RSpec::Parallel::Worker]
+ attr_reader :worker
+
# @return [BasicSocket, nil]
def connect_to_distributor
socket_builder.run
end
end
@@ -100,12 +105,16 @@
# Reset filter manager to run all specs. Just for simplicity
# TODO: Support config.run_all_when_everything_filtered = true
@configuration.filter_manager = RSpec::Core::FilterManager.new
success = @configuration.reporter.report(0) do |reporter|
+ # In genaral, ExampleGroup is configured by evaluating `describe`
+ # before `with_suite_hooks`
+ RSpec::Core::ExampleGroup.ensure_example_groups_are_configured
+
@configuration.with_suite_hooks do
example_groups.map do |g|
- RSpec::Parallel.configuration.logger.info("Run #{g.inspect}")
+ RSpec::Parallel.configuration.logger.debug("Run #{g.inspect}")
g.run(reporter)
end.all?
end
end && !@world.non_example_failure