Class: RSpecTurbo::Worker
- Inherits:
-
Object
- Object
- RSpecTurbo::Worker
- Defined in:
- lib/rspec_turbo/worker.rb
Overview
A single RSpec process running one batch of work. Worker.spawn forks the process and returns a Worker the executor tracks until the process exits.
Every worker is wired with two helper files shipped by the gem:
* progress_reporter.rb — a formatter that streams the example count to a
progress file so the parent can draw a global progress bar.
* slow_profile.rb — an opt-in profiler (RSPEC_PROFILE_SLOW=1) that
emits the "TOP N FILES BY TIME" block the report aggregates. It is a
no-op when profiling is disabled, so requiring it is always safe.
Constant Summary collapse
- PROGRESS_REPORTER_PATH =
File.("progress_reporter.rb", __dir__)
- SLOW_PROFILE_PATH =
File.("slow_profile.rb", __dir__)
Instance Attribute Summary collapse
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
-
#progress_file ⇒ Object
readonly
Returns the value of attribute progress_file.
-
#slot ⇒ Object
readonly
Returns the value of attribute slot.
-
#started ⇒ Object
readonly
Returns the value of attribute started.
-
#units ⇒ Object
readonly
Returns the value of attribute units.
Class Method Summary collapse
Instance Method Summary collapse
- #duration ⇒ Object
-
#initialize(pid:, label:, units:, slot:, started:, progress_file:) ⇒ Worker
constructor
A new instance of Worker.
Constructor Details
#initialize(pid:, label:, units:, slot:, started:, progress_file:) ⇒ Worker
Returns a new instance of Worker.
81 82 83 84 85 86 87 88 |
# File 'lib/rspec_turbo/worker.rb', line 81 def initialize(pid:, label:, units:, slot:, started:, progress_file:) @pid = pid @label = label @units = units @slot = slot @started = started @progress_file = progress_file end |
Instance Attribute Details
#label ⇒ Object (readonly)
Returns the value of attribute label.
19 20 21 |
# File 'lib/rspec_turbo/worker.rb', line 19 def label @label end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
19 20 21 |
# File 'lib/rspec_turbo/worker.rb', line 19 def pid @pid end |
#progress_file ⇒ Object (readonly)
Returns the value of attribute progress_file.
19 20 21 |
# File 'lib/rspec_turbo/worker.rb', line 19 def progress_file @progress_file end |
#slot ⇒ Object (readonly)
Returns the value of attribute slot.
19 20 21 |
# File 'lib/rspec_turbo/worker.rb', line 19 def slot @slot end |
#started ⇒ Object (readonly)
Returns the value of attribute started.
19 20 21 |
# File 'lib/rspec_turbo/worker.rb', line 19 def started @started end |
#units ⇒ Object (readonly)
Returns the value of attribute units.
19 20 21 |
# File 'lib/rspec_turbo/worker.rb', line 19 def units @units end |
Class Method Details
.spawn(label:, units:, slot:, rspec_options:) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rspec_turbo/worker.rb', line 21 def self.spawn(label:, units:, slot:, rspec_options:) started = Process.clock_gettime(Process::CLOCK_MONOTONIC) progress_file = Config.progress_path(slot) File.write(progress_file, "0") pid = Process.spawn( env(slot, progress_file), "bundle", "exec", "rspec", "--color", "--order", "random", "--require", PROGRESS_REPORTER_PATH, "--require", SLOW_PROFILE_PATH, "--format", "progress", "--format", "RSpecTurbo::ProgressReporter", *junit_args(slot), *, *rspec_args(units), out: Config.log_path(label), err: [:child, :out] ) new(pid: pid, label: label, units: units, slot: slot, started: started, progress_file: progress_file) end |
Instance Method Details
#duration ⇒ Object
90 |
# File 'lib/rspec_turbo/worker.rb', line 90 def duration = (Process.clock_gettime(Process::CLOCK_MONOTONIC) - @started).round |