Class: RSpec::Signal::ParallelMerger

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/signal/parallel_merger.rb

Overview

Rehydrates worker JSON and performs grouping once, over the complete run.

Defined Under Namespace

Classes: Result

Instance Method Summary collapse

Constructor Details

#initialize(registry:, config: RSpec::Signal.configuration) ⇒ ParallelMerger

Returns a new instance of ParallelMerger.



12
13
14
15
# File 'lib/rspec/signal/parallel_merger.rb', line 12

def initialize(registry:, config: RSpec::Signal.configuration)
  @registry = registry
  @config = config
end

Instance Method Details

#callObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rspec/signal/parallel_merger.rb', line 17

def call
  paths = Dir[File.join(@registry, "*.path")].map { |file| File.read(file).strip }
  documents, missing = paths.partition { |path| File.file?(path) }
  payloads = documents.map { |path| JSON.parse(File.read(path)) }
  validate_configuration!(payloads)
  apply_configuration(payloads.first&.fetch("configuration", {}) || {})
  report = aggregate(payloads)
  result = Result.new(
    report: report,
    workers: payloads.size,
    missing: missing,
    write_result: Writer.new(@config).write(report)
  )
  # Only once we have successfully produced a report: a worker JSON that
  # failed to parse should stay on disk for a human to look at, not be
  # deleted along with everything else.
  cleanup_worker_artifacts(paths)
  result
end