Permalink
Browse files

Point to http://github.com/grosser/parallel_specs

  • Loading branch information...
1 parent a142284 commit 8a0be78efef1e421b71437345a2b4e9c7ad4ee37 @jasonm committed Jan 14, 2010
Showing with 3 additions and 574 deletions.
  1. +3 −76 README.markdown
  2. +0 −6 Rakefile
  3. +0 −63 lib/parallel_specs.rb
  4. +0 −65 lib/parallel_tests.rb
  5. +0 −129 spec/parallel_specs_spec.rb
  6. +0 −117 spec/parallel_tests_spec.rb
  7. +0 −7 spec/spec_helper.rb
  8. +0 −111 tasks/parallel_specs.rake
View
@@ -1,78 +1,5 @@
-Rake tasks to run specs and tests in parallel, to use multiple CPUs and speedup test runtime.
+You should use:
-Setup
-=====
+http://github.com/grosser/parallel_specs
-For this fork (to be removed before pulling upstream):
-
- script/plugin install git://github.com/jasonm/parallel_specs.git
-
-For the upstream plugin:
-
- script/plugin install git://github.com/grosser/parallel_specs.git
-
-Add <%= ENV['TEST_ENV_NUMBER'] %> to the database name for the test environment in `config/database.yml`,
-it is '' for process 1, and '2' for process 2.
-
- test:
- adapter: mysql
- database: xxx_test<%= ENV['TEST_ENV_NUMBER'] %>
- username: root
-
-For each environment, create the databases
- mysql -u root -> create database xxx_test2;
-
-Run like hell :D
-
- rake spec:parallel:prepare[2] #db:reset for each database
-
- rake spec:parallel[1] --> 86 seconds
- rake spec:parallel --> 47 seconds (default = 2)
- rake spec:parallel[4] --> 26 seconds
- ...
-
-Example output
---------------
- 2 processes for 210 specs, ~ 105 specs per process
- ... test output ...
-
- Results:
- 877 examples, 0 failures, 11 pending
- 843 examples, 0 failures, 1 pending
-
- Took 29.925333 seconds
-
-Test::Unit
-----------
-
-To run Test::Unit tests, use the following task:
-
- rake test:parallel
-
-instead of
-
- rake spec:parallel
-
-This includes the ability to specify more than two parallel environments.
-
-TIPS
-====
- - `./script/generate rspec` if you are running rspec from gems (this plugin uses script/spec which may fail if rspec files are outdated)
- - with zsh this would be `rake "spec:parallel:prepare[3]"`
-
-TODO
-====
- - find out how many CPUs the user has [here](http://stackoverflow.com/questions/891537/ruby-detect-number-of-cpus-installed)
- - grab the 'xxx examples ..' line and display them after all tests have finished
-
-Authors
-====
-inspired by [pivotal labs](http://pivotallabs.com/users/miked/blog/articles/849-parallelize-your-rspec-suite)
-
-###Contributors
- - [Joakim Kolsjö](http://www.rubyblocks.se) -- joakim.kolsjo<$at$>gmail.com
- - [Jason Morrison](http://jayunit.net) -- jason.p.morrison<$at$>gmail.com
-
-[Michael Grosser](http://pragmatig.wordpress.com)
-grosser.michael@gmail.com
-Hereby placed under public domain, do what you want, just do not hold me accountable...
+because it's awesome! And regularly updated.
View
@@ -1,6 +0,0 @@
-desc "Run all specs in spec directory"
-task :default do |t|
- options = "--colour --format progress --loadby --reverse"
- files = FileList['spec/**/*_spec.rb']
- system("spec #{options} #{files}")
-end
View
@@ -1,63 +0,0 @@
-module ParallelSpecs
- extend self
-
- # finds all specs and partitions them into groups
- def specs_in_groups(root, num)
- specs_with_sizes = find_specs_with_sizes(root)
-
- groups = []
- current_group = current_size = 0
- specs_with_sizes.each do |spec, size|
- current_size += size
- # inserts into next group if current is full and we are not in the last group
- if current_size > group_size(specs_with_sizes, num) and num > current_group + 1
- current_size = 0
- current_group += 1
- end
- groups[current_group] ||= []
- groups[current_group] << spec
- end
- groups
- end
-
- def run_tests(test_files, process_number)
- color = ($stdout.tty? ? 'export RSPEC_COLOR=1 ;' : '')#display color when we are in a terminal
- cmd = "export RAILS_ENV=test ; export TEST_ENV_NUMBER=#{process_number==0?'':process_number+1} ; #{color} script/spec -O spec/spec.opts #{test_files*' '}"
- execute_command(cmd)
- end
-
- def execute_command(cmd)
- f = open("|#{cmd}")
- all = ''
- while out = f.gets(".")#split by '.' because every test is a '.'
- all+=out
- print out
- STDOUT.flush
- end
- all
- end
-
- def find_results(test_output)
- test_output.split("\n").map {|line|
- line = line.gsub(/\.|F|\*/,'')
- next unless line =~ /\d+ example[s]?, \d+ failure[s]?, \d+ pending/
- line
- }.compact
- end
-
- def failed?(results)
- !! results.detect{|r| r=~ /[1-9] failure[s]?/}
- end
-
- private
-
- def self.group_size(specs_with_sizes, num_groups)
- total_size = specs_with_sizes.inject(0) { |sum, spec| sum += spec[1] }
- total_size / num_groups.to_f
- end
-
- def self.find_specs_with_sizes(root)
- specs = Dir["#{root}/spec/**/*_spec.rb"].sort
- specs.map { |spec| [ spec, File.stat(spec).size ] }
- end
-end
View
@@ -1,65 +0,0 @@
-module ParallelTests
- extend self
-
- # finds all tests and partitions them into groups
- def tests_in_groups(root, num)
- specs_with_sizes = find_specs_with_sizes(root)
-
- groups = []
- current_group = current_size = 0
- specs_with_sizes.each do |spec, size|
- current_size += size
- # inserts into next group if current is full and we are not in the last group
- if current_size > group_size(specs_with_sizes, num) and num > current_group + 1
- current_size = 0
- current_group += 1
- end
- groups[current_group] ||= []
- groups[current_group] << spec
- end
- groups
- end
-
- def run_tests(test_files, process_number)
- require_list = test_files.map { |filename| "\"#{filename}\"" }.join(",")
- test_env_number = process_number == 0 ? '' : process_number + 1
- cmd = "export RAILS_ENV=test ; export TEST_ENV_NUMBER=#{test_env_number} ; ruby -Itest -e '[#{require_list}].each {|f| require f }'"
-
- execute_command(cmd)
- end
-
- def execute_command(cmd)
- f = open("|#{cmd}")
- all = ''
- while out = f.gets(".")#split by '.' because every test is a '.'
- all+=out
- print out
- STDOUT.flush
- end
- all
- end
-
- def find_results(test_output)
- test_output.split("\n").map {|line|
- line = line.gsub(/\.|F|\*/,'')
- next unless line =~ /\d+ example[s]?, \d+ failure[s]?, \d+ pending/
- line
- }.compact
- end
-
- def failed?(results)
- !! results.detect{|r| r=~ /[1-9] failure[s]?/}
- end
-
- private
-
- def self.group_size(specs_with_sizes, num_groups)
- total_size = specs_with_sizes.inject(0) { |sum, spec| sum += spec[1] }
- total_size / num_groups.to_f
- end
-
- def self.find_specs_with_sizes(root)
- specs = Dir["#{root}/test/**/*_test.rb"].sort
- specs.map { |spec| [ spec, File.stat(spec).size ] }
- end
-end
View
@@ -1,129 +0,0 @@
-require File.dirname(__FILE__) + '/spec_helper'
-
-describe ParallelSpecs do
- def size_of(group)
- group.inject(0) { |sum, spec| sum += File.stat(spec).size }
- end
-
- describe :specs_in_groups_of do
- before :all do
- system "rm -rf #{FAKE_RAILS_ROOT}; mkdir -p #{FAKE_RAILS_ROOT}/spec/temp"
-
- 1.upto(100) do |i|
- size = 100 * i
- File.open("#{FAKE_RAILS_ROOT}/spec/temp/x#{i}_spec.rb", 'w') { |f| f.puts 'x' * size }
- end
- end
-
- it "finds all specs" do
- found = ParallelSpecs.specs_in_groups(FAKE_RAILS_ROOT, 1)
- all = [ Dir["#{FAKE_RAILS_ROOT}/spec/**/*_spec.rb"] ]
- (found.flatten - all.flatten).should == []
- end
-
- it "partitions them into groups by equal size" do
- groups = ParallelSpecs.specs_in_groups(FAKE_RAILS_ROOT, 2)
- groups.size.should == 2
- group0 = size_of(groups[0])
- group1 = size_of(groups[1])
- diff = group0 * 0.1
- group0.should be_close(group1, diff)
- end
-
- it 'should partition correctly with a group size of 4' do
- groups = ParallelSpecs.specs_in_groups(FAKE_RAILS_ROOT, 4)
- groups.size.should == 4
- group_size = size_of(groups[0])
- diff = group_size * 0.1
- group_size.should be_close(size_of(groups[1]), diff)
- group_size.should be_close(size_of(groups[2]), diff)
- group_size.should be_close(size_of(groups[3]), diff)
- end
-
- it 'should partition correctly with an uneven group size' do
- groups = ParallelSpecs.specs_in_groups(FAKE_RAILS_ROOT, 3)
- groups.size.should == 3
- group_size = size_of(groups[0])
- diff = group_size * 0.1
- group_size.should be_close(size_of(groups[1]), diff)
- group_size.should be_close(size_of(groups[2]), diff)
- end
- end
-
- describe :run_tests do
- it "uses TEST_ENV_NUMBER=blank when called for process 0" do
- ParallelSpecs.should_receive(:open).with{|x|x=~/TEST_ENV_NUMBER= /}.and_return mock(:gets=>false)
- ParallelSpecs.run_tests(['xxx'],0)
- end
-
- it "uses TEST_ENV_NUMBER=2 when called for process 1" do
- ParallelSpecs.should_receive(:open).with{|x| x=~/TEST_ENV_NUMBER=2/}.and_return mock(:gets=>false)
- ParallelSpecs.run_tests(['xxx'],1)
- end
-
- it "runs with color when called from cmdline" do
- ParallelSpecs.should_receive(:open).with{|x| x=~/RSPEC_COLOR=1/}.and_return mock(:gets=>false)
- $stdout.should_receive(:tty?).and_return true
- ParallelSpecs.run_tests(['xxx'],1)
- end
-
- it "runs without color when not called from cmdline" do
- ParallelSpecs.should_receive(:open).with{|x| x !~ /RSPEC_COLOR/}.and_return mock(:gets=>false)
- $stdout.should_receive(:tty?).and_return false
- ParallelSpecs.run_tests(['xxx'],1)
- end
-
- it "returns the output" do
- io = open('spec/spec_helper.rb')
- ParallelSpecs.stub!(:print)
- ParallelSpecs.should_receive(:open).and_return io
- ParallelSpecs.run_tests(['xxx'],1).should =~ /\$LOAD_PATH << File/
- end
- end
-
- describe :find_results do
- it "finds multiple results in spec output" do
- output = <<EOF
-....F...
-..
-failute fsddsfsd
-...
-ff.**..
-0 examples, 0 failures, 0 pending
-ff.**..
-1 example, 1 failure, 1 pending
-EOF
-
- ParallelSpecs.find_results(output).should == ['0 examples, 0 failures, 0 pending','1 example, 1 failure, 1 pending']
- end
-
- it "is robust against scrambeled output" do
- output = <<EOF
-....F...
-..
-failute fsddsfsd
-...
-ff.**..
-0 exFampl*es, 0 failures, 0 pend.ing
-ff.**..
-1 exampF.les, 1 failures, 1 pend.ing
-EOF
-
- ParallelSpecs.find_results(output).should == ['0 examples, 0 failures, 0 pending','1 examples, 1 failures, 1 pending']
- end
- end
-
- describe :failed do
- it "fails with single failed specs" do
- ParallelSpecs.failed?(['0 examples, 0 failures, 0 pending','1 examples, 1 failure, 1 pending']).should == true
- end
-
- it "fails with multiple failed specs" do
- ParallelSpecs.failed?(['0 examples, 1 failure, 0 pending','1 examples, 111 failures, 1 pending']).should == true
- end
-
- it "does not fail with successful specs" do
- ParallelSpecs.failed?(['0 examples, 0 failures, 0 pending','1 examples, 0 failures, 1 pending']).should == false
- end
- end
-end
Oops, something went wrong.

2 comments on commit 8a0be78

thanks, will make hopefully installers life easier :)

hopefully <-> make ;)

Please sign in to comment.