parallel_tests 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.2
1
+ 0.4.3
@@ -2,6 +2,7 @@
2
2
  require 'rubygems'
3
3
  require 'optparse'
4
4
  require 'parallel'
5
+ raise "please ' gem install parallel '" if Gem::Version.new(Parallel::VERSION) < Gem::Version.new('0.4.2')
5
6
  $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
6
7
  require "parallel_tests"
7
8
 
@@ -31,9 +32,10 @@ num_processes = options[:count] || Parallel.processor_count
31
32
  num_processes = num_processes * (options[:multiply] || 1)
32
33
 
33
34
  if options[:execute]
34
- Parallel.in_processes(num_processes) do |i|
35
+ results = Parallel.map(0...num_processes, :in_processes => num_processes) do |i|
35
36
  ParallelTests.execute_command(options[:execute], i)
36
37
  end
38
+ abort if results.any?{|r| r[:exit_status] != 0 }
37
39
  else
38
40
  lib, name, task = {
39
41
  'test' => ["tests", "test", "test"],
@@ -4,7 +4,7 @@ class ParallelCucumber < ParallelTests
4
4
  def self.run_tests(test_files, process_number, options)
5
5
  color = ($stdout.tty? ? 'AUTOTEST=1 ; export AUTOTEST ;' : '')#display color when we are in a terminal
6
6
  cmd = "#{color} #{executable} #{options} #{test_files*' '}"
7
- execute_command(cmd, process_number)
7
+ execute_command(cmd, process_number)[:stdout]
8
8
  end
9
9
 
10
10
  def self.executable
@@ -3,7 +3,7 @@ require File.join(File.dirname(__FILE__), 'parallel_tests')
3
3
  class ParallelSpecs < ParallelTests
4
4
  def self.run_tests(test_files, process_number, options)
5
5
  cmd = "#{color} #{executable} #{options} #{spec_opts} #{test_files*' '}"
6
- execute_command(cmd, process_number)
6
+ execute_command(cmd, process_number)[:stdout]
7
7
  end
8
8
 
9
9
  def self.executable
@@ -30,7 +30,7 @@ class ParallelTests
30
30
  def self.run_tests(test_files, process_number, options)
31
31
  require_list = test_files.map { |filename| "\"#{filename}\"" }.join(",")
32
32
  cmd = "ruby -Itest #{options} -e '[#{require_list}].each {|f| require f }'"
33
- execute_command(cmd, process_number)
33
+ execute_command(cmd, process_number)[:stdout]
34
34
  end
35
35
 
36
36
  def self.execute_command(cmd, process_number)
@@ -43,7 +43,8 @@ class ParallelTests
43
43
  print char
44
44
  STDOUT.flush
45
45
  end
46
- all
46
+ f.close
47
+ {:stdout => all, :exit_status => $?.exitstatus}
47
48
  end
48
49
 
49
50
  def self.find_results(test_output)
@@ -1,7 +1,9 @@
1
1
  namespace :parallel do
2
2
  def run_in_parallel(cmd, options)
3
3
  count = (options[:count] ? options[:count].to_i : nil)
4
- system "#{File.join(File.dirname(__FILE__), '..', '..', 'bin', 'parallel_test')} --exec '#{cmd}' -n #{count}"
4
+ executable = File.join(File.dirname(__FILE__), '..', '..', 'bin', 'parallel_test')
5
+ command = "#{executable} --exec '#{cmd}' -n #{count}"
6
+ abort unless system(command)
5
7
  end
6
8
 
7
9
  desc "update test databases by running db:test:prepare for each test db --> parallel:prepare[num_cpus]"
@@ -28,7 +30,9 @@ namespace :parallel do
28
30
  $LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), '..'))
29
31
  require "parallel_tests"
30
32
  count, prefix, options = ParallelTests.parse_rake_args(args)
31
- exec "#{File.join(File.dirname(__FILE__), '..', '..', 'bin', 'parallel_test')} --type #{type} -n #{count} -p '#{prefix}' -r '#{RAILS_ROOT}' -o '#{options}'"
33
+ executable = File.join(File.dirname(__FILE__), '..', '..', 'bin', 'parallel_test')
34
+ command = "#{executable} --type #{type} -n #{count} -p '#{prefix}' -r '#{RAILS_ROOT}' -o '#{options}'"
35
+ abort unless system(command) # allow to chain tasks e.g. rake parallel:spec parallel:features
32
36
  end
33
37
  end
34
38
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{parallel_tests}
8
- s.version = "0.4.2"
8
+ s.version = "0.4.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Michael Grosser"]
12
- s.date = %q{2010-06-03}
12
+ s.date = %q{2010-07-15}
13
13
  s.email = %q{grosser.michael@gmail.com}
14
14
  s.executables = ["parallel_spec", "parallel_cucumber", "parallel_test"]
15
15
  s.extra_rdoc_files = [
@@ -1,3 +1,5 @@
1
+ require 'spec/spec_helper'
2
+
1
3
  describe 'CLI' do
2
4
  before do
3
5
  `rm -rf #{folder}`
@@ -63,6 +65,14 @@ describe 'CLI' do
63
65
  result.split("\n").sort.should == %w["" "2" "3" "4"]
64
66
  end
65
67
 
68
+ it "exists with success if all sub-processes returned success" do
69
+ system("#{executable} -e 'cat /dev/null' -n 4").should == true
70
+ end
71
+
72
+ it "exists with failure if any sub-processes returned failure" do
73
+ system("#{executable} -e 'test -e xxxx' -n 4").should == false
74
+ end
75
+
66
76
  it "can run through parallel_spec / parallel_cucumber" do
67
77
  version = `#{executable} -v`
68
78
  `#{bin_folder}/parallel_spec -v`.should == version
@@ -10,12 +10,12 @@ describe ParallelCucumber do
10
10
  end
11
11
 
12
12
  it "uses TEST_ENV_NUMBER=blank when called for process 0" do
13
- ParallelCucumber.should_receive(:open).with{|x,y| x=~/TEST_ENV_NUMBER= /}.and_return mock(:getc=>false)
13
+ ParallelCucumber.should_receive(:open).with{|x,y| x=~/TEST_ENV_NUMBER= /}.and_return mocked_process
14
14
  ParallelCucumber.run_tests(['xxx'],0,'')
15
15
  end
16
16
 
17
17
  it "uses TEST_ENV_NUMBER=2 when called for process 1" do
18
- ParallelCucumber.should_receive(:open).with{|x,y| x=~/TEST_ENV_NUMBER=2/}.and_return mock(:getc=>false)
18
+ ParallelCucumber.should_receive(:open).with{|x,y| x=~/TEST_ENV_NUMBER=2/}.and_return mocked_process
19
19
  ParallelCucumber.run_tests(['xxx'],1,'')
20
20
  end
21
21
 
@@ -28,23 +28,23 @@ describe ParallelCucumber do
28
28
 
29
29
  it "runs bundle exec cucumber when on bundler 0.9" do
30
30
  ParallelCucumber.stub!(:bundler_enabled?).and_return true
31
- ParallelCucumber.should_receive(:open).with{|x,y| x =~ %r{bundle exec cucumber}}.and_return mock(:getc=>false)
31
+ ParallelCucumber.should_receive(:open).with{|x,y| x =~ %r{bundle exec cucumber}}.and_return mocked_process
32
32
  ParallelCucumber.run_tests(['xxx'],1,'')
33
33
  end
34
34
 
35
35
  it "runs script/cucumber when script/cucumber is found" do
36
- ParallelCucumber.should_receive(:open).with{|x,y| x =~ %r{script/cucumber}}.and_return mock(:getc=>false)
36
+ ParallelCucumber.should_receive(:open).with{|x,y| x =~ %r{script/cucumber}}.and_return mocked_process
37
37
  ParallelCucumber.run_tests(['xxx'],1,'')
38
38
  end
39
39
 
40
40
  it "runs cucumber by default" do
41
41
  File.stub!(:file?).with('script/cucumber').and_return false
42
- ParallelCucumber.should_receive(:open).with{|x,y| x !~ %r{(script/cucumber)|(bundle exec cucumber)}}.and_return mock(:getc=>false)
42
+ ParallelCucumber.should_receive(:open).with{|x,y| x !~ %r{(script/cucumber)|(bundle exec cucumber)}}.and_return mocked_process
43
43
  ParallelCucumber.run_tests(['xxx'],1,'')
44
44
  end
45
45
 
46
46
  it "uses options passed in" do
47
- ParallelCucumber.should_receive(:open).with{|x,y| x =~ %r{script/cucumber -p default}}.and_return mock(:getc=>false)
47
+ ParallelCucumber.should_receive(:open).with{|x,y| x =~ %r{script/cucumber -p default}}.and_return mocked_process
48
48
  ParallelCucumber.run_tests(['xxx'],1,'-p default')
49
49
  end
50
50
  end
@@ -12,64 +12,64 @@ describe ParallelSpecs do
12
12
  end
13
13
 
14
14
  it "uses TEST_ENV_NUMBER=blank when called for process 0" do
15
- ParallelSpecs.should_receive(:open).with{|x,y|x=~/TEST_ENV_NUMBER= /}.and_return mock(:getc=>false)
15
+ ParallelSpecs.should_receive(:open).with{|x,y|x=~/TEST_ENV_NUMBER= /}.and_return mocked_process
16
16
  ParallelSpecs.run_tests(['xxx'],0,'')
17
17
  end
18
18
 
19
19
  it "uses TEST_ENV_NUMBER=2 when called for process 1" do
20
- ParallelSpecs.should_receive(:open).with{|x,y| x=~/TEST_ENV_NUMBER=2/}.and_return mock(:getc=>false)
20
+ ParallelSpecs.should_receive(:open).with{|x,y| x=~/TEST_ENV_NUMBER=2/}.and_return mocked_process
21
21
  ParallelSpecs.run_tests(['xxx'],1,'')
22
22
  end
23
23
 
24
24
  it "runs with color when called from cmdline" do
25
- ParallelSpecs.should_receive(:open).with{|x,y| x=~/RSPEC_COLOR=1/}.and_return mock(:getc=>false)
25
+ ParallelSpecs.should_receive(:open).with{|x,y| x=~/RSPEC_COLOR=1/}.and_return mocked_process
26
26
  $stdout.should_receive(:tty?).and_return true
27
27
  ParallelSpecs.run_tests(['xxx'],1,'')
28
28
  end
29
29
 
30
30
  it "runs without color when not called from cmdline" do
31
- ParallelSpecs.should_receive(:open).with{|x,y| x !~ /RSPEC_COLOR/}.and_return mock(:getc=>false)
31
+ ParallelSpecs.should_receive(:open).with{|x,y| x !~ /RSPEC_COLOR/}.and_return mocked_process
32
32
  $stdout.should_receive(:tty?).and_return false
33
33
  ParallelSpecs.run_tests(['xxx'],1,'')
34
34
  end
35
35
 
36
36
  it "run bundle exec spec when on bundler 0.9" do
37
37
  ParallelSpecs.stub!(:bundler_enabled?).and_return true
38
- ParallelSpecs.should_receive(:open).with{|x,y| x =~ %r{bundle exec spec}}.and_return mock(:getc=>false)
38
+ ParallelSpecs.should_receive(:open).with{|x,y| x =~ %r{bundle exec spec}}.and_return mocked_process
39
39
  ParallelSpecs.run_tests(['xxx'],1,'')
40
40
  end
41
41
 
42
42
  it "runs script/spec when script/spec can be found" do
43
43
  File.should_receive(:file?).with('script/spec').and_return true
44
- ParallelSpecs.should_receive(:open).with{|x,y| x =~ %r{script/spec}}.and_return mock(:getc=>false)
44
+ ParallelSpecs.should_receive(:open).with{|x,y| x =~ %r{script/spec}}.and_return mocked_process
45
45
  ParallelSpecs.run_tests(['xxx'],1,'')
46
46
  end
47
47
 
48
48
  it "runs spec when script/spec cannot be found" do
49
49
  File.stub!(:file?).with('script/spec').and_return false
50
- ParallelSpecs.should_receive(:open).with{|x,y| x !~ %r{(script/spec)|(bundle exec spec)}}.and_return mock(:getc=>false)
50
+ ParallelSpecs.should_receive(:open).with{|x,y| x !~ %r{(script/spec)|(bundle exec spec)}}.and_return mocked_process
51
51
  ParallelSpecs.run_tests(['xxx'],1,'')
52
52
  end
53
53
 
54
54
  it "uses no -O when no opts where found" do
55
55
  File.stub!(:file?).with('spec/spec.opts').and_return false
56
- ParallelSpecs.should_receive(:open).with{|x,y| x !~ %r{spec/spec.opts}}.and_return mock(:getc=>false)
56
+ ParallelSpecs.should_receive(:open).with{|x,y| x !~ %r{spec/spec.opts}}.and_return mocked_process
57
57
  ParallelSpecs.run_tests(['xxx'],1,'')
58
58
  end
59
59
 
60
60
  it "uses spec/spec.opts when found" do
61
- ParallelSpecs.should_receive(:open).with{|x,y| x =~ %r{script/spec\s+-O spec/spec.opts}}.and_return mock(:getc=>false)
61
+ ParallelSpecs.should_receive(:open).with{|x,y| x =~ %r{script/spec\s+-O spec/spec.opts}}.and_return mocked_process
62
62
  ParallelSpecs.run_tests(['xxx'],1,'')
63
63
  end
64
64
 
65
65
  it "uses spec/parallel_spec.opts when found" do
66
66
  File.should_receive(:file?).with('spec/parallel_spec.opts').and_return true
67
- ParallelSpecs.should_receive(:open).with{|x,y| x =~ %r{script/spec\s+-O spec/parallel_spec.opts}}.and_return mock(:getc=>false)
67
+ ParallelSpecs.should_receive(:open).with{|x,y| x =~ %r{script/spec\s+-O spec/parallel_spec.opts}}.and_return mocked_process
68
68
  ParallelSpecs.run_tests(['xxx'],1,'')
69
69
  end
70
70
 
71
71
  it "uses options passed in" do
72
- ParallelSpecs.should_receive(:open).with{|x,y| x =~ %r{script/spec -f n}}.and_return mock(:getc=>false)
72
+ ParallelSpecs.should_receive(:open).with{|x,y| x =~ %r{script/spec -f n}}.and_return mocked_process
73
73
  ParallelSpecs.run_tests(['xxx'],1,'-f n')
74
74
  end
75
75
 
@@ -27,17 +27,17 @@ describe ParallelTests do
27
27
 
28
28
  describe :run_tests do
29
29
  it "uses TEST_ENV_NUMBER=blank when called for process 0" do
30
- ParallelTests.should_receive(:open).with{|x,y|x=~/TEST_ENV_NUMBER= /}.and_return mock(:getc=>false)
30
+ ParallelTests.should_receive(:open).with{|x,y|x=~/TEST_ENV_NUMBER= /}.and_return mocked_process
31
31
  ParallelTests.run_tests(['xxx'],0,'')
32
32
  end
33
33
 
34
34
  it "uses TEST_ENV_NUMBER=2 when called for process 1" do
35
- ParallelTests.should_receive(:open).with{|x,y| x=~/TEST_ENV_NUMBER=2/}.and_return mock(:getc=>false)
35
+ ParallelTests.should_receive(:open).with{|x,y| x=~/TEST_ENV_NUMBER=2/}.and_return mocked_process
36
36
  ParallelTests.run_tests(['xxx'],1,'')
37
37
  end
38
38
 
39
39
  it "uses options" do
40
- ParallelTests.should_receive(:open).with{|x,y| x=~ %r{ruby -Itest -v}}.and_return mock(:getc=>false)
40
+ ParallelTests.should_receive(:open).with{|x,y| x=~ %r{ruby -Itest -v}}.and_return mocked_process
41
41
  ParallelTests.run_tests(['xxx'],1,'-v')
42
42
  end
43
43
 
@@ -7,6 +7,10 @@ FAKE_RAILS_ROOT = '/tmp/pspecs/fixtures'
7
7
  require 'parallel_specs'
8
8
  require 'parallel_cucumber'
9
9
 
10
+ def mocked_process
11
+ open('|cat /dev/null')
12
+ end
13
+
10
14
  def size_of(group)
11
15
  group.inject(0) { |sum, test| sum += File.stat(test).size }
12
16
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 4
8
- - 2
9
- version: 0.4.2
8
+ - 3
9
+ version: 0.4.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Michael Grosser
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-06-03 00:00:00 +02:00
17
+ date: 2010-07-15 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency