parallelized_specs 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +10 -0
- data/Gemfile.lock +30 -0
- data/Rakefile +21 -0
- data/Readme.md +240 -0
- data/VERSION +1 -0
- data/bin/parallel_spec +2 -0
- data/bin/parallel_test +97 -0
- data/lib/parallel_specs/spec_error_count_logger.rb +30 -0
- data/lib/parallel_specs/spec_error_logger.rb +45 -0
- data/lib/parallel_specs/spec_failures_logger.rb +43 -0
- data/lib/parallel_specs/spec_logger_base.rb +56 -0
- data/lib/parallel_specs/spec_runtime_logger.rb +34 -0
- data/lib/parallel_specs/spec_start_finish_logger.rb +38 -0
- data/lib/parallel_specs/spec_summary_logger.rb +19 -0
- data/lib/parallel_specs.rb +52 -0
- data/lib/parallel_tests/grouper.rb +49 -0
- data/lib/parallel_tests/railtie.rb +10 -0
- data/lib/parallel_tests/runtime_logger.rb +78 -0
- data/lib/parallel_tests/tasks.rb +80 -0
- data/lib/parallel_tests.rb +163 -0
- data/lib/tasks/parallel_tests.rake +1 -0
- data/parallelized_specs.gemspec +64 -0
- data/spec/integration_spec.rb +133 -0
- data/spec/parallel_specs/spec_failure_logger_spec.rb +82 -0
- data/spec/parallel_specs/spec_runtime_logger_spec.rb +76 -0
- data/spec/parallel_specs/spec_summary_logger_spec.rb +33 -0
- data/spec/parallel_specs_spec.rb +165 -0
- data/spec/parallel_tests/runtime_logger_spec.rb +74 -0
- data/spec/parallel_tests_spec.rb +229 -0
- data/spec/spec_helper.rb +149 -0
- metadata +109 -0
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
# ---- requirements
|
2
|
+
$LOAD_PATH << File.expand_path("../lib", File.dirname(__FILE__))
|
3
|
+
require 'rubygems'
|
4
|
+
|
5
|
+
FAKE_RAILS_ROOT = '/tmp/pspecs/fixtures'
|
6
|
+
|
7
|
+
require 'tempfile'
|
8
|
+
require 'parallel_specs'
|
9
|
+
require 'parallel_specs/spec_runtime_logger'
|
10
|
+
require 'parallel_specs/spec_summary_logger'
|
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
|
20
|
+
|
21
|
+
def mocked_process
|
22
|
+
open('|cat /dev/null')
|
23
|
+
end
|
24
|
+
|
25
|
+
def size_of(group)
|
26
|
+
group.inject(0) { |sum, test| sum += File.stat(test).size }
|
27
|
+
end
|
28
|
+
|
29
|
+
# Uses /tmp/parallel_tests/application as the cwd so we can create and remove
|
30
|
+
# files as we want to. After execution it changes cwd back to the original one.
|
31
|
+
def use_temporary_directory_for
|
32
|
+
require 'fileutils'
|
33
|
+
|
34
|
+
dir = File.join("/tmp", "parallel_tests")
|
35
|
+
new_dir = File.join(dir, "application")
|
36
|
+
|
37
|
+
begin
|
38
|
+
# just in case the temporary dir already exists
|
39
|
+
FileUtils.rm_rf(dir) if File.exists?(dir)
|
40
|
+
|
41
|
+
# create the temporary directory
|
42
|
+
FileUtils.mkdir_p(new_dir)
|
43
|
+
|
44
|
+
# chdir changes cwd back to the original one after it is done
|
45
|
+
Dir.chdir(new_dir) do
|
46
|
+
yield
|
47
|
+
end
|
48
|
+
ensure
|
49
|
+
FileUtils.rm_rf(dir) if File.exists?(dir)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_tests_in_groups(klass, folder, suffix)
|
54
|
+
test_root = "#{FAKE_RAILS_ROOT}/#{folder}"
|
55
|
+
|
56
|
+
describe :tests_in_groups do
|
57
|
+
before :all do
|
58
|
+
system "rm -rf #{FAKE_RAILS_ROOT}; mkdir -p #{test_root}/temp"
|
59
|
+
|
60
|
+
@files = [0,1,2,3,4,5,6,7].map do |i|
|
61
|
+
size = 99
|
62
|
+
file = "#{test_root}/temp/x#{i}#{suffix}"
|
63
|
+
File.open(file, 'w') { |f| f.puts 'x' * size }
|
64
|
+
file
|
65
|
+
end
|
66
|
+
|
67
|
+
@log = klass.runtime_log
|
68
|
+
`mkdir -p #{File.dirname(@log)}`
|
69
|
+
`rm -f #{@log}`
|
70
|
+
end
|
71
|
+
|
72
|
+
after :all do
|
73
|
+
`rm -f #{klass.runtime_log}`
|
74
|
+
end
|
75
|
+
|
76
|
+
it "groups when given an array of files" do
|
77
|
+
list_of_files = Dir["#{test_root}/**/*#{suffix}"]
|
78
|
+
found = klass.with_runtime_info(list_of_files)
|
79
|
+
found.should =~ list_of_files.map{ |file| [file, File.stat(file).size]}
|
80
|
+
end
|
81
|
+
|
82
|
+
it "finds all tests" do
|
83
|
+
found = klass.tests_in_groups(test_root, 1)
|
84
|
+
all = [ Dir["#{test_root}/**/*#{suffix}"] ]
|
85
|
+
(found.flatten - all.flatten).should == []
|
86
|
+
end
|
87
|
+
|
88
|
+
it "partitions them into groups by equal size" do
|
89
|
+
groups = klass.tests_in_groups(test_root, 2)
|
90
|
+
groups.map{|g| size_of(g)}.should == [400, 400]
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'should partition correctly with a group size of 4' do
|
94
|
+
groups = klass.tests_in_groups(test_root, 4)
|
95
|
+
groups.map{|g| size_of(g)}.should == [200, 200, 200, 200]
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'should partition correctly with an uneven group size' do
|
99
|
+
groups = klass.tests_in_groups(test_root, 3)
|
100
|
+
groups.map{|g| size_of(g)}.should =~ [300, 300, 200]
|
101
|
+
end
|
102
|
+
|
103
|
+
def setup_runtime_log
|
104
|
+
File.open(@log,'w') do |f|
|
105
|
+
@files[1..-1].each{|file| f.puts "#{file}:#{@files.index(file)}"}
|
106
|
+
f.puts "#{@files[0]}:10"
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
it "partitions by runtime when runtime-data is available" do
|
111
|
+
klass.stub!(:puts)
|
112
|
+
setup_runtime_log
|
113
|
+
|
114
|
+
groups = klass.tests_in_groups(test_root, 2)
|
115
|
+
groups.size.should == 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
|
131
|
+
end
|
132
|
+
|
133
|
+
it "partitions by round-robin when not sorting" do
|
134
|
+
files = ["file1.rb", "file2.rb", "file3.rb", "file4.rb"]
|
135
|
+
klass.should_receive(:find_tests).and_return(files)
|
136
|
+
groups = klass.tests_in_groups(files, 2, :no_sort => true)
|
137
|
+
groups[0].should == ["file1.rb", "file3.rb"]
|
138
|
+
groups[1].should == ["file2.rb", "file4.rb"]
|
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
|
148
|
+
end
|
149
|
+
end
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: parallelized_specs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Jake Sorce, Bryan Madsen
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-04-17 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: parallel
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
description:
|
35
|
+
email: jake@instructure.com
|
36
|
+
executables:
|
37
|
+
- parallel_test
|
38
|
+
- parallel_spec
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files: []
|
42
|
+
|
43
|
+
files:
|
44
|
+
- Gemfile
|
45
|
+
- Gemfile.lock
|
46
|
+
- Rakefile
|
47
|
+
- Readme.md
|
48
|
+
- VERSION
|
49
|
+
- bin/parallel_spec
|
50
|
+
- bin/parallel_test
|
51
|
+
- lib/parallel_specs.rb
|
52
|
+
- lib/parallel_specs/spec_error_count_logger.rb
|
53
|
+
- lib/parallel_specs/spec_error_logger.rb
|
54
|
+
- lib/parallel_specs/spec_failures_logger.rb
|
55
|
+
- lib/parallel_specs/spec_logger_base.rb
|
56
|
+
- lib/parallel_specs/spec_runtime_logger.rb
|
57
|
+
- lib/parallel_specs/spec_start_finish_logger.rb
|
58
|
+
- lib/parallel_specs/spec_summary_logger.rb
|
59
|
+
- lib/parallel_tests.rb
|
60
|
+
- lib/parallel_tests/grouper.rb
|
61
|
+
- lib/parallel_tests/railtie.rb
|
62
|
+
- lib/parallel_tests/runtime_logger.rb
|
63
|
+
- lib/parallel_tests/tasks.rb
|
64
|
+
- lib/tasks/parallel_tests.rake
|
65
|
+
- parallelized_specs.gemspec
|
66
|
+
- spec/integration_spec.rb
|
67
|
+
- spec/parallel_specs/spec_failure_logger_spec.rb
|
68
|
+
- spec/parallel_specs/spec_runtime_logger_spec.rb
|
69
|
+
- spec/parallel_specs/spec_summary_logger_spec.rb
|
70
|
+
- spec/parallel_specs_spec.rb
|
71
|
+
- spec/parallel_tests/runtime_logger_spec.rb
|
72
|
+
- spec/parallel_tests_spec.rb
|
73
|
+
- spec/spec_helper.rb
|
74
|
+
homepage: http://github.com/jake/parallelized_specs
|
75
|
+
licenses: []
|
76
|
+
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
hash: 3
|
88
|
+
segments:
|
89
|
+
- 0
|
90
|
+
version: "0"
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
none: false
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
hash: 3
|
97
|
+
segments:
|
98
|
+
- 0
|
99
|
+
version: "0"
|
100
|
+
requirements: []
|
101
|
+
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 1.8.22
|
104
|
+
signing_key:
|
105
|
+
specification_version: 3
|
106
|
+
summary: Run rspec tests in parallel
|
107
|
+
test_files: []
|
108
|
+
|
109
|
+
has_rdoc:
|