Class: RSpec::MultiprocessRunner::FileCoordinator
- Inherits:
-
Object
- Object
- RSpec::MultiprocessRunner::FileCoordinator
- Defined in:
- lib/rspec/multiprocess_runner/file_coordinator.rb
Constant Summary collapse
- COMMAND_FILE =
"file"- COMMAND_RESULTS =
"results"- COMMAND_PROCESS =
"process"- COMMAND_FINISHED =
"finished"- COMMAND_START =
"start"
Instance Attribute Summary collapse
-
#failed_workers ⇒ Object
readonly
Returns the value of attribute failed_workers.
-
#options ⇒ Object
Returns the value of attribute options.
-
#results ⇒ Object
readonly
Returns the value of attribute results.
Instance Method Summary collapse
- #finished ⇒ Object
- #get_file ⇒ Object
-
#initialize(files, options = {}) ⇒ FileCoordinator
constructor
A new instance of FileCoordinator.
- #missing_files ⇒ Object
- #remaining_files ⇒ Object
- #send_results(results) ⇒ Object
- #send_worker_status(worker) ⇒ Object
Constructor Details
#initialize(files, options = {}) ⇒ FileCoordinator
Returns a new instance of FileCoordinator.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rspec/multiprocess_runner/file_coordinator.rb', line 17 def initialize(files, ={}) @spec_files = [] @results = Set.new @threads = [] @failed_workers = [] self. = @spec_files_reference = files.to_set if .head_node @spec_files = .use_given_order ? files : sort_files(files) Thread.start { run_tcp_server } @node_socket, head_node_socket = Socket.pair(:UNIX, :STREAM) Thread.start { server_connection_established(head_node_socket) } else count = 100 while @node_socket.nil? do begin @node_socket = TCPSocket.new .hostname, .port raise unless start? rescue BadStartStringError @node_socket.close if @node_socket raise rescue @node_socket.close if @node_socket @node_socket = nil raise if count < 0 count -= 1 sleep(6) end end puts end ObjectSpace.define_finalizer( self, proc { @node_socket.close } ) end |
Instance Attribute Details
#failed_workers ⇒ Object (readonly)
Returns the value of attribute failed_workers.
8 9 10 |
# File 'lib/rspec/multiprocess_runner/file_coordinator.rb', line 8 def failed_workers @failed_workers end |
#options ⇒ Object
Returns the value of attribute options.
9 10 11 |
# File 'lib/rspec/multiprocess_runner/file_coordinator.rb', line 9 def end |
#results ⇒ Object (readonly)
Returns the value of attribute results.
8 9 10 |
# File 'lib/rspec/multiprocess_runner/file_coordinator.rb', line 8 def results @results end |
Instance Method Details
#finished ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/rspec/multiprocess_runner/file_coordinator.rb', line 85 def finished if .head_node if @tcp_server_running @tcp_server_running = false @threads.each(&:join) @spec_files += missing_files.to_a end else @node_socket.puts [COMMAND_FINISHED].to_json end end |
#get_file ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/rspec/multiprocess_runner/file_coordinator.rb', line 63 def get_file begin @node_socket.puts [COMMAND_FILE].to_json file = @node_socket.gets.chomp if @spec_files_reference.include? file return file else return nil # Malformed response, assume done, cease function end rescue return nil # If Error, assume done, cease function end end |
#missing_files ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/rspec/multiprocess_runner/file_coordinator.rb', line 55 def missing_files if .head_node @spec_files_reference - @results.map(&:filename) - @failed_workers.map(&:current_file) - @spec_files else [] end end |
#remaining_files ⇒ Object
51 52 53 |
# File 'lib/rspec/multiprocess_runner/file_coordinator.rb', line 51 def remaining_files @spec_files end |
#send_results(results) ⇒ Object
77 78 79 |
# File 'lib/rspec/multiprocess_runner/file_coordinator.rb', line 77 def send_results(results) @node_socket.puts [COMMAND_RESULTS, results].to_json end |
#send_worker_status(worker) ⇒ Object
81 82 83 |
# File 'lib/rspec/multiprocess_runner/file_coordinator.rb', line 81 def send_worker_status(worker) @node_socket.puts [COMMAND_PROCESS, worker, Socket.gethostname].to_json end |