parallel_tests 0.3.7 → 0.3.8

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.7
1
+ 0.3.8
@@ -2,9 +2,6 @@ require File.join(File.dirname(__FILE__), 'parallel_tests')
2
2
 
3
3
  class ParallelSpecs < ParallelTests
4
4
  def self.run_tests(test_files, process_number, options)
5
- spec_opts = ['spec/parallel_spec.opts', 'spec/spec.opts'].detect{|f| File.file?(f) }
6
- spec_opts = (spec_opts ? "-O #{spec_opts}" : nil)
7
- color = ($stdout.tty? ? 'RSPEC_COLOR=1 ; export RSPEC_COLOR ;' : '')#display color when we are in a terminal
8
5
  cmd = "RAILS_ENV=test ; export RAILS_ENV ; #{color} #{executable} #{options} #{spec_opts} #{test_files*' '}"
9
6
  execute_command(cmd, process_number)
10
7
  end
@@ -21,6 +18,16 @@ class ParallelSpecs < ParallelTests
21
18
 
22
19
  protected
23
20
 
21
+ def self.spec_opts
22
+ opts = ['spec/parallel_spec.opts', 'spec/spec.opts'].detect{|f| File.file?(f) }
23
+ opts ? "-O #{opts}" : nil
24
+ end
25
+
26
+ #display color when we are in a terminal
27
+ def self.color
28
+ ($stdout.tty? ? 'RSPEC_COLOR=1 ; export RSPEC_COLOR ;' : '')
29
+ end
30
+
24
31
  def self.test_suffix
25
32
  "_spec.rb"
26
33
  end
@@ -4,7 +4,7 @@ class ParallelTests
4
4
  VERSION = File.read( File.join(File.dirname(__FILE__),'..','VERSION') ).strip
5
5
 
6
6
  # parallel:spec[2,controller] <-> parallel:spec[controller]
7
- def self.parse_rake_args (args)
7
+ def self.parse_rake_args(args)
8
8
  num_processes = Parallel.processor_count
9
9
  options = ""
10
10
  if args[:count].to_s =~ /^\d*$/ # number or empty
@@ -19,18 +19,11 @@ class ParallelTests
19
19
 
20
20
  # finds all tests and partitions them into groups
21
21
  def self.tests_in_groups(root, num, options={})
22
- tests_with_sizes = find_tests_with_sizes(root)
23
- tests_with_sizes = slow_specs_first(tests_with_sizes) unless options[:no_sort]
24
-
25
- # always add to smallest group
26
- groups = Array.new(num){{:tests => [], :size => 0}}
27
- tests_with_sizes.each do |test, size|
28
- smallest = groups.sort_by{|g| g[:size] }.first
29
- smallest[:tests] << test
30
- smallest[:size] += size
22
+ if options[:no_sort] == true
23
+ distribute_tests_in_groups(root, num)
24
+ else
25
+ sorted_tests_in_groups(root, num)
31
26
  end
32
-
33
- groups.map{|g| g[:tests] }
34
27
  end
35
28
 
36
29
  def self.run_tests(test_files, process_number, options)
@@ -71,6 +64,36 @@ class ParallelTests
71
64
 
72
65
  protected
73
66
 
67
+
68
+ def self.sorted_tests_in_groups(root, num)
69
+ # always add to smallest group
70
+ groups = Array.new(num){{:tests => [], :size => 0}}
71
+ tests_with_sizes(root).each do |test, size|
72
+ smallest = groups.sort_by{|g| g[:size] }.first
73
+ smallest[:tests] << test
74
+ smallest[:size] += size
75
+ end
76
+
77
+ groups.map{|g| g[:tests] }
78
+ end
79
+
80
+ def self.distribute_tests_in_groups(root, num)
81
+ tests = find_tests(root)
82
+ [].tap do |groups|
83
+ while ! tests.empty?
84
+ (0...num).map do |group_number|
85
+ groups[group_number] ||= []
86
+ groups[group_number] << tests.shift
87
+ end
88
+ end
89
+ end
90
+ end
91
+
92
+ def self.tests_with_sizes(root)
93
+ tests_with_sizes = find_tests_with_sizes(root)
94
+ slow_specs_first(tests_with_sizes)
95
+ end
96
+
74
97
  def self.slow_specs_first(tests)
75
98
  tests.sort_by{|test, size| size }.reverse
76
99
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{parallel_tests}
8
- s.version = "0.3.7"
8
+ s.version = "0.3.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Michael Grosser"]
12
- s.date = %q{2010-05-15}
12
+ s.date = %q{2010-05-17}
13
13
  s.email = %q{grosser.michael@gmail.com}
14
14
  s.executables = ["parallel_spec", "parallel_cucumber", "parallel_test"]
15
15
  s.extra_rdoc_files = [
data/spec/spec_helper.rb CHANGED
@@ -70,5 +70,13 @@ def test_tests_in_groups(klass, folder, suffix)
70
70
  # 7 + 6 + 4 + 2 = 19
71
71
  groups[1].should == [@files[7],@files[6],@files[4],@files[2]]
72
72
  end
73
+
74
+ it "partitions by round-robin when not sorting" do
75
+ files = ["file1.rb", "file2.rb", "file3.rb", "file4.rb"]
76
+ klass.should_receive(:find_tests).and_return(files)
77
+ groups = klass.tests_in_groups(files, 2, :no_sort => true)
78
+ groups[0].should == ["file1.rb", "file3.rb"]
79
+ groups[1].should == ["file2.rb", "file4.rb"]
80
+ end
73
81
  end
74
82
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 7
9
- version: 0.3.7
8
+ - 8
9
+ version: 0.3.8
10
10
  platform: ruby
11
11
  authors:
12
12
  - Michael Grosser
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-05-15 00:00:00 +02:00
17
+ date: 2010-05-17 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency