Class: Minitest::Queue::Runner
- Inherits:
-
Object
- Object
- Minitest::Queue::Runner
- Includes:
- CI::Queue::OutputHelpers
- Defined in:
- lib/minitest/queue/runner.rb
Constant Summary collapse
- Error =
Class.new(StandardError)
- MissingParameter =
Class.new(Error)
Class Method Summary collapse
Instance Method Summary collapse
- #bisect_command ⇒ Object
-
#initialize(argv) ⇒ Runner
constructor
A new instance of Runner.
- #report_command ⇒ Object
- #retry_command ⇒ Object
- #run! ⇒ Object
- #run_command ⇒ Object
Constructor Details
#initialize(argv) ⇒ Runner
Returns a new instance of Runner.
19 20 21 22 |
# File 'lib/minitest/queue/runner.rb', line 19 def initialize(argv) @queue_config = CI::Queue::Configuration.from_env(ENV) @command, @argv = parse(argv) end |
Class Method Details
.invoke(argv) ⇒ Object
15 16 17 |
# File 'lib/minitest/queue/runner.rb', line 15 def self.invoke(argv) new(argv).run! end |
Instance Method Details
#bisect_command ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/minitest/queue/runner.rb', line 53 def bisect_command invalid_usage! "Missing the FAILING_TEST argument." unless queue_config.failing_test @queue = CI::Queue::Bisect.new(queue_url, queue_config) Minitest.queue = queue set_load_path load_tests populate_queue step("Testing the failing test in isolation") unless run_tests_in_fork(queue.failing_test) puts reopen_previous_step puts red("The test fail when ran alone, no need to bisect.") exit! 0 end run_index = 0 while queue.suspects_left > 1 run_index += 1 step("Run ##{run_index}, #{queue.suspects_left} suspects left") if run_tests_in_fork(queue.candidates) queue.succeeded! else queue.failed! end puts end failing_order = queue.candidates step("Final validation") status = if run_tests_in_fork(failing_order) step(yellow("The bisection was inconclusive, there might not be any leaky test here.")) exit! 1 else step(green('The following command should reproduce the leak on your machine:'), collapsed: false) command = %w(bundle exec minitest-queue --queue - run) command << "-I#{load_paths}" if load_paths command += argv puts puts "cat <<EOF |\n#{failing_order.to_a.map(&:id).join("\n")}\nEOF\n#{command.join(' ')}" puts exit! 0 end end |
#report_command ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/minitest/queue/runner.rb', line 99 def report_command supervisor = begin queue.supervisor rescue NotImplementedError => error abort! error. end step("Waiting for workers to complete") unless supervisor.wait_for_workers unless supervisor.queue_initialized? abort! "No master was elected. Did all workers crash?" end unless supervisor.exhausted? abort! "#{supervisor.size} tests weren't run." end end success = supervisor.minitest_reporters.all?(&:success?) supervisor.minitest_reporters.each do |reporter| reporter.report end exit! success ? 0 : 1 end |
#retry_command ⇒ Object
38 39 40 41 |
# File 'lib/minitest/queue/runner.rb', line 38 def retry_command self.queue = queue.retry_queue run_command end |
#run! ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/minitest/queue/runner.rb', line 24 def run! invalid_usage!("No command given") if command.nil? invalid_usage!('Missing queue URL') unless queue_url @queue = CI::Queue.from_uri(queue_url, queue_config) method = "#{command}_command" if respond_to?(method) public_send(method) else invalid_usage!("Unknown command: #{command}") end end |