Module: RSpec::Signal::ParallelRun
- Defined in:
- lib/rspec/signal/parallel_run.rb
Overview
Filesystem protocol shared by parallel_tests workers and the parent merger.
Constant Summary collapse
- RUN_ID =
"RSPEC_SIGNAL_RUN_ID"- REGISTRY =
"RSPEC_SIGNAL_RUN_REGISTRY"
Class Method Summary collapse
- .atomic_write(path, contents) ⇒ Object
- .configuration_h(config) ⇒ Object
- .register(path) ⇒ Object
- .worker? ⇒ Boolean
- .worker_id ⇒ Object
- .write_worker(report, config) ⇒ Object
Class Method Details
.atomic_write(path, contents) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/rspec/signal/parallel_run.rb', line 47 def atomic_write(path, contents) temporary = "#{path}.#{Process.pid}.tmp" File.write(temporary, contents) File.rename(temporary, path) ensure FileUtils.rm_f(temporary) if defined?(temporary) end |
.configuration_h(config) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/rspec/signal/parallel_run.rb', line 34 def configuration_h(config) %i[output_dir project_root max_frames max_external_context max_project_frames fallback_frames max_message_lines max_diff_lines reduce_html max_html_chars max_affected_examples max_groups relate_failures max_clusters max_cluster_specs write_json write_full write_gitignore terminal_summary capture_capybara capture_page_html].to_h { |name| [name, config.public_send(name)] } end |
.register(path) ⇒ Object
41 42 43 44 45 |
# File 'lib/rspec/signal/parallel_run.rb', line 41 def register(path) registry = ENV.fetch(REGISTRY) FileUtils.mkdir_p(registry) atomic_write(File.join(registry, "#{worker_id}.path"), "#{path}\n") end |
.worker? ⇒ Boolean
15 16 17 |
# File 'lib/rspec/signal/parallel_run.rb', line 15 def worker? !ENV[RUN_ID].to_s.empty? && ENV.key?("TEST_ENV_NUMBER") end |
.worker_id ⇒ Object
19 20 21 22 |
# File 'lib/rspec/signal/parallel_run.rb', line 19 def worker_id value = ENV.fetch("TEST_ENV_NUMBER", "").to_s value.empty? ? "1" : value end |
.write_worker(report, config) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/rspec/signal/parallel_run.rb', line 24 def write_worker(report, config) directory = File.join(config.output_path, "workers", ENV.fetch(RUN_ID), worker_id) FileUtils.mkdir_p(directory) path = File.join(directory, "signal.json") payload = report.worker_h(write_full: config.write_full) .merge(worker: worker_id, configuration: configuration_h(config)) atomic_write(path, "#{JSON.pretty_generate(payload)}\n") register(path) end |