Class: Quickdraw::Run
- Inherits:
-
Object
- Object
- Quickdraw::Run
- Defined in:
- lib/quickdraw/run.rb
Instance Method Summary collapse
- #call ⇒ Object
- #fork_processes ⇒ Object
-
#initialize(number_of_processes:, number_of_threads: 1, test_files:) ⇒ Run
constructor
A new instance of Run.
- #puts_results ⇒ Object
- #report_time ⇒ Object
Constructor Details
#initialize(number_of_processes:, number_of_threads: 1, test_files:) ⇒ Run
Returns a new instance of Run.
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/quickdraw/run.rb', line 4 def initialize(number_of_processes:, number_of_threads: 1, test_files:) @number_of_processes = number_of_processes @number_of_threads = number_of_threads @test_files = test_files.shuffle @cluster = Quickdraw::Cluster.new @batches = Array.new(@number_of_processes) { Quickdraw::Queue.new } @test_files.each_with_index do |file, index| @batches[index % @number_of_processes] << file end end |
Instance Method Details
#call ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/quickdraw/run.rb', line 17 def call report_time do fork_processes @results = @cluster.wait puts_results end end |
#fork_processes ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/quickdraw/run.rb', line 30 def fork_processes # Enable YJIT right before forking RubyVM::YJIT.enable @batches.each_with_index do |batch, index| @cluster.fork do |writer| results = @number_of_threads.times.map do Thread.new { Quickdraw::Runner.call(batch) } end.map(&:value) results.each_with_index do |result, thread| writer.write("\n") writer.write("Process[#{index + 1}], Thread[#{thread + 1}]: #{result.successes.count} assertions passed in #{result.duration}. #{Quickdraw::SUCCESS_EMOJI.sample}") end end end end |
#puts_results ⇒ Object
48 49 50 51 52 |
# File 'lib/quickdraw/run.rb', line 48 def puts_results puts puts puts "Collated results: \n#{@results.join("\n")}" end |