Class: ParallelTests::Grouper

Inherits:
Object
  • Object
show all
Defined in:
lib/parallel_tests/grouper.rb

Class Method Summary collapse

Class Method Details

.in_even_groups_by_size(items_with_sizes, num_groups, options = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/parallel_tests/grouper.rb', line 15

def self.in_even_groups_by_size(items_with_sizes, num_groups, options={})
  groups = Array.new(num_groups){{:items => [], :size => 0}}

  # add all files that should run in a single process to one group
  (options[:single_process]||[]).each do |pattern|
    matched, items_with_sizes = items_with_sizes.partition{|item, size| item =~ pattern }
    smallest = smallest_group(groups)
    matched.each{|item,size| add_to_group(smallest, item, size) }
  end

  # add all other files
  largest_first(items_with_sizes).each do |item, size|
    smallest = smallest_group(groups)
    add_to_group(smallest, item, size)
  end

  groups.map!{|g| g[:items].sort }
end

.in_groups(items, num_groups) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/parallel_tests/grouper.rb', line 3

def self.in_groups(items, num_groups)
  groups = Array.new(num_groups){ [] }

  until items.empty?
    num_groups.times do |group_number|
      groups[group_number] << items.shift
    end
  end

  groups.map!(&:sort!)
end

.largest_first(files) ⇒ Object



34
35
36
# File 'lib/parallel_tests/grouper.rb', line 34

def self.largest_first(files)
  files.sort_by{|item, size| size }.reverse
end