parallelized_specs 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +0,0 @@
1
- require File.join(File.dirname(__FILE__), "/../parallelized_tests/tasks")
@@ -1,132 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'CLI' do
4
- before do
5
- `rm -rf #{folder}`
6
- end
7
-
8
- after do
9
- `rm -rf #{folder}`
10
- end
11
-
12
- def folder
13
- "/tmp/parallelized_tests_tests"
14
- end
15
-
16
- def write(file, content)
17
- path = "#{folder}/#{file}"
18
- `mkdir -p #{File.dirname(path)}` unless File.exist?(File.dirname(path))
19
- File.open(path, 'w'){|f| f.write content }
20
- path
21
- end
22
-
23
- def bin_folder
24
- "#{File.expand_path(File.dirname(__FILE__))}/../bin"
25
- end
26
-
27
- def executable
28
- "#{bin_folder}/parallelized_test"
29
- end
30
-
31
- def run_tests(options={})
32
- `cd #{folder} && #{executable} --chunk-timeout 999 -t #{options[:type] || 'spec'} -n #{options[:processes]||2} #{options[:add]} 2>&1`
33
- end
34
-
35
- it "runs tests in parallel" do
36
- write 'spec/xxx_spec.rb', 'describe("it"){it("should"){puts "TEST1"}}'
37
- write 'spec/xxx2_spec.rb', 'describe("it"){it("should"){puts "TEST2"}}'
38
- result = run_tests
39
-
40
- # test ran and gave their puts
41
- result.should include('TEST1')
42
- result.should include('TEST2')
43
-
44
- # all results present
45
- result.scan('1 example, 0 failure').size.should == 2 # 2 results
46
- result.scan('2 examples, 0 failures').size.should == 1 # 1 summary
47
- result.scan(/Finished in \d+\.\d+ seconds/).size.should == 2
48
- result.scan(/Took \d+\.\d+ seconds/).size.should == 1 # parallel summary
49
- $?.success?.should == true
50
- end
51
-
52
- it "does not run any tests if there are none" do
53
- write 'spec/xxx.rb', 'xxx'
54
- result = run_tests
55
- result.should include('No examples found')
56
- result.should include('Took')
57
- end
58
-
59
- it "fails when tests fail" do
60
- write 'spec/xxx_spec.rb', 'describe("it"){it("should"){puts "TEST1"}}'
61
- write 'spec/xxx2_spec.rb', 'describe("it"){it("should"){1.should == 2}}'
62
- result = run_tests
63
-
64
- result.scan('1 example, 1 failure').size.should == 1
65
- result.scan('1 example, 0 failure').size.should == 1
66
- result.scan('2 examples, 1 failure').size.should == 1
67
- $?.success?.should == false
68
- end
69
-
70
- it "can exec given commands with ENV['TEST_ENV_NUM']" do
71
- result = `#{executable} -e 'ruby -e "print ENV[:TEST_ENV_NUMBER.to_s].to_i"' -n 4`
72
- result.gsub('"','').split('').sort.should == %w[0 2 3 4]
73
- end
74
-
75
- it "can exec given command non-parallel" do
76
- result = `#{executable} -e 'ruby -e "sleep(rand(10)/100.0); puts ENV[:TEST_ENV_NUMBER.to_s].inspect"' -n 4 --non-parallel`
77
- result.split("\n").should == %w["" "2" "3" "4"]
78
- end
79
-
80
- it "exists with success if all sub-processes returned success" do
81
- system("#{executable} -e 'cat /dev/null' -n 4").should == true
82
- end
83
-
84
- it "exists with failure if any sub-processes returned failure" do
85
- system("#{executable} -e 'test -e xxxx' -n 4").should == false
86
- end
87
-
88
- it "can run through parallel_spec / parallel_cucumber" do
89
- version = `#{executable} -v`
90
- `#{bin_folder}/parallelized_spec -v`.should == version
91
- end
92
-
93
- it "runs faster with more processes" do
94
- 2.times{|i|
95
- write "spec/xxx#{i}_spec.rb", 'describe("it"){it("should"){sleep 5}}; $stderr.puts ENV["TEST_ENV_NUMBER"]'
96
- }
97
- t = Time.now
98
- run_tests(:processes => 2)
99
- expected = 10
100
- (Time.now - t).should <= expected
101
- end
102
-
103
- it "can can with given files" do
104
- write "spec/x1_spec.rb", "puts '111'"
105
- write "spec/x2_spec.rb", "puts '222'"
106
- write "spec/x3_spec.rb", "puts '333'"
107
- result = run_tests(:add => 'spec/x1_spec.rb spec/x3_spec.rb')
108
- result.should include('111')
109
- result.should include('333')
110
- result.should_not include('222')
111
- end
112
-
113
- it "can run with test-options" do
114
- write "spec/x1_spec.rb", ""
115
- write "spec/x2_spec.rb", ""
116
- result = run_tests(:add => "--test-options ' --version'", :processes => 2)
117
- result.should =~ /\d+\.\d+\.\d+.*\d+\.\d+\.\d+/m # prints version twice
118
- end
119
-
120
- it "runs with test::unit" do
121
- write "test/x1_test.rb", "require 'test/unit'; class XTest < Test::Unit::TestCase; def test_xxx; end; end"
122
- result = run_tests(:type => :test)
123
- result.should include('1 test')
124
- $?.success?.should == true
125
- end
126
-
127
- it "passes test options to test::unit" do
128
- write "test/x1_test.rb", "require 'test/unit'; class XTest < Test::Unit::TestCase; def test_xxx; end; end"
129
- result = run_tests(:type => :test, :add => '--test-options "-v"')
130
- result.should include('test_xxx') # verbose output of every test
131
- end
132
- end
@@ -1,74 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ParallelizedTests::RuntimeLogger do
4
-
5
- describe :writing do
6
- it "overwrites the runtime_log file on first log invocation" do
7
- class FakeTest
8
- end
9
- test = FakeTest.new
10
- time = Time.now
11
- File.open(ParallelizedTests.runtime_log, 'w'){ |f| f.puts("FooBar") }
12
- ParallelizedTests::RuntimeLogger.send(:class_variable_set,:@@has_started, false)
13
- ParallelizedTests::RuntimeLogger.log(test, time, Time.at(time.to_f+2.00))
14
- result = File.read(ParallelizedTests.runtime_log)
15
- result.should_not include('FooBar')
16
- result.should include('test/fake_test.rb:2.00')
17
- end
18
-
19
- it "appends to the runtime_log file after first log invocation" do
20
- class FakeTest
21
- end
22
- test = FakeTest.new
23
- class OtherFakeTest
24
- end
25
- other_test = OtherFakeTest.new
26
-
27
- time = Time.now
28
- File.open(ParallelizedTests.runtime_log, 'w'){ |f| f.puts("FooBar") }
29
- ParallelizedTests::RuntimeLogger.send(:class_variable_set,:@@has_started, false)
30
- ParallelizedTests::RuntimeLogger.log(test, time, Time.at(time.to_f+2.00))
31
- ParallelizedTests::RuntimeLogger.log(other_test, time, Time.at(time.to_f+2.00))
32
- result = File.read(ParallelizedTests.runtime_log)
33
- result.should_not include('FooBar')
34
- result.should include('test/fake_test.rb:2.00')
35
- result.should include('test/other_fake_test.rb:2.00')
36
- end
37
-
38
- end
39
-
40
- describe :formatting do
41
- it "formats results for simple test names" do
42
- class FakeTest
43
- end
44
- test = FakeTest.new
45
- time = Time.now
46
- ParallelizedTests::RuntimeLogger.message(test, time, Time.at(time.to_f+2.00)).should == 'test/fake_test.rb:2.00'
47
- end
48
-
49
- it "formats results for complex test names" do
50
- class AVeryComplex
51
- class FakeTest
52
- end
53
- end
54
- test = AVeryComplex::FakeTest.new
55
- time = Time.now
56
- ParallelizedTests::RuntimeLogger.message(test, time, Time.at(time.to_f+2.00)).should == 'test/a_very_complex/fake_test.rb:2.00'
57
- end
58
-
59
- it "guesses subdirectory structure for rails test classes" do
60
- module Rails
61
- end
62
- class ActionController
63
- class TestCase
64
- end
65
- end
66
- class FakeControllerTest < ActionController::TestCase
67
- end
68
- test = FakeControllerTest.new
69
- time = Time.now
70
- ParallelizedTests::RuntimeLogger.message(test, time, Time.at(time.to_f+2.00)).should == 'test/functional/fake_controller_test.rb:2.00'
71
- end
72
- end
73
-
74
- end
@@ -1,229 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ParallelizedTests do
4
- test_tests_in_groups(ParallelizedTests, 'test', '_test.rb')
5
-
6
- describe :parse_rake_args do
7
- it "should return the count" do
8
- args = {:count => 2}
9
- ParallelizedTests.parse_rake_args(args).should == [2, '', ""]
10
- end
11
-
12
- it "should default to the prefix" do
13
- args = {:count => "models"}
14
- ParallelizedTests.parse_rake_args(args).should == [Parallel.processor_count, "models", ""]
15
- end
16
-
17
- it "should return the count and pattern" do
18
- args = {:count => 2, :pattern => "models"}
19
- ParallelizedTests.parse_rake_args(args).should == [2, "models", ""]
20
- end
21
-
22
- it "should return the count, pattern, and options" do
23
- args = {:count => 2, :pattern => "plain", :options => "-p default" }
24
- ParallelizedTests.parse_rake_args(args).should == [2, "plain", "-p default"]
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
- ParallelizedTests.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
- ParallelizedTests.parse_rake_args(args).should == [2, '', ""]
36
- end
37
- end
38
-
39
- describe :run_tests do
40
- it "uses TEST_ENV_NUMBER=blank when called for process 0" do
41
- ParallelizedTests.should_receive(:open).with{|x,y|x=~/TEST_ENV_NUMBER= /}.and_return mocked_process
42
- ParallelizedTests.run_tests(['xxx'],0,{})
43
- end
44
-
45
- it "uses TEST_ENV_NUMBER=2 when called for process 1" do
46
- ParallelizedTests.should_receive(:open).with{|x,y| x=~/TEST_ENV_NUMBER=2/}.and_return mocked_process
47
- ParallelizedTests.run_tests(['xxx'],1,{})
48
- end
49
-
50
- it "uses options" do
51
- ParallelizedTests.should_receive(:open).with{|x,y| x=~ %r{ruby -Itest .* -- -v}}.and_return mocked_process
52
- ParallelizedTests.run_tests(['xxx'],1,:test_options => '-v')
53
- end
54
-
55
- it "returns the output" do
56
- io = open('spec/spec_helper.rb')
57
- ParallelizedTests.stub!(:print)
58
- ParallelizedTests.should_receive(:open).and_return io
59
- ParallelizedTests.run_tests(['xxx'],1,{})[:stdout].should =~ /\$LOAD_PATH << File/
60
- end
61
- end
62
-
63
- describe :test_in_groups do
64
- it "does not sort when passed false do_sort option" do
65
- ParallelizedTests.should_not_receive(:smallest_first)
66
- ParallelizedTests.tests_in_groups [], 1, :no_sort => true
67
- end
68
-
69
- it "does sort when not passed do_sort option" do
70
- ParallelizedTests.stub!(:tests_with_runtime).and_return([])
71
- ParallelizedTests::Grouper.should_receive(:largest_first).and_return([])
72
- ParallelizedTests.tests_in_groups [], 1
73
- end
74
-
75
- it "groups by single_process pattern and then via size" do
76
- ParallelizedTests.should_receive(:with_runtime_info).and_return([['aaa',5],['aaa2',5],['bbb',2],['ccc',1],['ddd',1]])
77
- result = ParallelizedTests.tests_in_groups [], 3, :single_process => [/^a.a/]
78
- result.should == [["aaa", "aaa2"], ["bbb"], ["ccc", "ddd"]]
79
- end
80
- end
81
-
82
- describe :find_results do
83
- it "finds multiple results in test output" do
84
- output = <<EOF
85
- Loaded suite /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake/rake_test_loader
86
- Started
87
- ..............
88
- Finished in 0.145069 seconds.
89
-
90
- 10 tests, 20 assertions, 0 failures, 0 errors
91
- Loaded suite /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake/rake_test_loader
92
- Started
93
- ..............
94
- Finished in 0.145069 seconds.
95
-
96
- 14 tests, 20 assertions, 0 failures, 0 errors
97
-
98
- EOF
99
-
100
- ParallelizedTests.find_results(output).should == ['10 tests, 20 assertions, 0 failures, 0 errors','14 tests, 20 assertions, 0 failures, 0 errors']
101
- end
102
-
103
- it "is robust against scrambled output" do
104
- output = <<EOF
105
- Loaded suite /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake/rake_test_loader
106
- Started
107
- ..............
108
- Finished in 0.145069 seconds.
109
-
110
- 10 tests, 20 assertions, 0 failures, 0 errors
111
- Loaded suite /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake/rake_test_loader
112
- Started
113
- ..............
114
- Finished in 0.145069 seconds.
115
-
116
- 14 te.dsts, 20 assertions, 0 failures, 0 errors
117
- EOF
118
-
119
- ParallelizedTests.find_results(output).should == ['10 tests, 20 assertions, 0 failures, 0 errors','14 tedsts, 20 assertions, 0 failures, 0 errors']
120
- end
121
- end
122
-
123
- describe :bundler_enabled? do
124
- before do
125
- Object.stub!(:const_defined?).with(:Bundler).and_return false
126
- end
127
-
128
- it "should return false" do
129
- use_temporary_directory_for do
130
- ParallelizedTests.send(:bundler_enabled?).should == false
131
- end
132
- end
133
-
134
- it "should return true when there is a constant called Bundler" do
135
- use_temporary_directory_for do
136
- Object.stub!(:const_defined?).with(:Bundler).and_return true
137
- ParallelizedTests.send(:bundler_enabled?).should == true
138
- end
139
- end
140
-
141
- it "should be true when there is a Gemfile" do
142
- use_temporary_directory_for do
143
- FileUtils.touch("Gemfile")
144
- ParallelizedTests.send(:bundler_enabled?).should == true
145
- end
146
- end
147
-
148
- it "should be true when there is a Gemfile in the parent directory" do
149
- use_temporary_directory_for do
150
- FileUtils.touch(File.join("..", "Gemfile"))
151
- ParallelizedTests.send(:bundler_enabled?).should == true
152
- end
153
- end
154
- end
155
-
156
- describe :find_tests do
157
- it "returns if root is an array" do
158
- ParallelizedTests.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
- ParallelizedTests.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
- ParallelizedTests.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
- ParallelizedTests.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
- ParallelizedTests.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
- ParallelizedTests.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
- ParallelizedTests.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
- ParallelizedTests.summarize_results(['1 xxx 2 yyy']).should == '1 xxx, 2 yyys'
223
- end
224
- end
225
-
226
- it "has a version" do
227
- ParallelizedTests::VERSION.should =~ /^\d+\.\d+\.\d+$/
228
- end
229
- end