moxiesoft_parallel_tests 0.4.13 → 0.6.18

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
- require 'spec/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe ParallelTests do
4
4
  test_tests_in_groups(ParallelTests, 'test', '_test.rb')
@@ -14,38 +14,49 @@ describe ParallelTests do
14
14
  ParallelTests.parse_rake_args(args).should == [Parallel.processor_count, "models", ""]
15
15
  end
16
16
 
17
- it "should return the count and prefix" do
18
- args = {:count => 2, :path_prefix => "models"}
17
+ it "should return the count and pattern" do
18
+ args = {:count => 2, :pattern => "models"}
19
19
  ParallelTests.parse_rake_args(args).should == [2, "models", ""]
20
20
  end
21
21
 
22
- it "should return the count, prefix, and options" do
23
- args = {:count => 2, :path_prefix => "plain", :options => "-p default" }
22
+ it "should return the count, pattern, and options" do
23
+ args = {:count => 2, :pattern => "plain", :options => "-p default" }
24
24
  ParallelTests.parse_rake_args(args).should == [2, "plain", "-p default"]
25
25
  end
26
+
27
+ it "should use the PARALLEL_TEST_PROCESSORS env var for processor_count if set" do
28
+ ENV['PARALLEL_TEST_PROCESSORS'] = '28'
29
+ ParallelTests.parse_rake_args({}).should == [28, '', '']
30
+ end
31
+
32
+ it "should use count over PARALLEL_TEST_PROCESSORS env var" do
33
+ ENV['PARALLEL_TEST_PROCESSORS'] = '28'
34
+ args = {:count => 2}
35
+ ParallelTests.parse_rake_args(args).should == [2, '', ""]
36
+ end
26
37
  end
27
38
 
28
39
  describe :run_tests do
29
40
  it "uses TEST_ENV_NUMBER=blank when called for process 0" do
30
41
  ParallelTests.should_receive(:open).with{|x,y|x=~/TEST_ENV_NUMBER= /}.and_return mocked_process
31
- ParallelTests.run_tests(['xxx'],0,'')
42
+ ParallelTests.run_tests(['xxx'],0,{})
32
43
  end
33
44
 
34
45
  it "uses TEST_ENV_NUMBER=2 when called for process 1" do
35
46
  ParallelTests.should_receive(:open).with{|x,y| x=~/TEST_ENV_NUMBER=2/}.and_return mocked_process
36
- ParallelTests.run_tests(['xxx'],1,'')
47
+ ParallelTests.run_tests(['xxx'],1,{})
37
48
  end
38
49
 
39
50
  it "uses options" do
40
- ParallelTests.should_receive(:open).with{|x,y| x=~ %r{ruby -Itest -v}}.and_return mocked_process
41
- ParallelTests.run_tests(['xxx'],1,'-v')
51
+ ParallelTests.should_receive(:open).with{|x,y| x=~ %r{ruby -Itest .* -- -v}}.and_return mocked_process
52
+ ParallelTests.run_tests(['xxx'],1,:test_options => '-v')
42
53
  end
43
54
 
44
55
  it "returns the output" do
45
56
  io = open('spec/spec_helper.rb')
46
57
  ParallelTests.stub!(:print)
47
58
  ParallelTests.should_receive(:open).and_return io
48
- ParallelTests.run_tests(['xxx'],1,'')[:stdout].should =~ /\$LOAD_PATH << File/
59
+ ParallelTests.run_tests(['xxx'],1,{})[:stdout].should =~ /\$LOAD_PATH << File/
49
60
  end
50
61
  end
51
62
 
@@ -57,9 +68,15 @@ describe ParallelTests do
57
68
 
58
69
  it "does sort when not passed do_sort option" do
59
70
  ParallelTests.stub!(:tests_with_runtime).and_return([])
60
- ParallelTests::Grouper.should_receive(:smallest_first).and_return([])
71
+ ParallelTests::Grouper.should_receive(:largest_first).and_return([])
61
72
  ParallelTests.tests_in_groups [], 1
62
73
  end
74
+
75
+ it "groups by single_process pattern and then via size" do
76
+ ParallelTests.should_receive(:with_runtime_info).and_return([['aaa',5],['aaa2',5],['bbb',2],['ccc',1],['ddd',1]])
77
+ result = ParallelTests.tests_in_groups [], 3, :single_process => [/^a.a/]
78
+ result.should == [["aaa", "aaa2"], ["bbb"], ["ccc", "ddd"]]
79
+ end
63
80
  end
64
81
 
65
82
  describe :find_results do
@@ -83,7 +100,7 @@ EOF
83
100
  ParallelTests.find_results(output).should == ['10 tests, 20 assertions, 0 failures, 0 errors','14 tests, 20 assertions, 0 failures, 0 errors']
84
101
  end
85
102
 
86
- it "is robust against scrambeled output" do
103
+ it "is robust against scrambled output" do
87
104
  output = <<EOF
88
105
  Loaded suite /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake/rake_test_loader
89
106
  Started
@@ -136,7 +153,77 @@ EOF
136
153
  end
137
154
  end
138
155
 
156
+ describe :find_tests do
157
+ it "returns if root is an array" do
158
+ ParallelTests.send(:find_tests, [1]).should == [1]
159
+ end
160
+
161
+ it "finds all test files" do
162
+ begin
163
+ root = "/tmp/test-find_tests-#{rand(999)}"
164
+ `mkdir #{root}`
165
+ `mkdir #{root}/a`
166
+ `mkdir #{root}/b`
167
+ `touch #{root}/x_test.rb`
168
+ `touch #{root}/a/x_test.rb`
169
+ `touch #{root}/a/test.rb`
170
+ `touch #{root}/b/y_test.rb`
171
+ `touch #{root}/b/test.rb`
172
+ `ln -s #{root}/b #{root}/c`
173
+ `ln -s #{root}/b #{root}/a/`
174
+ ParallelTests.send(:find_tests, root).sort.should == [
175
+ "#{root}/a/b/y_test.rb",
176
+ "#{root}/a/x_test.rb",
177
+ "#{root}/b/y_test.rb",
178
+ "#{root}/c/y_test.rb",
179
+ "#{root}/x_test.rb"
180
+ ]
181
+ ensure
182
+ `rm -rf #{root}`
183
+ end
184
+ end
185
+
186
+ it "finds files by pattern" do
187
+ begin
188
+ root = "/tmp/test-find_tests-#{rand(999)}"
189
+ `mkdir #{root}`
190
+ `mkdir #{root}/a`
191
+ `touch #{root}/a/x_test.rb`
192
+ `touch #{root}/a/y_test.rb`
193
+ `touch #{root}/a/z_test.rb`
194
+ ParallelTests.send(:find_tests, root, :pattern => '^a/(y|z)_test').sort.should == [
195
+ "#{root}/a/y_test.rb",
196
+ "#{root}/a/z_test.rb",
197
+ ]
198
+ ensure
199
+ `rm -rf #{root}`
200
+ end
201
+ end
202
+ end
203
+
204
+ describe :summarize_results do
205
+ it "adds results" do
206
+ ParallelTests.summarize_results(['1 foo 3 bar','2 foo 5 bar']).should == '8 bars, 3 foos'
207
+ end
208
+
209
+ it "adds results with braces" do
210
+ ParallelTests.summarize_results(['1 foo(s) 3 bar(s)','2 foo 5 bar']).should == '8 bars, 3 foos'
211
+ end
212
+
213
+ it "adds same results with plurals" do
214
+ ParallelTests.summarize_results(['1 foo 3 bar','2 foos 5 bar']).should == '8 bars, 3 foos'
215
+ end
216
+
217
+ it "adds non-similar results" do
218
+ ParallelTests.summarize_results(['1 xxx 2 yyy','1 xxx 2 zzz']).should == '2 xxxs, 2 yyys, 2 zzzs'
219
+ end
220
+
221
+ it "does not pluralize 1" do
222
+ ParallelTests.summarize_results(['1 xxx 2 yyy']).should == '1 xxx, 2 yyys'
223
+ end
224
+ end
225
+
139
226
  it "has a version" do
140
227
  ParallelTests::VERSION.should =~ /^\d+\.\d+\.\d+$/
141
228
  end
142
- end
229
+ end
data/spec/spec_helper.rb CHANGED
@@ -4,8 +4,19 @@ require 'rubygems'
4
4
 
5
5
  FAKE_RAILS_ROOT = '/tmp/pspecs/fixtures'
6
6
 
7
+ require 'tempfile'
7
8
  require 'parallel_specs'
9
+ require 'parallel_specs/spec_runtime_logger'
10
+ require 'parallel_specs/spec_summary_logger'
8
11
  require 'parallel_cucumber'
12
+ require 'parallel_tests/runtime_logger'
13
+
14
+ OutputLogger = Struct.new(:output) do
15
+ attr_reader :flock, :flush
16
+ def puts(s=nil)
17
+ self.output << s.to_s
18
+ end
19
+ end
9
20
 
10
21
  def mocked_process
11
22
  open('|cat /dev/null')
@@ -25,7 +36,7 @@ def use_temporary_directory_for
25
36
 
26
37
  begin
27
38
  # just in case the temporary dir already exists
28
- FileUtils.rm_rf(dir) if File.exists?(dir)
39
+ FileUtils.rm_rf(dir) if File.exists?(dir)
29
40
 
30
41
  # create the temporary directory
31
42
  FileUtils.mkdir_p(new_dir)
@@ -53,14 +64,18 @@ def test_tests_in_groups(klass, folder, suffix)
53
64
  file
54
65
  end
55
66
 
56
- @log = "#{FAKE_RAILS_ROOT}/tmp/parallel_profile.log"
57
- `mkdir #{File.dirname(@log)}`
67
+ @log = klass.runtime_log
68
+ `mkdir -p #{File.dirname(@log)}`
58
69
  `rm -f #{@log}`
59
70
  end
60
71
 
72
+ after :all do
73
+ `rm -f #{klass.runtime_log}`
74
+ end
75
+
61
76
  it "groups when given an array of files" do
62
77
  list_of_files = Dir["#{test_root}/**/*#{suffix}"]
63
- found = klass.tests_with_runtime(list_of_files)
78
+ found = klass.with_runtime_info(list_of_files)
64
79
  found.should =~ list_of_files.map{ |file| [file, File.stat(file).size]}
65
80
  end
66
81
 
@@ -85,18 +100,34 @@ def test_tests_in_groups(klass, folder, suffix)
85
100
  groups.map{|g| size_of(g)}.should =~ [300, 300, 200]
86
101
  end
87
102
 
88
- it "partitions by runtime when runtime-data is available" do
103
+ def setup_runtime_log
89
104
  File.open(@log,'w') do |f|
90
105
  @files[1..-1].each{|file| f.puts "#{file}:#{@files.index(file)}"}
91
106
  f.puts "#{@files[0]}:10"
92
107
  end
108
+ end
109
+
110
+ it "partitions by runtime when runtime-data is available" do
111
+ klass.stub!(:puts)
112
+ setup_runtime_log
93
113
 
94
114
  groups = klass.tests_in_groups(test_root, 2)
95
115
  groups.size.should == 2
96
- # 10 + 5 + 3 + 1 = 19
97
- groups[0].should == [@files[0],@files[5],@files[3],@files[1]]
98
- # 7 + 6 + 4 + 2 = 19
99
- groups[1].should == [@files[7],@files[6],@files[4],@files[2]]
116
+ # 10 + 1 + 3 + 5 = 19
117
+ groups[0].should == [@files[0],@files[1],@files[3],@files[5]]
118
+ # 2 + 4 + 6 + 7 = 19
119
+ groups[1].should == [@files[2],@files[4],@files[6],@files[7]]
120
+ end
121
+
122
+ it "alpha-sorts partitions when runtime-data is available" do
123
+ klass.stub!(:puts)
124
+ setup_runtime_log
125
+
126
+ groups = klass.tests_in_groups(test_root, 2)
127
+ groups.size.should == 2
128
+
129
+ groups[0].should == groups[0].sort
130
+ groups[1].should == groups[1].sort
100
131
  end
101
132
 
102
133
  it "partitions by round-robin when not sorting" do
@@ -106,5 +137,13 @@ def test_tests_in_groups(klass, folder, suffix)
106
137
  groups[0].should == ["file1.rb", "file3.rb"]
107
138
  groups[1].should == ["file2.rb", "file4.rb"]
108
139
  end
140
+
141
+ it "alpha-sorts partitions when not sorting by runtime" do
142
+ files = %w[q w e r t y u i o p a s d f g h j k l z x c v b n m]
143
+ klass.should_receive(:find_tests).and_return(files)
144
+ groups = klass.tests_in_groups(files, 2, :no_sort => true)
145
+ groups[0].should == groups[0].sort
146
+ groups[1].should == groups[1].sort
147
+ end
109
148
  end
110
149
  end
metadata CHANGED
@@ -1,41 +1,37 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: moxiesoft_parallel_tests
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.18
4
5
  prerelease:
5
- version: 0.4.13
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Michael Grosser
9
9
  - Erik DeBill
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
-
14
- date: 2011-10-06 00:00:00 -05:00
15
- default_executable:
16
- dependencies:
17
- - !ruby/object:Gem::Dependency
13
+ date: 2011-04-07 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
18
16
  name: parallel
19
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: &2152337800 !ruby/object:Gem::Requirement
20
18
  none: false
21
- requirements:
22
- - - ">="
23
- - !ruby/object:Gem::Version
24
- version: "0"
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
25
23
  type: :runtime
26
24
  prerelease: false
27
- version_requirements: *id001
25
+ version_requirements: *2152337800
28
26
  description:
29
27
  email: grosser.michael@gmail.com
30
- executables:
28
+ executables:
31
29
  - parallel_cucumber
32
30
  - parallel_spec
33
31
  - parallel_test
34
32
  extensions: []
35
-
36
33
  extra_rdoc_files: []
37
-
38
- files:
34
+ files:
39
35
  - .gitignore
40
36
  - Gemfile
41
37
  - Gemfile.lock
@@ -53,44 +49,38 @@ files:
53
49
  - lib/parallel_tests/railtie.rb
54
50
  - lib/parallel_tests/tasks.rb
55
51
  - lib/tasks/parallel_tests.rake
56
- - moxiesoft_parallel_tests.gemspec
52
+ - parallel_tests.gemspec
57
53
  - spec/integration_spec.rb
58
54
  - spec/parallel_cucumber_spec.rb
59
55
  - spec/parallel_specs_spec.rb
60
56
  - spec/parallel_tests_spec.rb
61
57
  - spec/spec_helper.rb
62
- has_rdoc: true
63
58
  homepage: http://github.com/edebill-moxiesoft/moxiesoft_parallel_tests
64
59
  licenses: []
65
-
66
60
  post_install_message:
67
- rdoc_options:
61
+ rdoc_options:
68
62
  - --charset=UTF-8
69
- require_paths:
63
+ require_paths:
70
64
  - lib
71
- required_ruby_version: !ruby/object:Gem::Requirement
65
+ required_ruby_version: !ruby/object:Gem::Requirement
72
66
  none: false
73
- requirements:
74
- - - ">="
75
- - !ruby/object:Gem::Version
76
- hash: -4444091468267362963
77
- segments:
78
- - 0
79
- version: "0"
80
- required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
72
  none: false
82
- requirements:
83
- - - ">="
84
- - !ruby/object:Gem::Version
85
- version: "0"
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
86
77
  requirements: []
87
-
88
78
  rubyforge_project:
89
- rubygems_version: 1.6.1
79
+ rubygems_version: 1.8.10
90
80
  signing_key:
91
81
  specification_version: 3
92
82
  summary: Run tests / specs / features in parallel
93
- test_files:
83
+ test_files:
94
84
  - spec/integration_spec.rb
95
85
  - spec/parallel_cucumber_spec.rb
96
86
  - spec/parallel_specs_spec.rb
@@ -1,65 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = %q{moxiesoft_parallel_tests}
8
- s.version = "0.4.13"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Michael Grosser", "Erik DeBill"]
12
- s.date = %q{2011-10-06}
13
- s.email = %q{grosser.michael@gmail.com}
14
- s.executables = ["parallel_cucumber", "parallel_spec", "parallel_test"]
15
- s.files = [
16
- ".gitignore",
17
- "Gemfile",
18
- "Gemfile.lock",
19
- "Rakefile",
20
- "Readme.md",
21
- "VERSION",
22
- "bin/parallel_cucumber",
23
- "bin/parallel_spec",
24
- "bin/parallel_test",
25
- "lib/parallel_cucumber.rb",
26
- "lib/parallel_specs.rb",
27
- "lib/parallel_specs/spec_runtime_logger.rb",
28
- "lib/parallel_tests.rb",
29
- "lib/parallel_tests/grouper.rb",
30
- "lib/parallel_tests/railtie.rb",
31
- "lib/parallel_tests/tasks.rb",
32
- "lib/tasks/parallel_tests.rake",
33
- "moxiesoft_parallel_tests.gemspec",
34
- "spec/integration_spec.rb",
35
- "spec/parallel_cucumber_spec.rb",
36
- "spec/parallel_specs_spec.rb",
37
- "spec/parallel_tests_spec.rb",
38
- "spec/spec_helper.rb"
39
- ]
40
- s.homepage = %q{http://github.com/edebill-moxiesoft/moxiesoft_parallel_tests}
41
- s.rdoc_options = ["--charset=UTF-8"]
42
- s.require_paths = ["lib"]
43
- s.rubygems_version = %q{1.6.1}
44
- s.summary = %q{Run tests / specs / features in parallel}
45
- s.test_files = [
46
- "spec/integration_spec.rb",
47
- "spec/parallel_cucumber_spec.rb",
48
- "spec/parallel_specs_spec.rb",
49
- "spec/parallel_tests_spec.rb",
50
- "spec/spec_helper.rb"
51
- ]
52
-
53
- if s.respond_to? :specification_version then
54
- s.specification_version = 3
55
-
56
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
57
- s.add_runtime_dependency(%q<parallel>, [">= 0"])
58
- else
59
- s.add_dependency(%q<parallel>, [">= 0"])
60
- end
61
- else
62
- s.add_dependency(%q<parallel>, [">= 0"])
63
- end
64
- end
65
-