class Knapsack::Tracker

Attributes

global_time[R]
test_files_with_time[R]
test_path[W]

Public Class Methods

new() click to toggle source
# File lib/knapsack/tracker.rb, line 8
def initialize
  set_defaults
end

Public Instance Methods

config(opts={}) click to toggle source
# File lib/knapsack/tracker.rb, line 12
def config(opts={})
  @config ||= default_config
  @config.merge!(opts)
end
exceeded_time() click to toggle source
# File lib/knapsack/tracker.rb, line 49
def exceeded_time
  global_time - max_node_time_execution
end
max_node_time_execution() click to toggle source
# File lib/knapsack/tracker.rb, line 45
def max_node_time_execution
  report_distributor.node_time_execution + config[:time_offset_in_seconds]
end
reset!() click to toggle source
# File lib/knapsack/tracker.rb, line 17
def reset!
  set_defaults
end
start_timer() click to toggle source
# File lib/knapsack/tracker.rb, line 21
def start_timer
  @start_time = now_without_mock_time.to_f
end
stop_timer() click to toggle source
# File lib/knapsack/tracker.rb, line 25
def stop_timer
  execution_time = now_without_mock_time.to_f - @start_time

  if test_path
    update_global_time(execution_time)
    update_test_file_time(execution_time)
    @test_path = nil
  end

  execution_time
end
test_path() click to toggle source
# File lib/knapsack/tracker.rb, line 37
def test_path
  @test_path.sub(/^\.\//, '') if @test_path
end
time_exceeded?() click to toggle source
# File lib/knapsack/tracker.rb, line 41
def time_exceeded?
  global_time > max_node_time_execution
end

Private Instance Methods

default_config() click to toggle source
# File lib/knapsack/tracker.rb, line 55
def default_config
  {
    enable_time_offset_warning: Config::Tracker.enable_time_offset_warning,
    time_offset_in_seconds: Config::Tracker.time_offset_in_seconds,
    generate_report: Config::Tracker.generate_report
  }
end
now_without_mock_time() click to toggle source
# File lib/knapsack/tracker.rb, line 87
def now_without_mock_time
  Process.clock_gettime(Process::CLOCK_MONOTONIC)
end
report_distributor() click to toggle source
# File lib/knapsack/tracker.rb, line 78
def report_distributor
  @report_distributor ||= Knapsack::Distributors::ReportDistributor.new({
    report: Knapsack.report.open,
    test_file_pattern: Knapsack::Config::Env.test_file_pattern || Knapsack.report.config[:test_file_pattern],
    ci_node_total: Knapsack::Config::Env.ci_node_total,
    ci_node_index: Knapsack::Config::Env.ci_node_index
  })
end
set_defaults() click to toggle source
# File lib/knapsack/tracker.rb, line 63
def set_defaults
  @global_time = 0
  @test_files_with_time = {}
  @test_path = nil
end
update_global_time(execution_time) click to toggle source
# File lib/knapsack/tracker.rb, line 69
def update_global_time(execution_time)
  @global_time += execution_time
end
update_test_file_time(execution_time) click to toggle source
# File lib/knapsack/tracker.rb, line 73
def update_test_file_time(execution_time)
  @test_files_with_time[test_path] ||= 0
  @test_files_with_time[test_path] += execution_time
end