Sha256: abaa2cd040c53d53a685cf79a2b1ff636f72ea738ecbe997653c6be92ff75825

Contents?: true

Size: 1.17 KB

Versions: 36

Compression:

Stored size: 1.17 KB

Contents

require 'rubygems'

module Testbot::Server

  class Group

    DEFAULT = nil

    def self.build(files, sizes, instance_count, type)
      tests_with_sizes = slow_tests_first(map_files_and_sizes(files, sizes))

      groups = []
      current_group, current_size = 0, 0
      tests_with_sizes.each do |test, size|
        # inserts into next group if current is full and we are not in the last group
        if (0.5*size + current_size) > group_size(tests_with_sizes, instance_count) and instance_count > current_group + 1
          current_size = size
          current_group += 1
        else
          current_size += size
        end
        groups[current_group] ||= []
        groups[current_group] << test
      end

      groups.compact
    end

    private

    def self.group_size(tests_with_sizes, group_count)
      total = tests_with_sizes.inject(0) { |sum, test| sum += test[1] }
      total / group_count.to_f
    end

    def self.map_files_and_sizes(files, sizes)
      list = []
      files.each_with_index { |file, i| list << [ file, sizes[i] ] }
      list
    end

    def self.slow_tests_first(tests)
      tests.sort_by { |test, time| time.to_i }.reverse
    end

  end

end

Version data entries

36 entries across 36 versions & 2 rubygems

Version Path
testbot-0.7.12 lib/server/group.rb
testbot-0.7.11 lib/server/group.rb
testbot-0.7.9 lib/server/group.rb
testbot_instructure-0.7.9 lib/server/group.rb
testbot_instructure-0.7.8 lib/server/group.rb
testbot-0.7.8 lib/server/group.rb
testbot-0.7.7 lib/server/group.rb
testbot-0.7.6 lib/server/group.rb
testbot-0.7.5 lib/server/group.rb
testbot-0.7.3 lib/server/group.rb
testbot-0.7.2 lib/server/group.rb
testbot-0.7.1 lib/server/group.rb
testbot-0.7.0 lib/server/group.rb
testbot-0.6.9 lib/server/group.rb
testbot-0.6.8 lib/server/group.rb
testbot-0.6.7 lib/server/group.rb
testbot-0.6.6 lib/server/group.rb
testbot-0.6.5 lib/server/group.rb
testbot-0.6.4 lib/server/group.rb
testbot-0.6.3 lib/server/group.rb