parallel_split_test 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ spec/tmp*
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --backtrace
data/.travis.yml CHANGED
@@ -1,5 +1,4 @@
1
- script: "bundle exec rake"
2
1
  rvm:
3
2
  - ree
4
- - 1.9.2
5
3
  - 1.9.3
4
+ - 2.0.0
data/Gemfile CHANGED
@@ -1,6 +1,5 @@
1
- source :rubygems
1
+ source "https://rubygems.org"
2
2
  gemspec
3
3
 
4
- group :development do
5
- gem 'rake'
6
- end
4
+ gem "rake"
5
+ gem "bump"
data/Gemfile.lock CHANGED
@@ -1,28 +1,30 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- parallel_split_test (0.2.0)
4
+ parallel_split_test (0.2.1)
5
5
  parallel (>= 0.5.13)
6
6
  rspec (>= 2)
7
7
 
8
8
  GEM
9
- remote: http://rubygems.org/
9
+ remote: https://rubygems.org/
10
10
  specs:
11
- diff-lcs (1.1.3)
12
- parallel (0.5.13)
13
- rake (0.9.2)
14
- rspec (2.8.0)
15
- rspec-core (~> 2.8.0)
16
- rspec-expectations (~> 2.8.0)
17
- rspec-mocks (~> 2.8.0)
18
- rspec-core (2.8.0)
19
- rspec-expectations (2.8.0)
20
- diff-lcs (~> 1.1.2)
21
- rspec-mocks (2.8.0)
11
+ bump (0.4.1)
12
+ diff-lcs (1.2.3)
13
+ parallel (0.6.4)
14
+ rake (10.0.4)
15
+ rspec (2.13.0)
16
+ rspec-core (~> 2.13.0)
17
+ rspec-expectations (~> 2.13.0)
18
+ rspec-mocks (~> 2.13.0)
19
+ rspec-core (2.13.1)
20
+ rspec-expectations (2.13.0)
21
+ diff-lcs (>= 1.1.3, < 2.0)
22
+ rspec-mocks (2.13.1)
22
23
 
23
24
  PLATFORMS
24
25
  ruby
25
26
 
26
27
  DEPENDENCIES
28
+ bump
27
29
  parallel_split_test!
28
30
  rake
data/Rakefile CHANGED
@@ -1,18 +1,11 @@
1
+ require 'bundler/setup'
1
2
  require 'bundler/gem_tasks'
3
+ require 'bump/tasks'
2
4
 
3
5
  task :default do
4
6
  sh "rspec spec/"
5
7
  end
6
8
 
7
- rule /^version:bump:.*/ do |t|
8
- file = 'lib/parallel_split_test/version.rb'
9
- sh "git status | grep 'nothing to commit'" # ensure we are not dirty
10
- index = ['major', 'minor','patch'].index(t.name.split(':').last)
11
- version_file = File.read(file)
12
- old_version, *version_parts = version_file.match(/(\d+)\.(\d+)\.(\d+)/).to_a
13
- version_parts[index] = version_parts[index].to_i + 1
14
- new_version = version_parts * '.'
15
- File.open(file,'w'){|f| f.write(version_file.sub(old_version, new_version)) }
16
-
17
- sh "bundle && git add #{file} Gemfile.lock && git commit -m 'bump version to #{new_version}'"
9
+ task :selftest do
10
+ sh "./bin/parallel_split_test spec/"
18
11
  end
data/Readme.md CHANGED
@@ -2,10 +2,7 @@ Split a big test file into multiple chunks and run them in parallel
2
2
 
3
3
  Install
4
4
  =======
5
- sudo gem install parallel_split_test
6
- Or
7
-
8
- rails plugin install git://github.com/grosser/parallel_split_test.git
5
+ gem install parallel_split_test
9
6
 
10
7
  Usage
11
8
  =====
@@ -56,6 +53,12 @@ Output
56
53
  Took 10.06 seconds with 2 processes
57
54
 
58
55
 
56
+ Options
57
+ =======
58
+ <!-- last section of ./bin/parallel_split_test -h -->
59
+
60
+ -o, --test-options STRING Run tests with these options
61
+
59
62
  TIPS
60
63
  ====
61
64
  - set number of processes to use with `PARALLEL_SPLIT_TEST_PROCESSES` environment variable
@@ -2,6 +2,7 @@
2
2
  require "optparse"
3
3
  $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
4
4
 
5
+ options = {}
5
6
  parser = OptionParser.new do |opts|
6
7
  opts.banner = <<BANNER
7
8
  Split a big test file into multiple chunks and run them in parallel, giving ENV['TEST_ENV_NUMBER'] ('', '2', '3', ...)
@@ -13,6 +14,7 @@ Options are:
13
14
  BANNER
14
15
  opts.on("-v", "--version", "Show Version"){ require 'parallel_split_test/version'; puts ParallelSplitTest::VERSION; exit}
15
16
  opts.on("-h", "--help", "Show this.") { puts opts; exit }
17
+ opts.on("-o", "--test-options STRING", "Run tests with these options") { |test_options| options[:test_options] = test_options }
16
18
  end
17
19
 
18
20
  parser.parse!
@@ -23,4 +25,4 @@ if ARGV.empty?
23
25
  end
24
26
 
25
27
  require 'parallel_split_test/runner'
26
- exit ParallelSplitTest::Runner.run(ARGV)
28
+ exit ParallelSplitTest::Runner.run(ARGV, options)
@@ -3,22 +3,22 @@ require 'parallel'
3
3
  module ParallelSplitTest
4
4
  class << self
5
5
  attr_accessor :example_counter, :processes, :process_number
6
- end
7
6
 
8
- def self.run_example?
9
- self.example_counter += 1
10
- (example_counter - 1) % processes == process_number
11
- end
7
+ def run_example?
8
+ self.example_counter += 1
9
+ (example_counter - 1) % processes == process_number
10
+ end
12
11
 
13
- def self.choose_number_of_processes
14
- self.processes = best_number_of_processes
15
- end
12
+ def choose_number_of_processes
13
+ self.processes = best_number_of_processes
14
+ end
16
15
 
17
- def self.best_number_of_processes
18
- [
19
- ENV['PARALLEL_SPLIT_TEST_PROCESSES'],
20
- Parallel.physical_processor_count,
21
- Parallel.processor_count
22
- ].map(&:to_i).find{|number| number > 0 }
16
+ def best_number_of_processes
17
+ [
18
+ ENV['PARALLEL_SPLIT_TEST_PROCESSES'],
19
+ Parallel.physical_processor_count,
20
+ Parallel.processor_count
21
+ ].map(&:to_i).find{|number| number > 0 }
22
+ end
23
23
  end
24
24
  end
@@ -57,4 +57,4 @@ module ParallelSplitTest
57
57
  @world.announce_filters
58
58
  end
59
59
  end
60
- end
60
+ end
@@ -7,11 +7,11 @@ module ParallelSplitTest
7
7
  @out = out
8
8
  end
9
9
 
10
- %w[puts write print putc].each do |method|
10
+ %w[puts write print putc flush].each do |method|
11
11
  class_eval <<-RUBY, __FILE__, __LINE__
12
12
  def #{method}(*args)
13
- @recorded.puts(*args)
14
- @out.puts(*args)
13
+ @recorded.#{method}(*args)
14
+ @out.#{method}(*args)
15
15
  end
16
16
  RUBY
17
17
  end
@@ -21,4 +21,4 @@ module ParallelSplitTest
21
21
  @recorded.read
22
22
  end
23
23
  end
24
- end
24
+ end
@@ -1,10 +1,16 @@
1
1
  require 'parallel_split_test/command_line'
2
+ require 'shellwords'
2
3
 
3
4
  # a cleaned up version of the RSpec runner, e.g. no drb support
4
5
  module ParallelSplitTest
5
6
  class Runner < RSpec::Core::Runner
6
- def self.run(args, err=$stderr, out=$stdout)
7
+ def self.run(args, options={})
8
+ err = $stderr
9
+ out = $stdout
7
10
  trap_interrupt
11
+
12
+ args += Shellwords.shellwords(options[:test_options]) if options[:test_options] # TODO smarter parsing ...
13
+
8
14
  options = RSpec::Core::ConfigurationOptions.new(args)
9
15
  options.parse_options
10
16
 
@@ -18,6 +24,8 @@ module ParallelSplitTest
18
24
  RSpec.reset
19
25
  end
20
26
 
27
+ private
28
+
21
29
  def self.report_execution_time(out)
22
30
  start = Time.now.to_f
23
31
  result = yield
@@ -26,4 +34,4 @@ module ParallelSplitTest
26
34
  result
27
35
  end
28
36
  end
29
- end
37
+ end
@@ -1,3 +1,3 @@
1
1
  module ParallelSplitTest
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
@@ -44,7 +44,7 @@ describe ParallelSplitTest do
44
44
  end
45
45
 
46
46
  def parallel_split_test(x, options={})
47
- run "PARALLEL_SPLIT_TEST_PROCESSES=2 ../../bin/parallel_split_test #{x}", options
47
+ run "PARALLEL_SPLIT_TEST_PROCESSES=#{options[:process_count] || 2} ../../bin/parallel_split_test #{x}", options
48
48
  end
49
49
 
50
50
  def time
@@ -55,13 +55,11 @@ describe ParallelSplitTest do
55
55
 
56
56
  let(:root) { File.expand_path('../../', __FILE__) }
57
57
 
58
- before do
59
- run "rm -rf spec/tmp ; mkdir spec/tmp"
60
- Dir.chdir "spec/tmp"
61
- end
62
-
63
- after do
64
- Dir.chdir root
58
+ around do |example|
59
+ dir = "spec/tmp#{ENV['TEST_ENV_NUMBER']}"
60
+ run "rm -rf #{dir} ; mkdir #{dir}"
61
+ Dir.chdir(dir, &example)
62
+ run "rm -rf #{dir}"
65
63
  end
66
64
 
67
65
  describe "printing version" do
@@ -108,32 +106,49 @@ describe ParallelSplitTest do
108
106
  result.scan(/it-ran-.-in-.?-/).sort.should == ["it-ran-a-in--", "it-ran-b-in-2-"]
109
107
  end
110
108
 
109
+ it "runs in different processes for many examples/processes" do
110
+ write "xxx_spec.rb", <<-RUBY
111
+ describe "X" do
112
+ #{(0...3).to_a.map{|i| "it{ puts 'it-ran-"+ i.to_s+"-in-'+ENV['TEST_ENV_NUMBER'].to_s + '-' }" }.join("\n")}
113
+ describe "Y" do
114
+ #{(3...6).to_a.map{|i| "it{ puts 'it-ran-"+ i.to_s+"-in-'+ENV['TEST_ENV_NUMBER'].to_s + '-' }" }.join("\n")}
115
+ describe "Y" do
116
+ #{(6...9).to_a.map{|i| "it{ puts 'it-ran-"+ i.to_s+"-in-'+ENV['TEST_ENV_NUMBER'].to_s + '-' }" }.join("\n")}
117
+ end
118
+ end
119
+ end
120
+ RUBY
121
+ result = parallel_split_test "xxx_spec.rb", :process_count => 3
122
+ result.scan('3 examples, 0 failures').size.should == 6
123
+ result.scan(/it-ran-.-in-.?-/).size.should == 9
124
+ end
125
+
111
126
  it "runs faster" do
112
127
  write "xxx_spec.rb", <<-RUBY
113
128
  describe "X" do
114
- it { sleep 1 }
129
+ it { sleep 1.5 }
115
130
  end
116
131
 
117
132
  describe "Y" do
118
- it { sleep 1 }
133
+ it { sleep 1.5 }
119
134
  end
120
135
  RUBY
121
136
 
122
- time{ parallel_split_test "xxx_spec.rb" }.should < 2
137
+ time{ parallel_split_test "xxx_spec.rb" }.should < 3
123
138
  end
124
139
 
125
140
  it "splits based on examples" do
126
141
  write "xxx_spec.rb", <<-RUBY
127
142
  describe "X" do
128
143
  describe "Y" do
129
- it { sleep 1 }
130
- it { sleep 1 }
144
+ it { sleep 1.5 }
145
+ it { sleep 1.5 }
131
146
  end
132
147
  end
133
148
  RUBY
134
149
 
135
150
  result = nil
136
- time{ result = parallel_split_test "xxx_spec.rb" }.should < 2
151
+ time{ result = parallel_split_test "xxx_spec.rb" }.should < 3
137
152
  result.scan('1 example, 0 failures').size.should == 4
138
153
  end
139
154
 
@@ -207,6 +222,18 @@ describe ParallelSplitTest do
207
222
  result = parallel_split_test "xxx_spec.rb"
208
223
  result.should include("1 example, 0 failures\n1 example, 0 failures")
209
224
  end
225
+
226
+ it "can use --test-options" do
227
+ write "xxx_spec.rb", <<-RUBY
228
+ describe "xxx" do
229
+ it "yyy" do
230
+ end
231
+ end
232
+ RUBY
233
+
234
+ result = parallel_split_test "xxx_spec.rb --test-options '--format html'"
235
+ result.should include "</body>"
236
+ end
210
237
  end
211
238
  end
212
239
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parallel_split_test
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-04 00:00:00.000000000 Z
12
+ date: 2013-04-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &81205430 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '2'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *81205430
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '2'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: parallel
27
- requirement: &81205180 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,7 +37,12 @@ dependencies:
32
37
  version: 0.5.13
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *81205180
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 0.5.13
36
46
  description:
37
47
  email: michael@grosser.it
38
48
  executables:
@@ -40,6 +50,8 @@ executables:
40
50
  extensions: []
41
51
  extra_rdoc_files: []
42
52
  files:
53
+ - .gitignore
54
+ - .rspec
43
55
  - .travis.yml
44
56
  - Gemfile
45
57
  - Gemfile.lock
@@ -71,7 +83,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
71
83
  version: '0'
72
84
  segments:
73
85
  - 0
74
- hash: 131892335
86
+ hash: 4510026555026143828
75
87
  required_rubygems_version: !ruby/object:Gem::Requirement
76
88
  none: false
77
89
  requirements:
@@ -80,10 +92,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
92
  version: '0'
81
93
  segments:
82
94
  - 0
83
- hash: 131892335
95
+ hash: 4510026555026143828
84
96
  requirements: []
85
97
  rubyforge_project:
86
- rubygems_version: 1.8.10
98
+ rubygems_version: 1.8.25
87
99
  signing_key:
88
100
  specification_version: 3
89
101
  summary: Split a big test file into multiple chunks and run them in parallel