parallel_tests 0.9.2 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +2 -0
- data/Gemfile.lock +1 -1
- data/Readme.md +16 -1
- data/lib/parallel_tests.rb +18 -0
- data/lib/parallel_tests/version.rb +1 -1
- data/spec/integration_spec.rb +8 -0
- data/spec/parallel_tests/test/runtime_logger_spec.rb +16 -10
- data/spec/parallel_tests_spec.rb +64 -1
- data/spec/spec_helper.rb +6 -0
- metadata +13 -12
data/.rspec
ADDED
data/Gemfile.lock
CHANGED
data/Readme.md
CHANGED
@@ -65,6 +65,20 @@ Test by pattern (e.g. use one integration server per subfolder / see if you brok
|
|
65
65
|
|
66
66
|
Took 29.925333 seconds
|
67
67
|
|
68
|
+
Running things once
|
69
|
+
===================
|
70
|
+
|
71
|
+
```Ruby
|
72
|
+
# effected by race-condition: first process may boot slower the second
|
73
|
+
# either sleep a bit or use a lock for example File.lock
|
74
|
+
ParallelTests.first_process? ? do_something : sleep(1)
|
75
|
+
|
76
|
+
at_exit do
|
77
|
+
ParallelTests.wait_for_other_processes_to_finish
|
78
|
+
undo_something
|
79
|
+
end
|
80
|
+
```
|
81
|
+
|
68
82
|
Loggers
|
69
83
|
===================
|
70
84
|
|
@@ -178,8 +192,9 @@ TIPS
|
|
178
192
|
|
179
193
|
TODO
|
180
194
|
====
|
195
|
+
- make tests consistently pass with `--order random` in .rspec
|
181
196
|
- fix tests vs cucumber >= 1.2 `unknown option --format`
|
182
|
-
- add tests for the rake tasks, maybe generate a rails project ...
|
197
|
+
- add integration tests for the rake tasks, maybe generate a rails project ...
|
183
198
|
- add unit tests for cucumber runtime formatter
|
184
199
|
- make jRuby compatible [basics](http://yehudakatz.com/2009/07/01/new-rails-isolation-testing/)
|
185
200
|
- make windows compatible
|
data/lib/parallel_tests.rb
CHANGED
@@ -4,6 +4,8 @@ require 'parallel_tests/grouper'
|
|
4
4
|
require 'parallel_tests/railtie' if defined? Rails::Railtie
|
5
5
|
|
6
6
|
module ParallelTests
|
7
|
+
GREP_PROCESSES_COMMAND = "ps -ef | grep [T]EST_ENV_NUMBER= 2>&1"
|
8
|
+
|
7
9
|
def self.determine_number_of_processes(count)
|
8
10
|
[
|
9
11
|
count,
|
@@ -27,4 +29,20 @@ module ParallelTests
|
|
27
29
|
|
28
30
|
false
|
29
31
|
end
|
32
|
+
|
33
|
+
def self.first_process?
|
34
|
+
!ENV["TEST_ENV_NUMBER"] || ENV["TEST_ENV_NUMBER"].to_i == 0
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.wait_for_other_processes_to_finish
|
38
|
+
return unless ENV["TEST_ENV_NUMBER"]
|
39
|
+
sleep 1 until number_of_running_processes <= 1
|
40
|
+
end
|
41
|
+
|
42
|
+
# Fun fact: this includes the current process if it's run via parallel_tests
|
43
|
+
def self.number_of_running_processes
|
44
|
+
result = `#{GREP_PROCESSES_COMMAND}`
|
45
|
+
raise "Could not grep for processes -> #{result}" if result.strip != "" && !$?.success?
|
46
|
+
result.split("\n").size
|
47
|
+
end
|
30
48
|
end
|
data/spec/integration_spec.rb
CHANGED
@@ -172,6 +172,14 @@ describe 'CLI' do
|
|
172
172
|
result.should include('ZZZ')
|
173
173
|
end
|
174
174
|
|
175
|
+
it "can wait_for_other_processes_to_finish" do
|
176
|
+
write "test/a_test.rb", "require 'parallel_tests'; ParallelTests.wait_for_other_processes_to_finish; puts 'a'"
|
177
|
+
write "test/b_test.rb", "sleep 1; puts 'b'"
|
178
|
+
write "test/c_test.rb", "sleep 1.5; puts 'c'"
|
179
|
+
write "test/d_test.rb", "sleep 2; puts 'd'"
|
180
|
+
run_tests("test", :processes => 4).should include("b\nc\nd\na\n")
|
181
|
+
end
|
182
|
+
|
175
183
|
context "Test::Unit" do
|
176
184
|
it "runs" do
|
177
185
|
write "test/x1_test.rb", "require 'test/unit'; class XTest < Test::Unit::TestCase; def test_xxx; end; end"
|
@@ -44,7 +44,13 @@ describe ParallelTests::Test::RuntimeLogger do
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
-
describe
|
47
|
+
describe "formatting" do
|
48
|
+
def with_rails_defined
|
49
|
+
Object.const_set(:Rails, Module.new)
|
50
|
+
yield
|
51
|
+
Object.send(:remove_const, :Rails)
|
52
|
+
end
|
53
|
+
|
48
54
|
def call(*args)
|
49
55
|
ParallelTests::Test::RuntimeLogger.message(*args)
|
50
56
|
end
|
@@ -68,17 +74,17 @@ describe ParallelTests::Test::RuntimeLogger do
|
|
68
74
|
end
|
69
75
|
|
70
76
|
it "guesses subdirectory structure for rails test classes" do
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
77
|
+
with_rails_defined do
|
78
|
+
class ActionController
|
79
|
+
class TestCase
|
80
|
+
end
|
75
81
|
end
|
82
|
+
class FakeControllerTest < ActionController::TestCase
|
83
|
+
end
|
84
|
+
test = FakeControllerTest.new
|
85
|
+
time = Time.now
|
86
|
+
call(test, time, Time.at(time.to_f+2.00)).should == 'test/functional/fake_controller_test.rb:2.00'
|
76
87
|
end
|
77
|
-
class FakeControllerTest < ActionController::TestCase
|
78
|
-
end
|
79
|
-
test = FakeControllerTest.new
|
80
|
-
time = Time.now
|
81
|
-
call(test, time, Time.at(time.to_f+2.00)).should == 'test/functional/fake_controller_test.rb:2.00'
|
82
88
|
end
|
83
89
|
end
|
84
90
|
end
|
data/spec/parallel_tests_spec.rb
CHANGED
@@ -34,7 +34,7 @@ describe ParallelTests do
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
describe
|
37
|
+
describe ".bundler_enabled?" do
|
38
38
|
before do
|
39
39
|
Object.stub!(:const_defined?).with(:Bundler).and_return false
|
40
40
|
end
|
@@ -67,6 +67,69 @@ describe ParallelTests do
|
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
+
describe ".wait_for_other_processes_to_finish" do
|
71
|
+
def with_running_processes(count, wait=0.2)
|
72
|
+
count.times { Thread.new{ `TEST_ENV_NUMBER=1; sleep #{wait}` } }
|
73
|
+
sleep 0.1
|
74
|
+
yield
|
75
|
+
ensure
|
76
|
+
sleep wait # make sure the threads have finished
|
77
|
+
end
|
78
|
+
|
79
|
+
it "does not wait if not run in parallel" do
|
80
|
+
ParallelTests.should_not_receive(:sleep)
|
81
|
+
ParallelTests.wait_for_other_processes_to_finish
|
82
|
+
end
|
83
|
+
|
84
|
+
it "stops if only itself is running" do
|
85
|
+
ENV["TEST_ENV_NUMBER"] = "2"
|
86
|
+
ParallelTests.should_not_receive(:sleep)
|
87
|
+
with_running_processes(1) do
|
88
|
+
ParallelTests.wait_for_other_processes_to_finish
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
it "waits for other processes to finish" do
|
93
|
+
ENV["TEST_ENV_NUMBER"] = "2"
|
94
|
+
counter = 0
|
95
|
+
ParallelTests.stub(:sleep).with{ sleep 0.1; counter += 1 }
|
96
|
+
with_running_processes(2, 0.4) do
|
97
|
+
ParallelTests.wait_for_other_processes_to_finish
|
98
|
+
end
|
99
|
+
counter.should == 3
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
describe ".number_of_running_processes" do
|
104
|
+
it "is 0 for nothing" do
|
105
|
+
ParallelTests.number_of_running_processes.should == 0
|
106
|
+
end
|
107
|
+
|
108
|
+
it "is 2 when 2 are running" do
|
109
|
+
wait = 0.2
|
110
|
+
2.times { Thread.new{ `TEST_ENV_NUMBER=1; sleep #{wait}` } }
|
111
|
+
sleep 0.1
|
112
|
+
ParallelTests.number_of_running_processes.should == 2
|
113
|
+
sleep wait
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe ".first_process?" do
|
118
|
+
it "is first if no env is set" do
|
119
|
+
ParallelTests.first_process?.should == true
|
120
|
+
end
|
121
|
+
|
122
|
+
it "is first if env is set to blank" do
|
123
|
+
ENV["TEST_ENV_NUMBER"] = ""
|
124
|
+
ParallelTests.first_process?.should == true
|
125
|
+
end
|
126
|
+
|
127
|
+
it "is not first if env is set to something" do
|
128
|
+
ENV["TEST_ENV_NUMBER"] = "2"
|
129
|
+
ParallelTests.first_process?.should == false
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
70
133
|
it "has a version" do
|
71
134
|
ParallelTests::VERSION.should =~ /^\d+\.\d+\.\d+/
|
72
135
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,32 +1,32 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parallel_tests
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.3
|
4
5
|
prerelease:
|
5
|
-
version: 0.9.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Michael Grosser
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
|
15
|
+
name: parallel
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
16
18
|
requirements:
|
17
19
|
- - ! '>='
|
18
20
|
- !ruby/object:Gem::Version
|
19
21
|
version: '0'
|
20
|
-
|
22
|
+
type: :runtime
|
21
23
|
prerelease: false
|
22
|
-
|
23
|
-
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
24
26
|
requirements:
|
25
27
|
- - ! '>='
|
26
28
|
- !ruby/object:Gem::Version
|
27
29
|
version: '0'
|
28
|
-
none: false
|
29
|
-
type: :runtime
|
30
30
|
description:
|
31
31
|
email: michael@grosser.it
|
32
32
|
executables:
|
@@ -37,6 +37,7 @@ extensions: []
|
|
37
37
|
extra_rdoc_files: []
|
38
38
|
files:
|
39
39
|
- .gitignore
|
40
|
+
- .rspec
|
40
41
|
- Gemfile
|
41
42
|
- Gemfile.lock
|
42
43
|
- Rakefile
|
@@ -84,23 +85,23 @@ rdoc_options: []
|
|
84
85
|
require_paths:
|
85
86
|
- lib
|
86
87
|
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
87
89
|
requirements:
|
88
90
|
- - ! '>='
|
89
91
|
- !ruby/object:Gem::Version
|
90
92
|
version: '0'
|
91
93
|
segments:
|
92
94
|
- 0
|
93
|
-
hash: -
|
94
|
-
none: false
|
95
|
+
hash: -3882668074104783522
|
95
96
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
96
98
|
requirements:
|
97
99
|
- - ! '>='
|
98
100
|
- !ruby/object:Gem::Version
|
99
101
|
version: '0'
|
100
102
|
segments:
|
101
103
|
- 0
|
102
|
-
hash: -
|
103
|
-
none: false
|
104
|
+
hash: -3882668074104783522
|
104
105
|
requirements: []
|
105
106
|
rubyforge_project:
|
106
107
|
rubygems_version: 1.8.24
|