Sha256: 6c0354d365e35c08b25ac6c1748fc7be9b335aacf24b283bfc5ead5fc6f4b5ad
Contents?: true
Size: 1.33 KB
Versions: 2
Compression:
Stored size: 1.33 KB
Contents
# TestDiff module module TestDiff # estimates and prints how long it will take to empty a queue class TimingTracker def self.run(queue, &block) new(queue).run(&block) end def initialize(queue) @queue = queue @original_size = queue_size end def run @start_time = Time.now thread = start_timing_thread yield thread.kill end private def queue_size @queue.size end def queue_completed @original_size - queue_size end def seconds_elapsed (Time.now - @start_time).to_f end def start_timing_thread Thread.new do begin do_timing rescue => e puts "----- Timing failed: #{e.message} -----" end end end def do_timing puts "Timing #{@original_size} specs" until queue_empty? current_size = queue_size current_completed = queue_completed if current_completed > 5 time_per_spec = seconds_elapsed / current_completed.to_f est_time_left = time_per_spec * current_size puts "specs left #{current_size}, est time_left: #{est_time_left.to_i}" else puts "specs left #{current_size}, est time_left: N/A" end sleep(30) end end def queue_empty? @queue.empty? end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
test_diff-0.4.1 | lib/test_diff/timing_tracker.rb |
test_diff-0.4.0 | lib/test_diff/timing_tracker.rb |