class ParallelTests::Test::Runner

def sort_by_runtime(tests, runtimes, options={})

def sort_by_runtime(tests, runtimes, options={})
  allowed_missing = options[:allowed_missing] || 1.0
  allowed_missing = tests.size * allowed_missing
  # set know runtime for each test
  tests.sort!
  tests.map! do |test|
    allowed_missing -= 1 unless time = runtimes[test]
    if allowed_missing < 0
      log = options[:runtime_log] || runtime_log
      raise "Runtime log file '#{log}' does not cointain sufficient data to sort #{tests.size} test files, please update it."
    end
    [test, time]
  end
  if options[:verbose]
    puts "Runtime found for #{tests.count(&:last)} of #{tests.size} tests"
  end
  # fill gaps with unknown-runtime if given, average otherwise
  known, unknown = tests.partition(&:last)
  average = (known.any? ? known.map!(&:last).inject(:+) / known.size : 1)
  unknown_runtime = options[:unknown_runtime] || average
  unknown.each { |set| set[1] = unknown_runtime }
end