Class: ParallelTests::Grouper

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

Class Method Summary collapse

Class Method Details

.by_scenarios(tests, num_groups, options = {}) ⇒ Object



10
11
12
13
# File 'lib/parallel_tests/grouper.rb', line 10

def by_scenarios(tests, num_groups, options = {})
  scenarios = group_by_scenarios(tests, options)
  in_even_groups_by_size(scenarios, num_groups)
end

.by_steps(tests, num_groups, options) ⇒ Object



5
6
7
8
# File 'lib/parallel_tests/grouper.rb', line 5

def by_steps(tests, num_groups, options)
  features_with_steps = group_by_features_with_steps(tests, options)
  in_even_groups_by_size(features_with_steps, num_groups)
end

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



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/parallel_tests/grouper.rb', line 15

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

  return specify_groups(items, num_groups, options, groups) if options[:specify_groups]

  # add all files that should run in a single process to one group
  single_process_patterns = options[:single_process] || []

  single_items, items = items.partition do |item, _size|
    single_process_patterns.any? { |pattern| item =~ pattern }
  end

  isolate_count = isolate_count(options)

  if isolate_count >= num_groups
    raise 'Number of isolated processes must be >= total number of processes'
  end

  if isolate_count >= 1
    # add all files that should run in a multiple isolated processes to their own groups
    group_features_by_size(items_to_group(single_items), groups[0..(isolate_count - 1)])
    # group the non-isolated by size
    group_features_by_size(items_to_group(items), groups[isolate_count..])
  else
    # add all files that should run in a single non-isolated process to first group
    single_items.each { |item, size| add_to_group(groups.first, item, size) }

    # group all by size
    group_features_by_size(items_to_group(items), groups)
  end

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