Class: Binpacker::Orchestrator

Inherits:
Object
  • Object
show all
Defined in:
lib/binpacker/orchestrator.rb

Instance Method Summary collapse

Constructor Details

#initialize(config, passthrough: []) ⇒ Orchestrator

Returns a new instance of Orchestrator.



5
6
7
8
# File 'lib/binpacker/orchestrator.rb', line 5

def initialize(config, passthrough: [])
  @config = config
  @passthrough = passthrough
end

Instance Method Details

#runObject



10
11
12
13
14
15
16
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
50
51
52
53
54
55
56
57
58
# File 'lib/binpacker/orchestrator.rb', line 10

def run
  tests = discover

  timing = Timing.new(@config.timing_file)
  timings = timing.load_with_fallback(tests)

  scheduler = Scheduler.for(@config.scheduler["algorithm"])
  queues = scheduler.partition(
    tests: tests,
    worker_count: @config.worker_count,
    timings: timings
  )

  runner_class = TestRunner.for(@config.test_runner)
  workers = queues.map.with_index do |queue, idx|
    Worker.new(idx, runner_class, passthrough: @passthrough).tap(&:start)
  end

  workers.zip(queues).each do |worker, queue|
    worker.send_tests(queue.remaining)
  end

  all_timings = []
  all_passed = true
  total_examples = 0
  passed_examples = 0

  workers.each do |worker|
    worker.finish
    all_timings.concat(worker.timings)
    all_passed &&= worker.success?
    total_examples += worker.example_count
    passed_examples += worker.passed_count
  rescue WorkerError => e
    $stderr.puts "worker #{worker.id} error: #{e.message}"
    all_passed = false
  ensure
    worker.cleanup
  end

  timing.append_all(all_timings) unless all_timings.empty?

  {
    passed: all_passed,
    total: total_examples,
    passed_count: passed_examples,
    timings: all_timings
  }
end