Class: RSpec::Conductor::WorkerProcess
- Inherits:
-
Object
- Object
- RSpec::Conductor::WorkerProcess
- Defined in:
- lib/rspec/conductor/worker_process.rb
Instance Attribute Summary collapse
-
#child_process ⇒ Object
Returns the value of attribute child_process.
-
#current_spec ⇒ Object
Returns the value of attribute current_spec.
-
#number ⇒ Object
readonly
Returns the value of attribute number.
-
#status ⇒ Object
Returns the value of attribute status.
Class Method Summary collapse
- .spawn(number:, test_env_number:, on_message:, on_stdout: nil, on_stderr: nil, **worker_init_args) ⇒ Object
- .tick_all(worker_processes) ⇒ Object
- .wait_all(worker_processes) ⇒ Object
Instance Method Summary collapse
- #eql?(other) ⇒ Boolean
- #handle_message ⇒ Object
- #hash ⇒ Object
-
#initialize(number:, on_message: nil) ⇒ WorkerProcess
constructor
A new instance of WorkerProcess.
- #pid ⇒ Object
- #receive_message ⇒ Object
- #running? ⇒ Boolean
- #send_message(message) ⇒ Object
- #shut_down(status) ⇒ Object
- #socket ⇒ Object
Constructor Details
#initialize(number:, on_message: nil) ⇒ WorkerProcess
Returns a new instance of WorkerProcess.
33 34 35 36 37 |
# File 'lib/rspec/conductor/worker_process.rb', line 33 def initialize(number:, on_message: nil) @number = number @on_message = @status = :running end |
Instance Attribute Details
#child_process ⇒ Object
Returns the value of attribute child_process.
31 32 33 |
# File 'lib/rspec/conductor/worker_process.rb', line 31 def child_process @child_process end |
#current_spec ⇒ Object
Returns the value of attribute current_spec.
31 32 33 |
# File 'lib/rspec/conductor/worker_process.rb', line 31 def current_spec @current_spec end |
#number ⇒ Object (readonly)
Returns the value of attribute number.
30 31 32 |
# File 'lib/rspec/conductor/worker_process.rb', line 30 def number @number end |
#status ⇒ Object
Returns the value of attribute status.
31 32 33 |
# File 'lib/rspec/conductor/worker_process.rb', line 31 def status @status end |
Class Method Details
.spawn(number:, test_env_number:, on_message:, on_stdout: nil, on_stderr: nil, **worker_init_args) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/rspec/conductor/worker_process.rb', line 6 def self.spawn(number:, test_env_number:, on_message:, on_stdout: nil, on_stderr: nil, **worker_init_args) worker_process = new(number: number, on_message: ) child_process = Util::ChildProcess.fork(on_stdout: on_stdout, on_stderr: on_stderr, on_message: proc { worker_process. }) do |_, child_socket| ENV["TEST_ENV_NUMBER"] = test_env_number Worker.new( worker_number: number, socket: Protocol::Socket.new(child_socket), **worker_init_args ).run end worker_process.child_process = child_process worker_process end |
.tick_all(worker_processes) ⇒ Object
22 23 24 |
# File 'lib/rspec/conductor/worker_process.rb', line 22 def self.tick_all(worker_processes) Util::ChildProcess.tick_all(worker_processes.map(&:child_process)) end |
.wait_all(worker_processes) ⇒ Object
26 27 28 |
# File 'lib/rspec/conductor/worker_process.rb', line 26 def self.wait_all(worker_processes) Util::ChildProcess.wait_all(worker_processes.map(&:child_process)) end |
Instance Method Details
#eql?(other) ⇒ Boolean
79 80 81 |
# File 'lib/rspec/conductor/worker_process.rb', line 79 def eql?(other) other.is_a?(self.class) && other.number == number end |
#handle_message ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/rspec/conductor/worker_process.rb', line 39 def = unless socket.close return end @on_message&.call(self, ) end |
#hash ⇒ Object
75 76 77 |
# File 'lib/rspec/conductor/worker_process.rb', line 75 def hash [number].hash end |
#pid ⇒ Object
61 62 63 |
# File 'lib/rspec/conductor/worker_process.rb', line 61 def pid child_process.pid end |
#receive_message ⇒ Object
53 54 55 |
# File 'lib/rspec/conductor/worker_process.rb', line 53 def socket. end |
#running? ⇒ Boolean
71 72 73 |
# File 'lib/rspec/conductor/worker_process.rb', line 71 def running? status == :running end |
#send_message(message) ⇒ Object
49 50 51 |
# File 'lib/rspec/conductor/worker_process.rb', line 49 def () socket.() end |
#shut_down(status) ⇒ Object
65 66 67 68 69 |
# File 'lib/rspec/conductor/worker_process.rb', line 65 def shut_down(status) return unless running? @status = status end |